diff --git a/README.md b/README.md index c83622d..5baf9b4 100644 --- a/README.md +++ b/README.md @@ -280,12 +280,7 @@ with a given property value. Example: count the number of PODs with a given name Hence this additional syntax. ```bash -# Expecting 0 or 1 instance -try "at most times every s \ - to find <0 or 1> named '' \ - with '' being ''" - -# Expecting more than 1 instance +# Expecting a given number of instances try "at most times every s \ to find named '' \ with '' being ''" @@ -293,7 +288,7 @@ try "at most times every s \ This is a checking loop. It breaks the loop if as soon as the assertion is verified. If it reaches the end of the loop -with having been verified, an error is thrown. Please, refer to [this section](#property-names) for details +without having been verified, an error is thrown. Please, refer to [this section](#property-names) for details about the property names. This assertion is useful for PODs, whose life cycle changes take time. @@ -318,11 +313,11 @@ try "at most times every s \ This is a checking loop. It breaks the loop if as soon as the assertion is verified. If it reaches the end of the loop -with having been verified, an error is thrown. Please, refer to [this section](#property-names) for details +without having been verified, an error is thrown. Please, refer to [this section](#property-names) for details about the property names. This assertion verifies all the instances have this property value. -But unlike the assertion type to count resources, you do not verify how many instances have this value. +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**. ### Property Names diff --git a/lib/detik.bash b/lib/detik.bash index 928aeaa..d1dfbf6 100644 --- a/lib/detik.bash +++ b/lib/detik.bash @@ -244,6 +244,9 @@ verify_value() { else invalid=0 fi + # If no count expected, raise an error when 0 found items + elif [[ "$valid" == "0" ]]; then + invalid=102 fi return $invalid diff --git a/tests/test.detik.try.to.verify.bats b/tests/test.detik.try.to.verify.bats index d83a128..1d6ecd3 100755 --- a/tests/test.detik.try.to.verify.bats +++ b/tests/test.detik.try.to.verify.bats @@ -110,7 +110,7 @@ mytest() { @test "trying to verify the status of a POD with an invalid name" { run try "at most 1 times every 1s to get pods named 'nginx-something' and verify that 'status' is 'running'" - [ "$status" -eq 0 ] + [ "$status" -eq 3 ] [ ${#lines[@]} -eq 2 ] [ "${lines[0]}" = "Valid expression. Verification in progress..." ] [ "${lines[1]}" = "No resource of type 'pods' was found with the name 'nginx-something'." ] @@ -129,7 +129,7 @@ mytest() { @test "trying to verify the status of a POD with an invalid pattern name" { run try "at most 1 times every 1s to get pods named 'ngin.+x' and verify that 'status' is 'running'" - [ "$status" -eq 0 ] + [ "$status" -eq 3 ] [ ${#lines[@]} -eq 2 ] [ "${lines[0]}" = "Valid expression. Verification in progress..." ] [ "${lines[1]}" = "No resource of type 'pods' was found with the name 'ngin.+x'." ] diff --git a/tests/test.detik.verify.bats b/tests/test.detik.verify.bats index 458e5e1..3946f66 100755 --- a/tests/test.detik.verify.bats +++ b/tests/test.detik.verify.bats @@ -324,7 +324,7 @@ mytest_with_namespace() { @test "verifying the status of a POD with an invalid name" { run verify "'status' is 'running' for pods named 'nginx-something'" - [ "$status" -eq 0 ] + [ "$status" -eq 3 ] [ ${#lines[@]} -eq 2 ] [ "${lines[0]}" = "Valid expression. Verification in progress..." ] [ "${lines[1]}" = "No resource of type 'pods' was found with the name 'nginx-something'." ] @@ -343,7 +343,7 @@ mytest_with_namespace() { @test "verifying the status of a POD with an invalid pattern name" { run verify "'status' is 'running' for pods named 'ngin.+x'" - [ "$status" -eq 0 ] + [ "$status" -eq 3 ] [ ${#lines[@]} -eq 2 ] [ "${lines[0]}" = "Valid expression. Verification in progress..." ] [ "${lines[1]}" = "No resource of type 'pods' was found with the name 'ngin.+x'." ]