pkg/utils, test/system: Add some more tests for parsing RHEL releases

https://github.com/containers/toolbox/pull/1262
This commit is contained in:
Debarshi Ray 2023-03-15 16:00:00 +01:00
parent e01927bfdc
commit c6760299d2
2 changed files with 110 additions and 0 deletions

View file

@ -140,6 +140,11 @@ func TestParseRelease(t *testing.T) {
inputRelease: "3foo",
errMsg: "The release must be a positive integer.",
},
{
inputDistro: "rhel",
inputRelease: "8.0",
output: "8.0",
},
{
inputDistro: "rhel",
inputRelease: "8.3",
@ -155,6 +160,31 @@ func TestParseRelease(t *testing.T) {
inputRelease: "8",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "8.0.0",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "8.0.1",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "8.3.0",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "8.3.1",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "foo",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "8.2foo",
@ -165,6 +195,16 @@ func TestParseRelease(t *testing.T) {
inputRelease: "-2.1",
errMsg: "The release must be a positive number.",
},
{
inputDistro: "rhel",
inputRelease: "-2.-1",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
{
inputDistro: "rhel",
inputRelease: "2.-1",
errMsg: "The release must be in the '<major>.<minor>' format.",
},
}
for _, tc := range testCases {

View file

@ -230,6 +230,56 @@ teardown() {
assert [ ${#lines[@]} -eq 3 ]
}
@test "create: Try '--distro rhel --release 8.0.0'" {
run $TOOLBOX --assumeyes create --distro rhel --release 8.0.0
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 ]
}
@test "create: Try '--distro rhel --release 8.0.1'" {
run $TOOLBOX --assumeyes create --distro rhel --release 8.0.1
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 ]
}
@test "create: Try '--distro rhel --release 8.3.0'" {
run $TOOLBOX --assumeyes create --distro rhel --release 8.3.0
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 ]
}
@test "create: Try '--distro rhel --release 8.3.1'" {
run $TOOLBOX --assumeyes create --distro rhel --release 8.3.1
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 ]
}
@test "create: Try '--distro rhel --release foo'" {
run $TOOLBOX --assumeyes create --distro rhel --release foo
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 ]
}
@test "create: Try '--distro rhel --release 8.2foo'" {
run $TOOLBOX --assumeyes create --distro rhel --release 8.2foo
@ -250,6 +300,26 @@ teardown() {
assert [ ${#lines[@]} -eq 3 ]
}
@test "create: Try '--distro rhel --release -2.-1'" {
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 in the '<major>.<minor>' format."
assert_line --index 2 "Run 'toolbox --help' for usage."
assert [ ${#lines[@]} -eq 3 ]
}
@test "create: Try '--distro rhel --release 2.-1'" {
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 in the '<major>.<minor>' format."
assert_line --index 2 "Run 'toolbox --help' for usage."
assert [ ${#lines[@]} -eq 3 ]
}
@test "create: Try to create a container based on non-default distribution without providing version" {
local distro="fedora"
local system_id="$(get_system_id)"