Skip to content

Commit

Permalink
Merge pull request #44 from bats-core/fix/verify-objects-with-dots
Browse files Browse the repository at this point in the history
#43 Cannot verify for objects with dots
  • Loading branch information
vincent-zurczak authored Jun 3, 2024
2 parents 85ce4ba + f6e5dfb commit 5dca7f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/utils.bash
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 13 additions & 1 deletion tests/test.detik.try.to.find.being.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -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 ]
Expand Down
11 changes: 11 additions & 0 deletions tests/test.detik.verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5dca7f5

Please sign in to comment.