2020-07-27 13:35:17 +00:00
|
|
|
|
#!/usr/bin/env bats
|
2022-11-29 12:54:13 +00:00
|
|
|
|
#
|
|
|
|
|
# Copyright © 2019 – 2022 Red Hat, Inc.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
#
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
load 'libs/bats-support/load'
|
|
|
|
|
load 'libs/bats-assert/load'
|
|
|
|
|
load 'libs/helpers'
|
|
|
|
|
|
|
|
|
|
setup() {
|
2021-11-11 00:46:21 +00:00
|
|
|
|
_setup_environment
|
2020-07-27 13:35:17 +00:00
|
|
|
|
cleanup_containers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
|
cleanup_containers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@test "create: Create the default container" {
|
|
|
|
|
pull_default_image
|
|
|
|
|
|
2021-05-26 20:12:18 +00:00
|
|
|
|
run $TOOLBOX -y create
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Create a container with a valid custom name ('custom-containerName')" {
|
2021-05-25 22:09:53 +00:00
|
|
|
|
pull_default_image
|
|
|
|
|
|
2021-05-26 20:12:18 +00:00
|
|
|
|
run $TOOLBOX -y create -c "custom-containerName"
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
@test "create: Create a container with a custom image and name ('fedora34'; f34)" {
|
|
|
|
|
pull_distro_image fedora 34
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
run $TOOLBOX -y create -c "fedora34" -i fedora-toolbox:34
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container with invalid custom name ('ßpeci@l.Nam€'; using positional argument)" {
|
2021-05-26 20:12:18 +00:00
|
|
|
|
run $TOOLBOX -y create "ßpeci@l.Nam€"
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for 'CONTAINER'"
|
2022-08-02 14:34:18 +00:00
|
|
|
|
assert_line --index 1 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'."
|
2020-07-27 13:35:17 +00:00
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container with invalid custom name ('ßpeci@l.Nam€'; using option --container)" {
|
2021-05-26 20:12:18 +00:00
|
|
|
|
run $TOOLBOX -y create -c "ßpeci@l.Nam€"
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--container'"
|
2022-08-02 14:34:18 +00:00
|
|
|
|
assert_line --index 1 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'."
|
2020-07-27 13:35:17 +00:00
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
}
|
2021-02-12 18:55:48 +00:00
|
|
|
|
|
2022-07-31 08:49:03 +00:00
|
|
|
|
@test "create: Try to create a container with invalid custom image ('ßpeci@l.Nam€')" {
|
|
|
|
|
local image="ßpeci@l.Nam€"
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX create --image "$image"
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--image'"
|
|
|
|
|
assert_line --index 1 "Container name $image generated from image is invalid."
|
|
|
|
|
assert_line --index 2 "Container names must match '[a-zA-Z0-9][a-zA-Z0-9_.-]*'."
|
|
|
|
|
assert_line --index 3 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 4 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
@test "create: Create a container with a distro and release options ('fedora'; f34)" {
|
|
|
|
|
pull_distro_image fedora 34
|
2021-02-12 18:55:48 +00:00
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
run $TOOLBOX -y create -d "fedora" -r f34
|
2021-02-12 18:55:48 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
2022-12-05 19:54:51 +00:00
|
|
|
|
assert_output --partial "Created container: fedora-toolbox-34"
|
|
|
|
|
assert_output --partial "Enter with: toolbox enter fedora-toolbox-34"
|
2021-02-12 18:55:48 +00:00
|
|
|
|
|
|
|
|
|
# Make sure the container has actually been created
|
|
|
|
|
run podman ps -a
|
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
assert_output --regexp "Created[[:blank:]]+fedora-toolbox-34"
|
2021-02-12 18:55:48 +00:00
|
|
|
|
}
|
2021-07-28 13:57:45 +00:00
|
|
|
|
|
2022-07-30 17:38:32 +00:00
|
|
|
|
@test "create: Try to create a container based on unsupported distribution" {
|
|
|
|
|
local distro="foo"
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --distro "$distro"
|
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-08-01 21:44:49 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--distro'"
|
|
|
|
|
assert_line --index 1 "Distribution $distro is unsupported."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
2022-07-30 17:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 13:57:45 +00:00
|
|
|
|
@test "create: Try to create a container based on non-existent image" {
|
|
|
|
|
run $TOOLBOX -y create -i foo.org/bar
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: failed to pull image foo.org/bar"
|
|
|
|
|
assert_line --index 1 "If it was a private image, log in with: podman login foo.org"
|
|
|
|
|
assert_line --index 2 "Use 'toolbox --verbose ...' for further details."
|
|
|
|
|
}
|
2021-12-17 14:27:21 +00:00
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container based on Fedora but with wrong version" {
|
|
|
|
|
run $TOOLBOX -y create -d fedora -r foobar
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 1 "The release must be a positive integer."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --distro fedora --release -3
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be a positive integer."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container based on RHEL but with wrong version" {
|
|
|
|
|
run $TOOLBOX --assumeyes create --distro rhel --release 8
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be in the '<major>.<minor>' format."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --distro rhel --release 8.2foo
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be in the '<major>.<minor>' format."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --distro rhel --release -2.1
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be a positive number."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
2021-12-17 14:27:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container based on non-default distribution without providing version" {
|
|
|
|
|
local distro="fedora"
|
|
|
|
|
local system_id="$(get_system_id)"
|
|
|
|
|
|
|
|
|
|
if [ "$system_id" = "fedora" ]; then
|
|
|
|
|
distro="rhel"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX -y create -d "$distro"
|
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-08-01 21:44:49 +00:00
|
|
|
|
assert_line --index 0 "Error: option '--release' is needed"
|
|
|
|
|
assert_line --index 1 "Distribution $distro doesn't match the host."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
2021-12-17 14:27:21 +00:00
|
|
|
|
}
|
2021-11-24 23:52:15 +00:00
|
|
|
|
|
2022-09-07 17:14:43 +00:00
|
|
|
|
@test "create: Try to create a container using both --distro and --image" {
|
2022-12-05 19:54:51 +00:00
|
|
|
|
pull_distro_image fedora 34
|
2022-09-07 17:14:43 +00:00
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
run $TOOLBOX --assumeyes create --distro "fedora" --image fedora-toolbox:34
|
2022-09-07 17:14:43 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: options --distro and --image cannot be used together"
|
|
|
|
|
assert_line --index 1 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 2 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Try to create a container using both --image and --release" {
|
2022-12-05 19:54:51 +00:00
|
|
|
|
pull_distro_image fedora 34
|
2022-09-07 17:14:43 +00:00
|
|
|
|
|
2022-12-05 19:54:51 +00:00
|
|
|
|
run $TOOLBOX --assumeyes create --image fedora-toolbox:34 --release 34
|
2022-09-07 17:14:43 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: options --image and --release cannot be used together"
|
|
|
|
|
assert_line --index 1 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 2 ]
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 23:52:15 +00:00
|
|
|
|
@test "create: Try to create a container and pass a non-existent file to the --authfile option" {
|
|
|
|
|
local file="$BATS_RUN_TMPDIR/non-existent-file"
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX create --authfile "$file"
|
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-09-07 17:00:52 +00:00
|
|
|
|
assert_line --index 0 "Error: file $file not found"
|
|
|
|
|
assert_line --index 1 "'podman login' can be used to create the file."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
2021-11-24 23:52:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "create: Create a container based on an image from locked registry using an authentication file" {
|
|
|
|
|
local authfile="$BATS_RUN_TMPDIR/authfile"
|
2022-12-05 19:54:51 +00:00
|
|
|
|
local image="fedora-toolbox:34"
|
2021-11-24 23:52:15 +00:00
|
|
|
|
|
|
|
|
|
run $PODMAN login --authfile "$authfile" --username user --password user "$DOCKER_REG_URI"
|
|
|
|
|
assert_success
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --image "$DOCKER_REG_URI/$image"
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_line --index 0 "Error: failed to pull image $DOCKER_REG_URI/$image"
|
|
|
|
|
assert_line --index 1 "If it was a private image, log in with: podman login $DOCKER_REG_URI"
|
|
|
|
|
assert_line --index 2 "Use 'toolbox --verbose ...' for further details."
|
|
|
|
|
assert [ ${#lines[@]} -eq 3 ]
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX --assumeyes create --authfile "$authfile" --image "$DOCKER_REG_URI/$image"
|
|
|
|
|
|
|
|
|
|
rm "$authfile"
|
|
|
|
|
|
|
|
|
|
assert_success
|
2022-12-05 19:54:51 +00:00
|
|
|
|
assert_line --index 0 "Created container: fedora-toolbox-34"
|
|
|
|
|
assert_line --index 1 "Enter with: toolbox enter fedora-toolbox-34"
|
2021-11-24 23:52:15 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 2 ]
|
|
|
|
|
}
|