Skip to content

Commit 5dca7f5

Browse files
Merge pull request #44 from bats-core/fix/verify-objects-with-dots
#43 Cannot verify for objects with dots
2 parents 85ce4ba + f6e5dfb commit 5dca7f5

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

lib/utils.bash

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#!/bin/bash
22

3+
# The pattern for resource types
4+
# (pod, PODs, complex.crd.resource, etc.)
5+
resource_type_pattern="[a-z][a-z.]+"
36

47
# The regex for the "try" key word
5-
try_regex_verify_is="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +is +'([^']+)'$"
6-
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 +'([^']+)'$"
7-
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 +'([^']+)'$"
8-
try_regex_verify_matches="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +([a-z]+) +named +'([^']+)' +and +verify +that +'([^']+)' +matches +'([^']+)'$"
9-
try_regex_find_being="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +([a-z]+) +named +'([^']+)' +with +'([^']+)' +being +'([^']+)'$"
10-
try_regex_find_matching="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +([a-z]+) +named +'([^']+)' +with +'([^']+)' +matching +'([^']+)'$"
8+
try_regex_verify_is="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +is +'([^']+)'$"
9+
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 +'([^']+)'$"
10+
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 +'([^']+)'$"
11+
try_regex_verify_matches="^at +most +([0-9]+) +times +every +([0-9]+)s +to +get +($resource_type_pattern) +named +'([^']+)' +and +verify +that +'([^']+)' +matches +'([^']+)'$"
12+
try_regex_find_being="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +($resource_type_pattern) +named +'([^']+)' +with +'([^']+)' +being +'([^']+)'$"
13+
try_regex_find_matching="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find +([0-9]+) +($resource_type_pattern) +named +'([^']+)' +with +'([^']+)' +matching +'([^']+)'$"
1114

1215
# The regex for the "verify" key word
13-
verify_regex_count_is="^there +is +(0|1) +([a-z]+) +named +'([^']+)'$"
14-
verify_regex_count_are="^there +are +([0-9]+) +([a-z]+) +named +'([^']+)'$"
15-
verify_regex_count_is_less_than="^there are less than +([0-9]+) +([a-z]+) +named +'([^']+)'$"
16-
verify_regex_count_is_more_than="^there are more than +([0-9]+) +([a-z]+) +named +'([^']+)'$"
17-
verify_regex_property_is="^'([^']+)' +is +'([^']+)' +for +([a-z]+) +named +'([^']+)'$"
18-
verify_regex_property_matches="^'([^']+)' +matches +'([^']+)' +for +([a-z]+) +named +'([^']+)'$"
16+
verify_regex_count_is="^there +is +(0|1) +($resource_type_pattern) +named +'([^']+)'$"
17+
verify_regex_count_are="^there +are +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$"
18+
verify_regex_count_is_less_than="^there are less than +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$"
19+
verify_regex_count_is_more_than="^there are more than +([0-9]+) +($resource_type_pattern) +named +'([^']+)'$"
20+
verify_regex_property_is="^'([^']+)' +is +'([^']+)' +for +($resource_type_pattern) +named +'([^']+)'$"
21+
verify_regex_property_matches="^'([^']+)' +matches +'([^']+)' +for +($resource_type_pattern) +named +'([^']+)'$"
1922

2023

2124
# Prints a string in lower case.

tests/test.detik.try.to.find.being.bats

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ mytest_with_spaces() {
124124
}
125125

126126

127-
@test "trying to find of a POD with upper-case letters" {
127+
@test "trying to find a POD with upper-case letters" {
128128
run try "at most 5 times eVery 5s to find 2 pods named 'nginx' with 'status' being 'RUNNING'"
129129
[ "$status" -eq 0 ]
130130
[ ${#lines[@]} -eq 3 ]
@@ -134,6 +134,18 @@ mytest_with_spaces() {
134134
}
135135

136136

137+
@test "trying to find resource whose type contains a dot" {
138+
# The value is not important. We want to make sure resource
139+
# types with dots is supported.
140+
run try "at most 5 times eVery 5s to find 2 settings.management.cattle.io named 'nginx' with 'status' being 'RUNNING'"
141+
[ "$status" -eq 0 ]
142+
[ ${#lines[@]} -eq 3 ]
143+
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
144+
[ "${lines[1]}" = "nginx-deployment-75675f5897-6dg9r has the right value (running)." ]
145+
[ "${lines[2]}" = "nginx-deployment-75675f5897-gstkw has the right value (running)." ]
146+
}
147+
148+
137149
@test "trying to verify the syntax check (invalid wording)" {
138150
run try "at most 5 times VERY 5hours to find 1 pod named 'nginx' with 'status' being 'RUNNING'"
139151
[ "$status" -eq 2 ]

tests/test.detik.verify.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ mytest_with_namespace() {
7676
}
7777

7878

79+
@test "verifying the number of resources with their type including dots" {
80+
# The value is not important. We want to make sure resource
81+
# types with dots is supported.
82+
run verify "There are 2 settings.management.cattle.io named 'nginx'"
83+
[ "$status" -eq 0 ]
84+
[ ${#lines[@]} -eq 2 ]
85+
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
86+
[ "${lines[1]}" = "Found 2 settings.management.cattle.io named nginx (as expected)." ]
87+
}
88+
89+
7990
@test "verifying the number of PODs with upper-case letters (with a different K8s namespace)" {
8091
DETIK_CLIENT_NAME="mytest_with_namespace"
8192
DETIK_CLIENT_NAMESPACE="test_ns"

0 commit comments

Comments
 (0)