From 30e70fc195510f44e4c1eacf65259c4a368b17da Mon Sep 17 00:00:00 2001 From: Vincent Zurczak Date: Wed, 21 Jul 2021 09:19:30 +0200 Subject: [PATCH 1/2] Simplify and clarify the documentation --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c83622d..8c6da1b 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,7 +313,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 verifies all the instances have this property value. From 48b29b48026adda352adf07f8b9b8df13e9c84df Mon Sep 17 00:00:00 2001 From: Vincent Zurczak Date: Wed, 21 Jul 2021 10:49:41 +0200 Subject: [PATCH 2/2] #29 Raise an error when no found item and no expected count --- README.md | 2 +- lib/detik.bash | 3 +++ tests/test.detik.try.to.verify.bats | 4 ++-- tests/test.detik.verify.bats | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8c6da1b..5baf9b4 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,7 @@ without having been verified, an error is thrown. Please, refer to [this section 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'." ]