Update tests

This commit is contained in:
Puskar Basu
2024-09-24 11:42:05 +05:30
parent 9e713885e9
commit 36740cdc81
11 changed files with 23 additions and 1545 deletions

View File

@@ -2,6 +2,7 @@ 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
@@ -20,6 +21,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
}
@test "steampipe cache functionality check OFF" {
skip "TODO - test using steampipe query command"
cd $FUNCTIONALITY_TEST_MOD
# set the env variable to false
@@ -183,6 +185,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
}
@test "test caching with cache=true in workspace profile" {
skip "TODO - test using steampipe query command"
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
cp $SRC_DATA_DIR/workspace_cache_enabled.spc $STEAMPIPE_INSTALL_DIR/config/workspace_cache_enabled.spc
@@ -206,6 +209,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
}
@test "test caching with cache=false in workspace profile" {
skip "TODO - test using steampipe query command"
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
cp $SRC_DATA_DIR/workspace_cache_disabled.spc $STEAMPIPE_INSTALL_DIR/config/workspace_cache_disabled.spc

View File

@@ -1,352 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
@test "steampipe check exitCode - no control alarms or errors" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check benchmark.all_controls_ok
assert_equal $status 0
cd -
}
@test "steampipe check exitCode - with controls in error" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check benchmark.control_check_rendering_benchmark
assert_equal $status 2
cd -
}
#@test "steampipe check exitCode - with controls in alarm" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe check benchmark.check_search_path_benchmark
# assert_equal $status 1
# cd -
#}
@test "steampipe check exitCode - with controls in error(running multiple benchmarks together)" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check benchmark.control_summary_benchmark benchmark.check_cache_benchmark
assert_equal $status 2
cd -
}
@test "steampipe check exitCode - runtime error(insufficient args)" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check
assert_equal $status 254
cd -
}
@test "steampipe check long control title" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.control_long_title --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_long_title.txt)"
cd -
}
@test "steampipe check short control title" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.control_short_title --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_short_title.txt)"
cd -
}
@test "steampipe check unicode control title" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.control_unicode_title --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_unicode_title.txt)"
cd -
}
@test "steampipe check reasons(very long, very short, unicode)" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.control_long_short_unicode_reasons --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_reasons.txt)"
cd -
}
@test "steampipe check control with all possible statuses(10 OK, 5 ALARM, 2 ERROR, 1 SKIP and 3 INFO)" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.sample_control_mixed_results_1 --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_mixed_results.txt)"
cd -
}
@test "steampipe check control with all resources in ALARM" {
cd $CONTROL_RENDERING_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check control.sample_control_all_alarms --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_all_alarm.txt)"
cd -
}
@test "steampipe check control with blank dimension" {
cd $BLANK_DIMENSION_VALUE_TEST_MOD
export STEAMPIPE_DISPLAY_WIDTH=100
run steampipe check all --progress=false --theme=plain
assert_output --partial "$(cat $TEST_DATA_DIR/expected_blank_dimension.txt)"
cd -
}
@test "steampipe check - output csv - no header" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --output=csv --progress=false --header=false
assert_output --partial "$(cat $TEST_DATA_DIR/expected_check_csv_noheader.csv)"
cd -
}
@test "steampipe check - output csv(check tags and dimensions sorting)" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_sorted_tags_and_dimensions --output=csv --progress=false
assert_output --partial "$(cat $TEST_DATA_DIR/expected_check_csv_sorted_tags.csv)"
cd -
}
@test "steampipe check - output json" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --output json --progress=false --export output.json
output=""
run jd "$TEST_DATA_DIR/expected_check_json.json" output.json
echo $output
assert_success
rm -f output.json
cd -
}
@test "steampipe check - export csv" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.csv --progress=false
assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv.csv)"
rm -f test.csv
cd -
}
@test "steampipe check - export csv - pipe separator" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.csv --separator="|" --progress=false
assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv_pipe_separator.csv)"
rm -f test.csv
cd -
}
@test "steampipe check - export csv(check tags and dimensions sorting)" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_sorted_tags_and_dimensions --export test.csv --progress=false
assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv_sorted_tags.csv)"
rm -f test.csv
cd -
}
@test "steampipe check - export json" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.json --progress=false
output=""
run jd "$TEST_DATA_DIR/expected_check_json.json" test.json
echo $output
assert_success
rm -f output.json
cd -
}
@test "steampipe check - export html" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.html --progress=false
# checking for OS type, since sed command is different for linux and OSX
# removing the 642nd line, since it contains file locations and timestamps
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".html" "642d" test.html
run sed -i ".html" "642d" test.html
run sed -i ".html" "642d" test.html
else
run sed -i "642d" test.html
run sed -i "642d" test.html
run sed -i "642d" test.html
fi
assert_equal "$(cat test.html)" "$(cat $TEST_DATA_DIR/expected_check_html.html)"
rm -rf test.html*
cd -
}
@test "steampipe check - export md" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.md --progress=false
# checking for OS type, since sed command is different for linux and OSX
# removing the 42nd line, since it contains file locations and timestamps
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".md" "42d" test.md
else
run sed -i "42d" test.md
fi
assert_equal "$(cat test.md)" "$(cat $TEST_DATA_DIR/expected_check_markdown.md)"
rm -rf test.md*
cd -
}
@test "steampipe check - export nunit3" {
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.xml --progress=false
# checking for OS type, since sed command is different for linux and OSX
# removing the 6th line, since it contains duration, and duration will be different in each run
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".xml" "6d" test.xml
else
run sed -i "6d" test.xml
fi
assert_equal "$(cat test.xml)" "$(cat $TEST_DATA_DIR/expected_check_nunit3.xml)"
rm -f test.xml*
cd -
}
@test "steampipe check - export snapshot" {
skip "deprecated"
cd $CONTROL_RENDERING_TEST_MOD
run steampipe check control.sample_control_mixed_results_1 --export test.sps --progress=false
# get the patch diff between the two snapshots
run jd -f patch $TEST_DATA_DIR/expected_check_snapshot.sps test.sps
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
cd -
}
@test "steampipe check all" {
cd $CHECK_ALL_MOD
run steampipe check all --export test.json --progress=false
output=""
run jd "$TEST_DATA_DIR/expected_check_all.json" test.json
echo $output
assert_success
rm -f output.json
cd -
}
@test "check all - export sps" {
skip "not implemented yet"
}
@test "check all - export file.sps" {
skip "not implemented yet"
}
@test "check single benchmark - export sps" {
skip "not implemented yet"
}
@test "check single benchmark - export file.sps" {
skip "not implemented yet"
}
@test "check multiple benchmark - export sps" {
skip "not implemented yet"
}
@test "check multiple benchmark - export file.sps" {
skip "not implemented yet"
}
@test "check all - export json" {
skip "not implemented yet"
}
@test "check all - export file.json" {
skip "not implemented yet"
}
@test "check single benchmark - export json" {
skip "not implemented yet"
}
@test "check single benchmark - export file.json" {
skip "not implemented yet"
}
@test "check multiple benchmark - export json" {
skip "not implemented yet"
}
@test "check multiple benchmark - export file.json" {
skip "not implemented yet"
}
@test "check all - export csv" {
skip "not implemented yet"
}
@test "check all - export file.csv" {
skip "not implemented yet"
}
@test "check single benchmark - export csv" {
skip "not implemented yet"
}
@test "check single benchmark - export file.csv" {
skip "not implemented yet"
}
@test "check multiple benchmark - export csv" {
skip "not implemented yet"
}
@test "check multiple benchmark - export file.csv" {
skip "not implemented yet"
}
## check search_path tests
#@test "steampipe check search_path_prefix when passed through command line" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe check control.search_path_test_1 --output json --search-path-prefix aws --export test.json
# assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
# rm -f test.json
#}
#@test "steampipe check search_path when passed through command line" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe check control.search_path_test_2 --output json --search-path chaos,b,c --export test.json
# assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
# rm -f test.json
#}
#@test "steampipe check search_path and search_path_prefix when passed through command line" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe check control.search_path_test_3 --output json --search-path chaos,b,c --search-path-prefix aws --export test.json
# assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
# rm -f test.json
#}
## plugin crash
@test "check whether the plugin is crashing or not" {
skip
cd $FUNCTIONALITY_TEST_MOD
run steampipe check benchmark.check_plugin_crash_benchmark
echo $output
[ $(echo $output | grep "ERROR: context canceled" | wc -l | tr -d ' ') -eq 0 ]
}
# testing the check summary output feature in steampipe
@test "check summary output" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check benchmark.control_summary_benchmark --theme plain
echo $output
# TODO: Find a way to store the output in a file and match it with the
# expected file. For now the work-around is to check whether the output
# contains `summary`
assert_output --partial 'Summary'
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}

View File

@@ -4,7 +4,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
## workspace tests
@test "generic config precedence test" {
skip 'disabled for now'
skip 'TODO - update and enable this test'
cp $FILE_PATH/test_data/source_files/config_tests/default.spc $STEAMPIPE_INSTALL_DIR/config/default.spc
# setup test folder and read the test-cases file

View File

@@ -1,147 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
@test "simple dashboard test" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.sibling_containers_report --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_sibling_containers"
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_sibling_containers_report.json test.sps
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard with 'with' blocks" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.testing_with_blocks --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_withs"
# sort the panels data by 'name' using jq sort_by(for ease in comparison)
cat test.sps | jq '.panels."dashbaord_withs.graph.with_testing".data.columns|=sort_by(.name)' > test2.json
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_many_withs_dashboard.json test2.json
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
rm -f test2.json
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard with 'text' blocks" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.testing_text_blocks --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_texts"
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_testing_text_blocks_dashboard.json test.sps
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard with 'card' blocks" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.testing_card_blocks --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_cards"
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_testing_card_blocks_dashboard.json test.sps
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard with node and edge blocks" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.testing_nodes_and_edges --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_graphs"
# sort the panels data by 'name' using jq sort_by(for ease in comparison)
cat test.sps | jq '.panels."dashboard_graphs.graph.node_and_edge_testing".data.columns|=sort_by(.name)' > test2.json
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_testing_nodes_and_edges_dashboard.json test2.json
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
rm -f test2.json
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard with 'input' and test --dashboard-input arg" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.testing_dashboard_inputs --export test.sps --output none --mod-location "$FILE_PATH/test_data/mods/dashboard_inputs" --dashboard-input new_input=test
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_testing_dashboard_inputs.json test.sps
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
@test "dashboard input with base" {
skip "deprecated"
# run a dashboard and shapshot the output
run steampipe dashboard dashboard.resource_details --export test.sps --output none --mod-location "$FILE_PATH/test_data/dashboard_inputs_with_base"
# get the patch diff between the two snapshots
run jd -f patch $SNAPSHOTS_DIR/expected_sps_testing_dashboard_inputs_with_base.json test.sps
echo $output
# run the script to evaluate the patch
# returns nothing if there is no diff(except start_time, end_time & search_path)
diff=$($FILE_PATH/json_patch.sh $output)
echo $diff
rm -f test.sps
# check if there is no diff returned by the script
assert_equal "$diff" ""
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}

View File

@@ -1,83 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
# TODO rename tests properly
@test "Parsing case 1 - top level query providers do not require query/sql blocks (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.query_providers_top_level --output snapshot
assert_success
}
@test "Parsing case 2 - top level query providers do not require query/sql blocks except control/query (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.query_providers_top_level_require_sql --output snapshot
assert_success
}
@test "Parsing case 3 - top level control/query always require query/sql block (FAIL)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_top_level_query_providers_fail
run steampipe dashboard dashboard.top_level_control_query_require_sql --output snapshot
assert_output --partial 'does not define a query or SQL'
}
@test "Parsing case 4 - nested query providers do require query/sql blocks (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.query_providers_nested --output snapshot
assert_success
}
@test "Parsing case 5 - nested query providers do require query/sql blocks (FAIL)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_nested_query_providers_fail
run steampipe dashboard dashboard.query_providers_nested --output snapshot
assert_output --partial 'does not define a query or SQL'
}
@test "Parsing case 6 - nested query providers do not require require query/sql blocks except images/cards (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.query_providers_nested_dont_require_sql --output snapshot
assert_success
}
@test "Parsing case 7 - top level node and edge providers do not require a query/sql block or a node/edge block (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.node_edge_providers_top_level --output snapshot
assert_success
}
@test "Parsing case 8 - nested node and edge providers always require a query/sql block or a node/edge block (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.node_edge_providers_nested --output snapshot
assert_success
}
@test "Parsing case 9 - nested node and edge providers do require a query/sql block or a node/edge block (FAIL)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_nested_node_edge_providers_fail
run steampipe dashboard dashboard.node_edge_providers_nested --output snapshot
assert_output --partial 'does not define a query or SQL, and has no edges/nodes'
}
@test "Parsing case 10 - nested dashboards (PASS)" {
cd $FILE_PATH/test_data/mods/dashboard_parsing_validation
run steampipe dashboard dashboard.nested_dashboards --output snapshot
assert_success
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}

