Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#43 Cannot verify for objects with dots #44

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading