From cdfdc14958f9eab342fd660059e42d9a2565c533 Mon Sep 17 00:00:00 2001 From: Vincent Zurczak Date: Fri, 31 May 2024 15:04:05 +0200 Subject: [PATCH] #43 Cannot verify for objects with dots --- lib/utils.bash | 27 ++++++++++++++----------- tests/test.detik.try.to.find.being.bats | 14 ++++++++++++- tests/test.detik.verify.bats | 11 ++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index 0ab6252..b179bc7 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -1,21 +1,24 @@ #!/bin/bash +# The pattern for resource types +# (pod, PODs, complex.crd.resource, etc.) +resource_type_pattern="[a-z][a-z.]+" # The regex for the "try" key word -try_regex_verify_is="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +is +'([^']+)'$" -try_regex_verify_is_more_than="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +is more than +'([^']+)'$" -try_regex_verify_is_less_than="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +is less than +'([^']+)'$" -try_regex_verify_matches="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +matches +'([^']+)'$" -try_regex_find_being="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +([a-z]+) +named +'([^']+)' +with +'([^']+)' +being +'([^']+)'$" -try_regex_find_matching="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +([a-z]+) +named +'([^']+)' +with +'([^']+)' +matching +'([^']+)'$" +try_regex_verify_is="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +is +'([^']+)'$" +try_regex_verify_is_more_than="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +is more than +'([^']+)'$" +try_regex_verify_is_less_than="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +is less than +'([^']+)'$" +try_regex_verify_matches="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +matches +'([^']+)'$" +try_regex_find_being="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +($resource_type_pattern) +named +'([^']+)' +with +'([^']+)' +being +'([^']+)'$" +try_regex_find_matching="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +($resource_type_pattern) +named +'([^']+)' +with +'([^']+)' +matching +'([^']+)'$" # The regex for the "verify" key word -verify_regex_count_is="^there +is +(0|1) +([a-z]+) +named +'([^']+)'$" -verify_regex_count_are="^there +are +([0-9]+) +([a-z]+) +named +'([^']+)'$" -verify_regex_count_is_less_than="^there are less than +([0-9]+) +([a-z]+) +named +'([^']+)'$" -verify_regex_count_is_more_than="^there are more than +([0-9]+) +([a-z]+) +named +'([^']+)'$" -verify_regex_property_is="^'([^']+)' +is +'([^']+)' +for +([a-z]+) +named +'([^']+)'$" -verify_regex_property_matches="^'([^']+)' +matches +'([^']+)' +for +([a-z]+) +named +'([^']+)'$" +verify_regex_count_is="^there +is +(0|1) +($resource_type_pattern) +named +'([^']+)'$" +verify_regex_count_are="^there +are +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$" +verify_regex_count_is_less_than="^there are less than +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$" +verify_regex_count_is_more_than="^there are more than +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$" +verify_regex_property_is="^'([^']+)' +is +'([^']+)' +for +($resource_type_pattern) +named +'([^']+)'$" +verify_regex_property_matches="^'([^']+)' +matches +'([^']+)' +for +($resource_type_pattern) +named +'([^']+)'$" # Prints a string in lower case. diff --git a/tests/test.detik.try.to.find.being.bats b/tests/test.detik.try.to.find.being.bats index 3124815..fe70a88 100755 --- a/tests/test.detik.try.to.find.being.bats +++ b/tests/test.detik.try.to.find.being.bats @@ -124,7 +124,7 @@ mytest_with_spaces() { } -@test "trying to find of a POD with upper-case letters" { +@test "trying to find a POD with upper-case letters" { run try "at most 5 times eVery 5s to find 2 pods named 'nginx' with 'status' being 'RUNNING'" [ "$status" -eq 0 ] [ ${#lines[@]} -eq 3 ] @@ -134,6 +134,18 @@ mytest_with_spaces() { } +@test "trying to find resource whose type contains a dot" { + # The value is not important. We want to make sure resource + # types with dots is supported. + run try "at most 5 times eVery 5s to find 2 settings.management.cattle.io named 'nginx' with 'status' being 'RUNNING'" + [ "$status" -eq 0 ] + [ ${#lines[@]} -eq 3 ] + [ "${lines[0]}" = "Valid expression. Verification in progress..." ] + [ "${lines[1]}" = "nginx-deployment-75675f5897-6dg9r has the right value (running)." ] + [ "${lines[2]}" = "nginx-deployment-75675f5897-gstkw has the right value (running)." ] +} + + @test "trying to verify the syntax check (invalid wording)" { run try "at most 5 times VERY 5hours to find 1 pod named 'nginx' with 'status' being 'RUNNING'" [ "$status" -eq 2 ] diff --git a/tests/test.detik.verify.bats b/tests/test.detik.verify.bats index 73ba2d3..641e530 100755 --- a/tests/test.detik.verify.bats +++ b/tests/test.detik.verify.bats @@ -76,6 +76,17 @@ mytest_with_namespace() { } +@test "verifying the number of resources with their type including dots" { + # The value is not important. We want to make sure resource + # types with dots is supported. + run verify "There are 2 settings.management.cattle.io named 'nginx'" + [ "$status" -eq 0 ] + [ ${#lines[@]} -eq 2 ] + [ "${lines[0]}" = "Valid expression. Verification in progress..." ] + [ "${lines[1]}" = "Found 2 settings.management.cattle.io named nginx (as expected)." ] +} + + @test "verifying the number of PODs with upper-case letters (with a different K8s namespace)" { DETIK_CLIENT_NAME="mytest_with_namespace" DETIK_CLIENT_NAMESPACE="test_ns"