View File

@@ -8,14 +8,6 @@ load "$LIB_BATS_SUPPORT/load.bash"
[ $status -ne 0 ]
}
@test "steampipe check fail with non-0 exit code" {
cd $WORKSPACE_DIR
# this check should fail with a non 0 exit code, due to insufficient args
run steampipe check
echo $status
[ $status -ne 0 ]
}
@test "steampipe query pass with 0 exit code" {
# this query should pass and return a 0 exit code
run steampipe query "select 1"

View File

@@ -431,27 +431,27 @@ load "$LIB_BATS_SUPPORT/load.bash"
# rm -f output.json
# }
@test "steampipe check --where | steampipe_introspection=control" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=control
steampipe check control.sample_control_1 --where "severity in ('high')" --export output.json
# @test "steampipe check --where | steampipe_introspection=control" {
# cd $SIMPLE_MOD_DIR
# export STEAMPIPE_INTROSPECTION=control
# steampipe check control.sample_control_1 --where "severity in ('high')" --export output.json
run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json
echo $output
assert_success
rm -f output.json
}
# run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json
# echo $output
# assert_success
# rm -f output.json
# }
@test "steampipe check --tag | steampipe_introspection=control" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=control
steampipe check control.sample_control_1 --tag foo=bar --export output.json
# @test "steampipe check --tag | steampipe_introspection=control" {
# cd $SIMPLE_MOD_DIR
# export STEAMPIPE_INTROSPECTION=control
# steampipe check control.sample_control_1 --tag foo=bar --export output.json
run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json
echo $output
assert_success
rm -f output.json
}
# run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json
# echo $output
# assert_success
# rm -f output.json
# }
function teardown_file() {
# list running processes

View File

@@ -1,461 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
############### QUERIES ###############
@test "query with default params and no params passed through CLI" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query query.query_params_with_all_defaults --output json
# store the reason field in `content`
content=$(echo $output | jq '.rows[0].reason')
assert_equal "$content" '"default_parameter_1 default_parameter_2 default_parameter_3"'
}
@test "query with default params and some positional params passed through CLI" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query "query.query_params_with_all_defaults(\"command_param_1\")" --output json
# store the reason field in `content`
content=$(echo $output | jq '.rows[0].reason')
assert_equal "$content" '"command_param_1 default_parameter_2 default_parameter_3"'
}
@test "query with default params and some named params passed through CLI" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query "query.query_params_with_all_defaults(p1 => \"command_param_1\")" --output json
# store the reason field in `content`
content=$(echo $output | jq '.rows[0].reason')
assert_equal "$content" '"command_param_1 default_parameter_2 default_parameter_3"'
}
@test "query with no default params and no params passed through CLI" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query query.query_params_with_no_defaults --output json
assert_output --partial 'failed to resolve args for functionality_test_mod.query.query_params_with_no_defaults: p1,p2,p3'
}
@test "query with no default params and all params passed through CLI" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query "query.query_params_with_all_defaults(\"command_param_1\",\"command_param_2\",\"command_param_3\")" --output json
# store the reason field in `content`
content=$(echo $output | jq '.rows[0].reason')
assert_equal "$content" '"command_param_1 command_param_2 command_param_3"'
}
@test "query specific array index from param - DISABLED" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe query query.query_array_params_with_default --output json
# # store the reason field in `content`
# content=$(echo $output | jq '.rows[0].reason')
# assert_equal "$content" '"default_p1_element_02"'
}
@test "query with invalid param syntax" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query "query.query_map_params_with_default(\"foo \")" --output json
# should return an error `invalid input syntax for type json`
assert_output --partial 'invalid input syntax for type json'
cd -
}
@test "query specific property from map param" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe query query.query_map_params_with_default --output json
# store the reason field in `content`
content=$(echo $output | jq '.rows[0].reason')
assert_equal "$content" '"default_property_value_01"'
}
############### CONTROLS ###############
@test "control with default params and no args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_defaults_and_no_args --export test.json
echo $output
ls
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"default_parameter_1 default_parameter_2 default_parameter_3"'
rm -f test.json
}
@test "control with default params and partial named args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_defaults_and_partial_named_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"default_parameter_1 command_parameter_2 default_parameter_3"'
rm -f test.json
}
@test "control with default params and partial positional args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_defaults_and_partial_positional_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 default_parameter_2 default_parameter_3"'
rm -f test.json
}
@test "control with default params and all named args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_defaults_and_all_named_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
rm -f test.json
}
@test "control with default params and all positional args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_defaults_and_all_positional_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
rm -f test.json
}
@test "control with no default params and no args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_no_defaults_and_no_args --output json
# should return an error `failed to resolve value for 3 parameters`
echo $output
[ $(echo $output | grep "failed to resolve value for 3 parameters" | wc -l | tr -d ' ') -eq 0 ]
}
@test "control with no default params and all args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_with_no_defaults_with_named_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
rm -f test.json
}
@test "control to access specific array index from param - DISABLED" {
# cd $FUNCTIONALITY_TEST_MOD
# run steampipe check control.query_params_array_with_default --export test.json
# # store the reason field in `content`
# content=$(cat test.json | jq '.controls[0].results[0].reason')
# assert_equal "$content" '"default_p1_element_02"'
# rm -f test.json
}
@test "control to access specific property from map" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_map_with_default --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"default_property_value_01"'
rm -f test.json
}
@test "control with invaild args syntax passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_params_invalid_arg_syntax --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `invalid input syntax for type json`, so the results should be empty
assert_equal "$content" ""
}
@test "control with inline sql with partial named args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_inline_sql_from_control_with_partial_named_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 default_parameter_2 command_parameter_3"'
rm -f test.json
}
@test "control with inline sql with partial positional args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_inline_sql_from_control_with_partial_positional_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 default_parameter_3"'
rm -f test.json
}
@test "control with inline sql with no args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_inline_sql_from_control_with_no_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"default_parameter_1 default_parameter_2 default_parameter_3"'
rm -f test.json
}
@test "control with inline sql with all named args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_inline_sql_from_control_with_all_named_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
rm -f test.json
}
@test "control with inline sql with all positional args passed in control" {
cd $FUNCTIONALITY_TEST_MOD
run steampipe check control.query_inline_sql_from_control_with_all_positional_args --export test.json
# store the reason field in `content`
content=$(cat test.json | jq '.controls[0].results[0].reason')
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
rm -f test.json
}
##
@test "control with neither query property nor sql property" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_no_query_no_sql --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `must define either a 'sql' property or a 'query' property`,
# so the results should be empty
assert_equal "$content" ""
}
@test "control with both query property and sql property" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_both_query_and_sql --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `must define either a 'sql' property or a 'query' property`,
# so the results should be empty
assert_equal "$content" ""
}
@test "control with both params property and query property" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_params_and_query --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `has 'query' property set so cannot define param blocks`,
# so the results should be empty
assert_equal "$content" ""
}
@test "control referring to query with no params definitions and named args passed" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_query_with_no_def_and_named_args_passed --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error since query has o parameter definitions,
# so the results should be empty
assert_equal "$content" ""
}
@test "control referring to query with no params defaults and partial positional args passed" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_insufficient_positional_args_passed --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `failed to resolve value for 3 parameters`
# so the results should be empty
assert_equal "$content" ""
}
@test "control referring to query with no params defaults and partial named args passed" {
cd $BAD_TEST_MOD_DIR
run steampipe check control.control_fail_with_insufficient_named_args_passed --output json
# store the results field in `content`
content=$(cat output.json | jq '.controls[0].results')
# should return an error `failed to resolve value for 3 parameters`,
# so the results should be empty
assert_equal "$content" ""
}
@test "control referring to query with empty list as param" {
cd $STRING_LIST_TEST_MOD
run steampipe check all --var 'string_list=[]'
assert_success
}
## traversal
# This test consists of a mod with nested folders, with mod.sp file within one of them(folder11).
# Running steampipe check from folder111 should give us the result since the mod.sp file is present somewhere
# up the directory tree
@test "load a mod from an arbitrarily nested sub folder - PASS" {
# go to the nested sub directory within the mod
cd $FILE_PATH/test_data/mods/nested_mod/folder1/folder11/folder111
run steampipe check all
assert_success
cd -
}
# This test consists of a mod with nested folders, with mod.sp file within one of them(folder11).
# Running steampipe check from folder1(i.e. _above_ the mod folder) should return an error, since the mod.sp file is present nowhere
# up the directory tree
@test "load a mod from an arbitrarily nested sub folder - FAIL" {
# go to the nested sub directory within the mod
cd $FILE_PATH/test_data/mods/nested_mod/folder1
run steampipe check all
assert_output --partial "This command requires a mod definition file (mod.sp) - could not find in the current directory tree."
cd -
}
# This test consists of a mod with nested folders, with no mod.sp file in any of them.
# Running steampipe check from folder11 should return an error, since the mod.sp file is present nowhere
# up the directory tree
# Running steampipe query from folder11 should give us the result since query is independent of mod.sp file.
@test "check and query from an arbitrarily nested sub folder - PASS & FAIL" {
# go to the nested sub directory within the mod
cd $FILE_PATH/test_data/mods/nested_mod_no_mod_file/folder1/folder11
run steampipe check all
assert_output --partial "This command requires a mod definition file (mod.sp) - could not find in the current directory tree."
run steampipe query control.check_1
assert_success
cd -
}
## parsing
@test "mod parsing" {
skip "Skipping for now, need to re-design"
# install necessary plugins
steampipe plugin install aws oci azure azuread
# create a directory to install the mods
target_directory=$(mktemp -d)
cd $target_directory
# install steampipe-mod-aws-compliance
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance
# go to the mod directory and run steampipe query to verify parsing
cd .steampipe/mods/github.com/turbot/steampipe-mod-aws-compliance@*
run steampipe query "select 1"
assert_success
cd -
# install steampipe-mod-aws-thrifty
steampipe mod install github.com/turbot/steampipe-mod-aws-thrifty
# go to the mod directory and run steampipe query to verify parsing
cd .steampipe/mods/github.com/turbot/steampipe-mod-aws-thrifty@*
run steampipe query "select 1"
assert_success
cd -
# install steampipe-mod-oci-compliance
steampipe mod install github.com/turbot/steampipe-mod-oci-compliance
# go to the mod directory and run steampipe query to verify parsing
cd .steampipe/mods/github.com/turbot/steampipe-mod-oci-compliance@*
run steampipe query "select 1"
assert_success
cd -
# install steampipe-mod-azure-compliance
steampipe mod install github.com/turbot/steampipe-mod-azure-compliance
# go to the mod directory and run steampipe query to verify parsing
cd .steampipe/mods/github.com/turbot/steampipe-mod-azure-compliance@*
run steampipe query "select 1"
assert_success
cd -
# remove the directory
cd ..
rm -rf $target_directory
# remove the connection config files
rm -f $STEAMPIPE_INSTALL_DIR/config/aws.spc
rm -f $STEAMPIPE_INSTALL_DIR/config/ibm.spc
rm -f $STEAMPIPE_INSTALL_DIR/config/oci.spc
rm -f $STEAMPIPE_INSTALL_DIR/config/azure.spc
rm -f $STEAMPIPE_INSTALL_DIR/config/azuread.spc
# uninstall the plugins
steampipe plugin uninstall aws oci azure azuread
# rerun steampipe to make sure they are removed from steampipe
steampipe query "select 1"
}
## dependency resolution tests
@test "complex mod dependency resolution - test vars resolution from require section of local mod" {
cd $FILE_PATH/test_data/mods/local_mod_with_args_in_require
steampipe mod install
run steampipe query dependency_vars_1.query.version --output csv
# check the output - query should use the value of variable from the local
# mod require section("v3.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v3.0.0 | v3.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v3.0.0,v3.0.0,ok'
rm -rf .steampipe/
rm -rf .mod.cache.json
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}

View File

@@ -1,160 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
@test "list with no mods installed" {
run steampipe mod list
assert_output --partial 'No mods installed.'
}
@test "install latest(plugin requirement not satisfied)" {
run steampipe mod install github.com/turbot/steampipe-mod-aws-compliance
assert_output --partial "dependency failed to install"
}
@test "install latest(--force)" {
run steampipe mod install github.com/turbot/steampipe-mod-aws-compliance --force
assert_output --partial 'Installed 1 mod:
local
└── github.com/turbot/steampipe-mod-aws-compliance'
# need the check the version from mod.sp file as well
}
@test "install latest and then run install" {
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance --force
run steampipe mod install
assert_output --partial 'All mods are up to date'
}
@test "install mod and list" {
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance@0.10 --force
run steampipe mod list
assert_output --partial '
local
└── github.com/turbot/steampipe-mod-aws-compliance@v0.10.0'
}
@test "install old version when latest already installed" {
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance --force
run steampipe mod install github.com/turbot/steampipe-mod-aws-compliance@0.1
assert_output --partial '
Downgraded 1 mod:
local
└── github.com/turbot/steampipe-mod-aws-compliance@v0.1.0'
}
@test "install mod version, remove .steampipe folder and then run install" {
# install particular mod version, remove .steampipe folder and run mod install
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance@0.1 --force
rm -rf .steampipe
run steampipe mod install
# should install the same cached version
# better message
assert_output --partial '
Installed 1 mod:
local
└── github.com/turbot/steampipe-mod-aws-compliance@v0.1.0'
}
@test "install mod version, remove .cache file and then run install" {
# install particular mod version, remove .mod.cache.json file and run mod install
steampipe mod install github.com/turbot/steampipe-mod-aws-compliance@0.1 --force
rm -rf .mod.cache.json
run steampipe mod install
# should install the same cached version
# better message
assert_output --partial '
Installed 1 mod:
local
└── github.com/turbot/steampipe-mod-aws-compliance@v0.1.0'
}
@test "install mod version should fail, since dependant mod has a requirement of different steampipe CLI version" {
run steampipe mod install github.com/pskrbasu/steampipe-mod-m4
assert_output --partial 'does not satisfy mod.m4 which requires version 10.99.99'
}
@test "install a mod with protocol in url" {
skip
run steampipe mod install https://github.com/turbot/steampipe-mod-hackernews-insights@0.4.0
# should install with the protocol in the url prefix
assert_output --partial '
Installed 1 mod:
local
└── github.com/turbot/steampipe-mod-hackernews-insights@v0.4.0'
}
# Installed 4 mods:
# local
# └── github.com/pskrbasu/steampipe-mod-top-level@v3.0.0
# ├── github.com/pskrbasu/steampipe-mod-dependency-1@v4.0.0
# └── github.com/pskrbasu/steampipe-mod-dependency-2@v3.0.0
# └── github.com/pskrbasu/steampipe-mod-dependency-1@v3.0.0
@test "complex mod dependency resolution - test tree structure" {
run steampipe mod install github.com/pskrbasu/steampipe-mod-top-level
# test the tree structure output
assert_output --partial '
Installed 4 mods:
local
└── github.com/pskrbasu/steampipe-mod-top-level@v3.0.0
├── github.com/pskrbasu/steampipe-mod-dependency-1@v4.0.0
└── github.com/pskrbasu/steampipe-mod-dependency-2@v3.0.0
└── github.com/pskrbasu/steampipe-mod-dependency-1@v3.0.0'
}
@test "complex mod dependency resolution - test benchmark and controls resolution 1" {
steampipe mod install github.com/pskrbasu/steampipe-mod-top-level
run steampipe check top_level.benchmark.bm_version_dependency_mod_1 --output csv
# check the output - benchmark should run the control and query from dependency mod 1 which will
# have the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | 4 | 4 | alarm |
# +--------+----------+--------+
assert_output --partial 'group_id,title,description,control_id,control_title,control_description,reason,resource,status,severity
top_level.benchmark.bm_version_dependency_mod_1,Benchmark version dependency mod 1,,dependency_1.control.version,,,4,4,alarm,'
}
@test "complex mod dependency resolution - test benchmark and controls resolution 2" {
steampipe mod install github.com/pskrbasu/steampipe-mod-top-level
run steampipe check top_level.benchmark.bm_version_dependency_mod_2 --output csv
# check the output - benchmark should run the control and query from dependency mod 2 which will
# have the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | 3 | 3 | ok |
# +--------+----------+--------+
assert_output --partial 'group_id,title,description,control_id,control_title,control_description,reason,resource,status,severity
top_level.benchmark.bm_version_dependency_mod_2,Benchmark version dependency mod 2,,dependency_2.control.version,,,3,3,ok,'
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}
function teardown() {
rm -rf .steampipe/
rm -rf .mod.cache.json
rm -rf mod.sp
}
function setup() {
cd $FILE_PATH/test_data/mods/mod_install
}

