Skip to content

Commit

Permalink
chore: fix variable name and more|less than tests are more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
massimoschembri committed Feb 23, 2024
1 parent ef40b60 commit 74dd2c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions lib/detik.bash
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ verify() {
echo "An empty expression was not expected."
return 1

elif [[ "$exp" =~ $verify_regex_count_is ]] || [[ "$exp" =~ $verify_regex_count_are ]] || [[ "$exp" =~ $verify_regex_count_less_than ]] || [[ "$exp" =~ $verify_regex_count_more_than ]]; then
elif [[ "$exp" =~ $verify_regex_count_is ]] || [[ "$exp" =~ $verify_regex_count_are ]] || [[ "$exp" =~ $verify_regex_count_is_less_than ]] || [[ "$exp" =~ $verify_regex_count_is_more_than ]]; then
card="${BASH_REMATCH[1]}"
resource=$(to_lower_case "${BASH_REMATCH[2]}")
name="${BASH_REMATCH[3]}"
Expand All @@ -168,15 +168,14 @@ verify() {
detik_debug "-----DETIK:end-----"
detik_debug ""

if [[ "$exp" =~ "less" ]]; then
if [[ "$exp" =~ "less than" ]]; then
if [[ "$result" -lt "$card" ]]; then
echo "Found $result $resource named $name (less than $card as expected)."
else
echo "Found $result $resource named $name (instead of less than $card expected)."
return 3

return 3
fi
elif [[ "$exp" =~ "more" ]]; then
elif [[ "$exp" =~ "more than" ]]; then
if [[ "$result" -gt "$card" ]]; then
echo "Found $result $resource named $name (more than $card as expected)."
else
Expand Down Expand Up @@ -284,15 +283,15 @@ verify_value() {
element=$(cut -d ' ' -f 1 <<< "$line" | xargs)

# Compare with an exact value (case insensitive)
if [[ "$exp" =~ "more" ]]; then
if [[ "$exp" =~ "more than" ]]; then
if [[ "$value" -gt "$expected_value" ]]; then
echo "$element matches the regular expression (found $value)."
valid=$((valid + 1))
else
echo "Current value for $element is not more than $expected_value..."
invalid=$((invalid + 1))
fi
elif [[ "$exp" =~ "less" ]]; then
elif [[ "$exp" =~ "less than" ]]; then
if [[ "$value" -lt "$expected_value" ]]; then
echo "$element matches the regular expression (found $value)."
valid=$((valid + 1))
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ try_regex_find_matching="^at +most +([0-9]+) +times +every +([0-9]+)s +to +find
# 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_less_than="^there are less than +([0-9]+) +([a-z]+) +named +'([^']+)'$"
verify_regex_count_more_than="^there are more than +([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 +'([^']+)'$"

Expand Down
2 changes: 1 addition & 1 deletion tests/test.detik.try.to.verify.is.bats
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,4 @@ mytest_deployment(){
[ ${#lines[@]} -eq 2 ]
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
[ "${lines[1]}" = "Current value for nginx is not less than 1..." ]
}
}

0 comments on commit 74dd2c9

Please sign in to comment.