github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/tests/acceptance/test_files/snapshot.bats (about) 1 load "$LIB_BATS_ASSERT/load.bash" 2 load "$LIB_BATS_SUPPORT/load.bash" 3 4 # These set of tests are skipped locally 5 # To run these tests locally set the SPIPETOOLS_TOKEN env var. 6 # These tests will be skipped locally unless the below env var is set. 7 8 function setup() { 9 if [[ -z "${SPIPETOOLS_TOKEN}" ]]; then 10 skip 11 fi 12 } 13 14 # These set of tests check the different types of output in query snapshot mode and not snapshot creation/upload 15 # Related to https://github.com/turbot/steampipe/issues/3112 16 17 @test "snapshot mode - query output csv" { 18 cd $FILE_PATH/test_data/mods/functionality_test_mod 19 20 steampipe query query.static_query_2 --snapshot --output csv --pipes-token $SPIPETOOLS_TOKEN --snapshot-location turbot-ops/clitesting > output.csv 21 22 # extract the snapshot url from the output 23 url=$(grep -o 'http[^"]*' output.csv) 24 echo $url 25 26 # checking for OS type, since sed command is different for linux and OSX 27 # removing the 15th line, since it contains snapshot upload link, which will be different in each run 28 if [[ "$OSTYPE" == "darwin"* ]]; then 29 run sed -i ".csv" "15d" output.csv 30 else 31 run sed -i "15d" output.csv 32 fi 33 cat output.csv 34 35 # create the snapshot DELETE Request URL 36 req_url=$($FILE_PATH/url_parse.sh $url) 37 echo $req_url 38 39 assert_equal "$(cat output.csv)" "$(cat $TEST_DATA_DIR/expected_static_query_csv_snapshot_mode.csv)" 40 rm -f output.* 41 42 # delete the snapshot from cloud workspace to avoid exceeding quota 43 curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" 44 } 45 46 @test "snapshot mode - query output json" { 47 skip 48 cd $FILE_PATH/test_data/mods/functionality_test_mod 49 50 steampipe query query.static_query_2 --snapshot --output json --pipes-token $SPIPETOOLS_TOKEN --snapshot-location turbot-ops/clitesting > output.json 51 52 # extract the snapshot url from the output 53 url=$(grep -o 'http[^"]*' output.json) 54 echo $url 55 56 # checking for OS type, since sed command is different for linux and OSX 57 # removing the 64th line, since it contains snapshot upload link, which will be different in each run 58 if [[ "$OSTYPE" == "darwin"* ]]; then 59 run sed -i ".csv" "64d" output.json 60 else 61 run sed -i "64d" output.json 62 fi 63 cat output.json 64 65 # create the snapshot DELETE Request URL 66 req_url=$($FILE_PATH/url_parse.sh $url) 67 echo $req_url 68 69 assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_static_query_json_snapshot_mode.json)" 70 rm -f output.* 71 72 # delete the snapshot from cloud workspace to avoid exceeding quota 73 curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" 74 } 75 76 @test "snapshot mode - query output table" { 77 cd $FILE_PATH/test_data/mods/functionality_test_mod 78 79 steampipe query query.static_query_2 --snapshot --output table --pipes-token $SPIPETOOLS_TOKEN --snapshot-location turbot-ops/clitesting > output.txt 80 81 # extract the snapshot url from the output 82 url=$(grep -o 'http[^"]*' output.txt) 83 echo $url 84 85 # checking for OS type, since sed command is different for linux and OSX 86 # removing the 18th line, since it contains snapshot upload link, which will be different in each run 87 if [[ "$OSTYPE" == "darwin"* ]]; then 88 run sed -i ".csv" "18d" output.txt 89 else 90 run sed -i "18d" output.txt 91 fi 92 cat output.txt 93 94 # create the snapshot DELETE Request URL 95 req_url=$($FILE_PATH/url_parse.sh $url) 96 echo $req_url 97 98 assert_equal "$(cat output.txt)" "$(cat $TEST_DATA_DIR/expected_static_query_table_snapshot_mode.txt)" 99 rm -f output.* 100 101 # delete the snapshot from cloud workspace to avoid exceeding quota 102 curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" 103 } 104 105 function teardown_file() { 106 # list running processes 107 ps -ef | grep steampipe 108 109 # check if any processes are running 110 num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ') 111 assert_equal $num 0 112 }