View File

@@ -1,134 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
### require tests ###
@test "running steampipe query with mod plugin requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_plugin_require_not_met
run steampipe query "select 1"
assert_output --partial 'Warning: could not find plugin which satisfies requirement'
cd -
}
@test "running steampipe check with mod plugin requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_plugin_require_not_met
run steampipe check all
assert_output --partial 'Warning: could not find plugin which satisfies requirement'
cd -
}
@test "running steampipe dashboard with mod plugin requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_plugin_require_not_met
run steampipe dashboard dashboard.sample_dashboard
assert_output --partial "Warning: could not find plugin which satisfies requirement 'gcp@99.21.0' - required by 'bad_mod_with_require_not_met'"
cd -
}
@test "running steampipe query with steampipe CLI version requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_sp_version_require_not_met
run steampipe query "select 1"
assert_output --partial 'does not satisfy mod.bad_mod_with_sp_version_require_not_met which requires version 10.99.99'
cd -
}
@test "running steampipe check with steampipe CLI version requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_sp_version_require_not_met
run steampipe check all
assert_output --partial 'does not satisfy mod.bad_mod_with_sp_version_require_not_met which requires version 10.99.99'
cd -
}
@test "running steampipe dashboard with steampipe CLI version requirement not met" {
cd $FILE_PATH/test_data/mods/bad_mod_with_sp_version_require_not_met
run steampipe dashboard dashboard.sample_dashboard
assert_output --partial 'does not satisfy mod.bad_mod_with_sp_version_require_not_met which requires version 10.99.99'
cd -
}
@test "running steampipe query with dependant mod version requirement not met(not installed)" {
cd $FILE_PATH/test_data/mods/bad_mod_with_dep_mod_version_require_not_met
run steampipe query "select 1"
assert_output --partial 'Error: failed to load workspace: not all dependencies are installed'
run steampipe mod install
assert_output --partial 'Error: 1 dependency failed to install - no version of github.com/turbot/steampipe-mod-aws-compliance found satisfying version constraint: 99.21.0'
cd -
}
@test "running steampipe check with dependant mod version requirement not met(not installed)" {
cd $FILE_PATH/test_data/mods/bad_mod_with_dep_mod_version_require_not_met
run steampipe check all
assert_output --partial 'Error: failed to load workspace: not all dependencies are installed'
run steampipe mod install
assert_output --partial 'Error: 1 dependency failed to install - no version of github.com/turbot/steampipe-mod-aws-compliance found satisfying version constraint: 99.21.0'
cd -
}
@test "running steampipe dashboard with dependant mod version requirement not met(not installed)" {
cd $FILE_PATH/test_data/mods/bad_mod_with_dep_mod_version_require_not_met
run steampipe dashboard dashboard.sample_dashboard
assert_output --partial 'Error: failed to load workspace: not all dependencies are installed'
run steampipe mod install
assert_output --partial 'Error: 1 dependency failed to install - no version of github.com/turbot/steampipe-mod-aws-compliance found satisfying version constraint: 99.21.0'
cd -
}
### deprecation tests ###
@test "old steampipe property" {
# go to the mod directory and run steampipe to get the deprectaion warning
# or error, and check the output
cd $FILE_PATH/test_data/mods/mod_with_old_steampipe_in_require
run steampipe query "select 1"
assert_output --partial "Warning: Property 'steampipe' is deprecated for mod require block - use a steampipe block instead"
}
@test "new steampipe block with old steampipe property" {
# go to the mod directory and run steampipe to get the deprectaion warning
# or error, and check the output
cd $FILE_PATH/test_data/mods/mod_with_old_steampipe_and_new_steampipe_block_in_require
run steampipe query "select 1"
assert_output --partial "Both 'steampipe' block and deprecated 'steampipe' property are set"
}
@test "new steampipe block with min_version" {
# go to the mod directory and run steampipe to get the deprectaion warning
# or error, and check the output
cd $FILE_PATH/test_data/mods/mod_with_new_steampipe_block
run steampipe query "select 1"
assert_output --partial "1"
}
@test "legacy 'requires' block" {
# go to the mod directory and run steampipe to get the deprectaion warning
# or error, and check the output
cd $FILE_PATH/test_data/mods/mod_with_legacy_requires_block
run steampipe query "select 1"
# TODO: update this test when the deprecation warning for legacy 'requries'
# block is added
assert_output --partial "1"
}
function teardown_file() {
# list running processes
ps -ef | grep steampipe
# check if any processes are running
num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
assert_equal $num 0
}

