Skip to content

Commit e3ea96e

Browse files
Merge pull request #30 from bats-core/vz
Review assertions without an expected count
2 parents 0925f14 + 48b29b4 commit e3ea96e

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,15 @@ with a given property value. Example: count the number of PODs with a given name
280280
Hence this additional syntax.
281281

282282
```bash
283-
# Expecting 0 or 1 instance
284-
try "at most <number> times every <number>s \
285-
to find <0 or 1> <resource-type> named '<regular-expression>' \
286-
with '<property-name>' being '<expected-value>'"
287-
288-
# Expecting more than 1 instance
283+
# Expecting a given number of instances
289284
try "at most <number> times every <number>s \
290285
to find <number> <resource-type> named '<regular-expression>' \
291286
with '<property-name>' being '<expected-value>'"
292287
```
293288

294289
This is a checking loop.
295290
It breaks the loop if as soon as the assertion is verified. If it reaches the end of the loop
296-
with having been verified, an error is thrown. Please, refer to [this section](#property-names) for details
291+
without having been verified, an error is thrown. Please, refer to [this section](#property-names) for details
297292
about the property names.
298293

299294
This assertion is useful for PODs, whose life cycle changes take time.
@@ -318,11 +313,11 @@ try "at most <number> times every <number>s \
318313

319314
This is a checking loop.
320315
It breaks the loop if as soon as the assertion is verified. If it reaches the end of the loop
321-
with having been verified, an error is thrown. Please, refer to [this section](#property-names) for details
316+
without having been verified, an error is thrown. Please, refer to [this section](#property-names) for details
322317
about the property names.
323318

324319
This assertion verifies all the instances have this property value.
325-
But unlike the assertion type to count resources, you do not verify how many instances have this value.
320+
But unlike the assertion type to count resources, you do not verify how many instances have this value. Notice however that **if it finds 0 item verifying the property, the assertion fails**.
326321

327322

328323
### Property Names

lib/detik.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ verify_value() {
244244
else
245245
invalid=0
246246
fi
247+
# If no count expected, raise an error when 0 found items
248+
elif [[ "$valid" == "0" ]]; then
249+
invalid=102
247250
fi
248251

249252
return $invalid

tests/test.detik.try.to.verify.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mytest() {
110110

111111
@test "trying to verify the status of a POD with an invalid name" {
112112
run try "at most 1 times every 1s to get pods named 'nginx-something' and verify that 'status' is 'running'"
113-
[ "$status" -eq 0 ]
113+
[ "$status" -eq 3 ]
114114
[ ${#lines[@]} -eq 2 ]
115115
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
116116
[ "${lines[1]}" = "No resource of type 'pods' was found with the name 'nginx-something'." ]
@@ -129,7 +129,7 @@ mytest() {
129129

130130
@test "trying to verify the status of a POD with an invalid pattern name" {
131131
run try "at most 1 times every 1s to get pods named 'ngin.+x' and verify that 'status' is 'running'"
132-
[ "$status" -eq 0 ]
132+
[ "$status" -eq 3 ]
133133
[ ${#lines[@]} -eq 2 ]
134134
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
135135
[ "${lines[1]}" = "No resource of type 'pods' was found with the name 'ngin.+x'." ]

tests/test.detik.verify.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mytest_with_namespace() {
324324

325325
@test "verifying the status of a POD with an invalid name" {
326326
run verify "'status' is 'running' for pods named 'nginx-something'"
327-
[ "$status" -eq 0 ]
327+
[ "$status" -eq 3 ]
328328
[ ${#lines[@]} -eq 2 ]
329329
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
330330
[ "${lines[1]}" = "No resource of type 'pods' was found with the name 'nginx-something'." ]
@@ -343,7 +343,7 @@ mytest_with_namespace() {
343343

344344
@test "verifying the status of a POD with an invalid pattern name" {
345345
run verify "'status' is 'running' for pods named 'ngin.+x'"
346-
[ "$status" -eq 0 ]
346+
[ "$status" -eq 3 ]
347347
[ ${#lines[@]} -eq 2 ]
348348
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
349349
[ "${lines[1]}" = "No resource of type 'pods' was found with the name 'ngin.+x'." ]

0 commit comments

Comments
 (0)