update caching tests

This commit is contained in:
Puskar Basu
2024-10-07 15:07:07 +05:30
parent 197ced3e8c
commit d29bc2c09b

View File

@@ -2,47 +2,28 @@ load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
@test "steampipe cache functionality check ON" {
skip "TODO - test using steampipe query command"
run steampipe plugin install chaos
cd $FUNCTIONALITY_TEST_MOD
run steampipe check benchmark.check_cache_benchmark --export test.json --max-parallel 1
# start service to turn on caching
steampipe service start
# store the unique number from 1st control in `content`
content=$(cat test.json | jq '.groups[].controls[0].results[0].resource')
# store the unique number from 2nd control in `new_content`
new_content=$(cat test.json | jq '.groups[].controls[1].results[0].resource')
echo $content
echo $new_content
# run two queries to check if the results are the same
run steampipe query "select unique_col from chaos_cache_check limit 1" --output json > output1.json
run steampipe query "select unique_col from chaos_cache_check limit 1" --output json > output2.json
# verify that `content` and `new_content` are the same
assert_equal "$new_content" "$content"
rm -f test.json
}
# stop service
steampipe service stop
@test "steampipe cache functionality check OFF" {
skip "TODO - test using steampipe query command"
cd $FUNCTIONALITY_TEST_MOD
unique1=$(cat output1.json | jq '.rows[0].unique_col')
unique2=$(cat output2.json | jq '.rows[0].unique_col')
# set the env variable to false
export STEAMPIPE_CACHE=false
run steampipe check benchmark.check_cache_benchmark --export test.json --max-parallel 1
echo $unique1
echo $unique2
# store the unique number from 1st control in `content`
content=$(cat test.json | jq '.groups[].controls[0].results[0].resource')
# store the unique number from 2nd control in `new_content`
new_content=$(cat test.json | jq '.groups[].controls[1].results[0].resource')
echo $content
echo $new_content
assert_equal "$unique1" "$unique2"
# verify that `content` and `new_content` are not the same
if [[ "$content" == "$new_content" ]]; then
flag=1
else
flag=0
fi
assert_equal "$flag" "0"
rm -f test.json
rm -f output1.json
rm -f output2.json
}
@test "steampipe cache functionality check ON(check content of results, not just the unique column)" {
@@ -103,41 +84,6 @@ load "$LIB_BATS_SUPPORT/load.bash"
assert_not_equal "$unique1" "$unique3"
}
@test "verify cache ttl works when set in connections options" {
skip "skipping - this is a deprecated functionality"
cp $SRC_DATA_DIR/chaos_ttl_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_ttl_options.spc
# start the service
steampipe service start
# cache functionality check since cache=true in options
steampipe query "select unique_col from chaos_ttl_options.chaos_cache_check where id=2" --output json > out1.json
steampipe query "select unique_col from chaos_ttl_options.chaos_cache_check where id=2" --output json > out2.json
# wait for 15 seconds - the value of the TTL in connection options
sleep 15
# run the query again
steampipe query "select unique_col from chaos_ttl_options.chaos_cache_check where id=2" --output json > out3.json
# stop the service
steampipe service stop
unique1=$(cat out1.json | jq '.[].unique_col')
unique2=$(cat out2.json | jq '.[].unique_col')
unique3=$(cat out3.json | jq '.[].unique_col')
# remove the output and the config files
rm -f out*.json
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_ttl_options.spc
# the first and the seconds query should have the same value
assert_equal "$unique1" "$unique2"
# the third query should have a different value
assert_not_equal "$unique1" "$unique3"
}
@test "verify cache ttl works when set in database options" {
skip "TODO - fix and test using steampipe query command"
export STEAMPIPE_LOG=info