View File

@@ -1,181 +0,0 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
### workspace mod tests ###
# The following set of tests use a workspace mod(the mod is committed) with no dependencies and the
# variable has a default. The variable is then set from the command line, an auto spvars file, an explicit spvars
# file, or an ENV var. The tests below check that the variable is resolved correctly in each of these cases.
@test "test variable resolution in workspace mod set from command line(--var)" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_command_line
run steampipe query query.version --output csv --var version="v5.0.0"
# check the output - query should use the value of variable set from the command line
# --var flag ("v5.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v5.0.0 | v5.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v5.0.0,v5.0.0,ok'
}
@test "test variable resolution in workspace mod set from steampipe.spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_steampipe.spvars
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the steampipe spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}
@test "test variable resolution in workspace mod set from *.auto.spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_auto.spvars
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the auto spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}
@test "test variable resolution in workspace mod set from explicit spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_explicit_spvars
run steampipe query query.version --output csv --var-file='deps.spvars'
# check the output - query should use the value of variable set from the explicit spvars
# file ("v8.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v8.0.0 | v8.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v8.0.0,v8.0.0,ok'
}
@test "test variable resolution in workspace mod set from ENV" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_command_line
export SP_VAR_version=v9.0.0
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the ENV var
# SP_VAR_version ("v9.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v9.0.0 | v9.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v9.0.0,v9.0.0,ok'
}
### dependency mod tests ###
# The following set of tests use a dependency mod(the mod is committed) that has a variable dependency but the
# variable does not have a default. This means that the variable must be set from the command
# line, an auto spvars file, an explicit spvars file, or an ENV var. The tests below check that
# the variable is resolved correctly in each of these cases.
@test "test variable resolution in dependency mod set from command line(--var)" {
cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_command_line
run steampipe query dependency_vars_1.query.version --output csv --var dependency_vars_1.version="v5.0.0"
# check the output - query should use the value of variable set from the command line
# --var flag ("v5.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v5.0.0 | v5.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v5.0.0,v5.0.0,ok'
}
@test "test variable resolution in dependency mod set from steampipe.spvars file" {
cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_steampipe.spvars
run steampipe query dependency_vars_1.query.version --output csv
# check the output - query should use the value of variable set from the steampipe.spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}
@test "test variable resolution in dependency mod set from *.auto.spvars spvars file" {
cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_auto.spvars
run steampipe query dependency_vars_1.query.version --output csv
# check the output - query should use the value of variable set from the *.auto.spvars
# file ("v8.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v8.0.0 | v8.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v8.0.0,v8.0.0,ok'
}
### precedence tests ###
@test "test variable resolution precedence in workspace mod set from steampipe.spvars and *.auto.spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_precedence_set_from_both_spvars
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the *.auto.spvars("v8.0.0") file over
# steampipe.spvars("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v8.0.0 | v8.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v8.0.0,v8.0.0,ok'
}
@test "test variable resolution precedence in workspace mod set from steampipe.spvars and ENV" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_steampipe.spvars
export SP_VAR_version=v9.0.0
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the steampipe.spvars("v7.0.0") file over
# ENV("v9.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}
@test "test variable resolution precedence in workspace mod set from command line(--var) and steampipe.spvars file and *.auto.spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_precedence_set_from_both_spvars
run steampipe query query.version --output csv --var version="v5.0.0"
# check the output - query should use the value of variable set from the command line --var flag("v5.0.0") over
# steampipe.spvars("v7.0.0") and *.auto.spvars file("v8.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v5.0.0 | v5.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v5.0.0,v5.0.0,ok'
}