Skip to content

Commit f3f59b3

Browse files
committed
test/system: Added test cases for non-Toolbx image usage warning
Test cases for non-Toolbx image usage warning added in the commit f06a819
1 parent 38e8d04 commit f3f59b3

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

test/system/101-create.bats

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,3 +1009,56 @@ teardown() {
10091009
assert [ ${#lines[@]} -eq 2 ]
10101010
assert [ ${#stderr_lines[@]} -eq 0 ]
10111011
}
1012+
1013+
@test "create: With a non-Toolbx image and prompt for confirmation - Yes" {
1014+
image="$(build_non_toolbx_image)"
1015+
containerName="test-container-non-toolbx"
1016+
1017+
run --keep-empty-lines --separate-stderr "$TOOLBX" create --image "$image" "$containerName" <<< "y"
1018+
1019+
assert_success
1020+
assert_line --index 0 "Image '$image' is not a Toolbx image and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: Created container: $containerName"
1021+
assert_line --index 1 "Enter with: toolbox enter $containerName"
1022+
assert [ ${#lines[@]} -eq 2 ]
1023+
assert [ ${#stderr_lines[@]} -eq 0 ]
1024+
1025+
run podman ps --all
1026+
1027+
assert_success
1028+
assert_output --regexp "Created[[:blank:]]+$containerName"
1029+
}
1030+
1031+
@test "create: With a non-Toolbx image and prompt for confirmation - No" {
1032+
image="$(build_non_toolbx_image)"
1033+
containerName="test-container-non-toolbx"
1034+
1035+
run --keep-empty-lines --separate-stderr "$TOOLBX" create --image "$image" "$containerName" <<< "n"
1036+
1037+
assert_success
1038+
assert_line --index 0 "Image '$image' is not a Toolbx image and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: "
1039+
assert [ ${#lines[@]} -eq 1 ]
1040+
assert [ ${#stderr_lines[@]} -eq 0 ]
1041+
1042+
run podman ps --all
1043+
1044+
assert_success
1045+
assert [ ${#lines[@]} -eq 1 ]
1046+
}
1047+
1048+
@test "create: With a non-Toolbx image and prompt for confirmation - assumeyes" {
1049+
image="$(build_non_toolbx_image)"
1050+
containerName="test-container-non-toolbx"
1051+
1052+
run --keep-empty-lines --separate-stderr "$TOOLBX" create --assumeyes --image "$image" "$containerName"
1053+
1054+
assert_success
1055+
assert_line --index 0 "Created container: $containerName"
1056+
assert_line --index 1 "Enter with: toolbox enter $containerName"
1057+
assert [ ${#lines[@]} -eq 2 ]
1058+
assert [ ${#stderr_lines[@]} -eq 0 ]
1059+
1060+
run podman ps --all
1061+
1062+
assert_success
1063+
assert_output --regexp "Created[[:blank:]]+$containerName"
1064+
}

test/system/104-run.bats

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,50 @@ teardown() {
863863
assert_line --index 1 "Recreate it with Toolbx version 0.0.17 or newer."
864864
assert [ ${#stderr_lines[@]} -eq 2 ]
865865
}
866+
867+
@test "run: With a non-Toolbx image and prompt for confirmation - Yes" {
868+
containerName="test-container-non-toolbx"
869+
image="$(build_non_toolbx_image)"
870+
871+
create_image_container "$image" "$containerName"
872+
873+
run --keep-empty-lines --separate-stderr "$TOOLBX" run --container "$containerName" true <<< "y"
874+
875+
assert_failure
876+
assert_line --index 0 "Container '$containerName' uses a non-Toolbx image '$image' and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: "
877+
assert [ ${#lines[@]} -eq 1 ]
878+
879+
lines=("${stderr_lines[@]}")
880+
assert_line --index 0 "Error: failed to start container $containerName"
881+
assert [ ${#stderr_lines[@]} -eq 1 ]
882+
}
883+
884+
@test "run: With a non-Toolbx image and prompt for confirmation - No" {
885+
containerName="test-container-non-toolbx"
886+
image="$(build_non_toolbx_image)"
887+
888+
create_image_container "$image" "$containerName"
889+
890+
run --keep-empty-lines --separate-stderr "$TOOLBX" run --container "$containerName" true <<< "n"
891+
892+
assert_success
893+
assert_line --index 0 "Container '$containerName' uses a non-Toolbx image '$image' and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: "
894+
assert [ ${#lines[@]} -eq 1 ]
895+
assert [ ${#stderr_lines[@]} -eq 0 ]
896+
}
897+
898+
@test "run: With a non-Toolbx image and prompt for confirmation - assumeyes" {
899+
containerName="test-container-non-toolbx"
900+
image="$(build_non_toolbx_image)"
901+
902+
create_image_container "$image" "$containerName"
903+
904+
run --keep-empty-lines --separate-stderr "$TOOLBX" --assumeyes run --container "$containerName" true
905+
906+
assert_failure
907+
assert [ ${#lines[@]} -eq 0 ]
908+
909+
lines=("${stderr_lines[@]}")
910+
assert_line --index 0 "Error: failed to start container $containerName"
911+
assert [ ${#stderr_lines[@]} -eq 1 ]
912+
}

test/system/105-enter.bats

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,53 @@ teardown() {
147147
assert [ ${#lines[@]} -eq 3 ]
148148
}
149149

150+
@test "enter: With a non-Toolbx image and prompt for confirmation - Yes" {
151+
containerName="test-container-non-toolbx"
152+
image="$(build_non_toolbx_image)"
153+
154+
create_image_container "$image" "$containerName"
155+
156+
run --keep-empty-lines --separate-stderr "$TOOLBX" enter --container "$containerName" <<< "y"
157+
158+
assert_failure
159+
assert_line --index 0 "Container '$containerName' uses a non-Toolbx image '$image' and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: "
160+
assert [ ${#lines[@]} -eq 1 ]
161+
162+
lines=("${stderr_lines[@]}")
163+
assert_line --index 0 "Error: failed to start container $containerName"
164+
assert [ ${#stderr_lines[@]} -eq 1 ]
165+
}
166+
167+
@test "enter: With a non-Toolbx image and prompt for confirmation - No" {
168+
containerName="test-container-non-toolbx"
169+
image="$(build_non_toolbx_image)"
170+
171+
create_image_container "$image" "$containerName"
172+
173+
run --keep-empty-lines --separate-stderr "$TOOLBX" enter --container "$containerName" <<< "n"
174+
175+
assert_success
176+
assert_line --index 0 "Container '$containerName' uses a non-Toolbx image '$image' and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]: "
177+
assert [ ${#lines[@]} -eq 1 ]
178+
assert [ ${#stderr_lines[@]} -eq 0 ]
179+
}
180+
181+
@test "enter: With a non-Toolbx image and prompt for confirmation - assumeyes" {
182+
containerName="test-container-non-toolbx"
183+
image="$(build_non_toolbx_image)"
184+
185+
create_image_container "$image" "$containerName"
186+
187+
run --keep-empty-lines --separate-stderr "$TOOLBX" --assumeyes enter --container "$containerName"
188+
189+
assert_failure
190+
assert [ ${#lines[@]} -eq 0 ]
191+
192+
lines=("${stderr_lines[@]}")
193+
assert_line --index 0 "Error: failed to start container $containerName"
194+
assert [ ${#stderr_lines[@]} -eq 1 ]
195+
}
196+
150197
# TODO: Write the test
151198
@test "enter: Enter the default Toolbx" {
152199
skip "Testing of entering Toolbxes is not implemented"

test/system/libs/helpers.bash

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ function build_image_without_name() {
255255
}
256256

257257

258+
function build_non_toolbx_image() {
259+
local image_name="localhost/non-toolbx:test-$$"
260+
261+
echo -e "FROM scratch\n\nLABEL test=\"non-toolbx\"" > "$BATS_TEST_TMPDIR"/Containerfile
262+
263+
run podman build --quiet --tag "$image_name" "$BATS_TEST_TMPDIR"
264+
265+
assert_success
266+
assert_line --index 0 --regexp "^[a-f0-9]{64}$"
267+
268+
# shellcheck disable=SC2154
269+
assert [ ${#lines[@]} -eq 1 ]
270+
271+
rm -f "$BATS_TEST_TMPDIR"/Containerfile
272+
273+
echo "$image_name"
274+
}
275+
276+
258277
function check_bats_version() {
259278
local required_version
260279
required_version="$1"
@@ -422,6 +441,24 @@ function create_default_container() {
422441
}
423442

424443

444+
# Creates a container with specific name and image
445+
#
446+
# Parameters:
447+
# ===========
448+
# - image - name of the image
449+
# - container_name - name of the container
450+
function create_image_container() {
451+
local image
452+
local container_name
453+
454+
image="$1"
455+
container_name="$2"
456+
457+
"$TOOLBX" --assumeyes create --container "${container_name}" --image "${image}" >/dev/null \
458+
|| fail "Toolbx couldn't create container '$container_name'"
459+
}
460+
461+
425462
function start_container() {
426463
local container_name
427464
container_name="$1"

0 commit comments

Comments
 (0)