From bc6ce7502968af69f4b2c6a9b10249c80386e105 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Mon, 31 Jul 2023 19:05:01 +0530 Subject: [PATCH 1/8] add workspace profiles --- .../workspace_profiles_config/workspaces.spc | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/acceptance/test_data/source_files/config_tests/workspace_profiles_config/workspaces.spc diff --git a/tests/acceptance/test_data/source_files/config_tests/workspace_profiles_config/workspaces.spc b/tests/acceptance/test_data/source_files/config_tests/workspace_profiles_config/workspaces.spc new file mode 100644 index 0000000000..bc879b428a --- /dev/null +++ b/tests/acceptance/test_data/source_files/config_tests/workspace_profiles_config/workspaces.spc @@ -0,0 +1,69 @@ +workspace "default" { + cloud_host = "latestpipe.turbot.io/" + cloud_token = "spt_012faketoken34567890_012faketoken3456789099999" + mod_location = "sp_install_dir_default" + snapshot_location = "snaps" + workspace_database = "fk43e7" + search_path = "" + search_path_prefix = "abc" + watch = false + introspection = "info" + query_timeout = 180 + max_parallel = 1 + install_dir = "sp_install_dir_default" + theme = "plain" + progress = true + input = false + options "query" { + autocomplete = false + header = false + multi = true + output = "json" + separator = "|" + timing = true + } + options "check" { + header = false + output = "json" + separator = "|" + timing = true + } + options "dashboard" { + browser = true + } +} + +workspace "sample" { + cloud_host = "testpipe.turbot.io/" + cloud_token = "spt_012faketoken34567890_012faketoken3456789099998" + mod_location = "sp_install_dir_sample" + snapshot_location = "snaps2" + workspace_database = "fk43e6" + search_path = "abc,def" + search_path_prefix = "abc" + watch = true + introspection = "control" + query_timeout = 200 + max_parallel = 2 + install_dir = "sp_install_dir_sample" + theme = "dark" + progress = false + input = true + options "query" { + autocomplete = true + header = true + multi = false + output = "csv" + separator = "," + timing = false + } + options "check" { + header = true + output = "csv" + separator = "," + timing = false + } + options "dashboard" { + browser = false + } +} \ No newline at end of file From d6cbcc878ab252039f30408396add983beeaf803 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Mon, 31 Jul 2023 19:05:09 +0530 Subject: [PATCH 2/8] add timing tests --- tests/acceptance/test_files/config.bats | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/acceptance/test_files/config.bats diff --git a/tests/acceptance/test_files/config.bats b/tests/acceptance/test_files/config.bats new file mode 100644 index 0000000000..f06ec4f5d4 --- /dev/null +++ b/tests/acceptance/test_files/config.bats @@ -0,0 +1,67 @@ +load "$LIB_BATS_ASSERT/load.bash" +load "$LIB_BATS_SUPPORT/load.bash" + +function setup_file() { + cd $FILE_PATH/test_data/source_files/config_tests + export STEAMPIPE_WORKSPACE_PROFILES_LOCATION=$FILE_PATH/test_data/source_files/config_tests/workspace_profiles_config + export STEAMPIPE_DIAGNOSTICS=config_json +} + +@test "timing" { + + #### test command line args #### + + # steampipe query with timing set + run steampipe query "select 1" --timing + timing=$(echo $output | jq .timing) + echo "timing: $timing" + # timing should be true + assert_equal $timing true + + # steampipe check with timing set + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --timing + timing=$(echo $output | jq .timing) + cd - # go back to the previous directory + echo "timing: $timing" + # timing should be true + assert_equal $timing true + + #### test workspace profile options #### + + # steampipe query with no timing set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so timing should be set from the "default" workspace profile + run steampipe query "select 1" + timing=$(echo $output | jq .timing) + echo "timing: $timing" + # timing should be true(since options.query.timing=true in "default" workspace) + assert_equal $timing true + + # steampipe query with no timing set, but --workspace is set to "sample", + # so timing should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + timing=$(echo $output | jq .timing) + echo "timing: $timing" + # timing should be false(since options.query.timing=false in "sample" workspace) + assert_equal $timing false + + # steampipe check with no timing set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so timing should be set from the "default" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all + timing=$(echo $output | jq .timing) + cd - # go back to the previous directory + echo "timing: $timing" + # timing should be true(since options.check.timing=true in "default" workspace) + assert_equal $timing true + + # steampipe check with no timing set, but --workspace is set to "sample", + # so timing should be set from the "sample" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --workspace=sample + timing=$(echo $output | jq .timing) + cd - # go back to the previous directory + echo "timing: $timing" + # timing should be true(since options.check.timing=true in "default" workspace) + assert_equal $timing false +} From 34a4c4c907864b95d330f83ddb471be0fcb627f9 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 11:51:46 +0530 Subject: [PATCH 3/8] added other config tests --- tests/acceptance/test_files/config.bats | 242 +++++++++++++++++++++++- 1 file changed, 241 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/test_files/config.bats b/tests/acceptance/test_files/config.bats index f06ec4f5d4..55b2b5777f 100644 --- a/tests/acceptance/test_files/config.bats +++ b/tests/acceptance/test_files/config.bats @@ -62,6 +62,246 @@ function setup_file() { timing=$(echo $output | jq .timing) cd - # go back to the previous directory echo "timing: $timing" - # timing should be true(since options.check.timing=true in "default" workspace) + # timing should be false(since options.check.timing=false in "sample" workspace) assert_equal $timing false } + +@test "query-timeout" { + + #### test command line args #### + + # steampipe query with query-timeout set to 250 + run steampipe query "select 1" --query-timeout=250 + querytimeout=$(echo $output | jq '."query-timeout"') + echo "querytimeout: $querytimeout" + # query-timeout should be 250 + assert_equal $querytimeout 250 + + # steampipe check with query-timeout set to 240 + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --query-timeout=240 + querytimeout=$(echo $output | jq '."query-timeout"') + cd - # go back to the previous directory + echo "querytimeout: $querytimeout" + # query-timeout should be 240 + assert_equal $querytimeout 240 + + #### test ENV vars #### + + # steampipe query with STEAMPIPE_QUERY_TIMEOUT set to 250 + export STEAMPIPE_QUERY_TIMEOUT=250 + run steampipe query "select 1" + querytimeout=$(echo $output | jq '."query-timeout"') + echo "querytimeout: $querytimeout" + # query-timeout should be 250 + assert_equal $querytimeout 250 + + # steampipe check with STEAMPIPE_QUERY_TIMEOUT set to 240 + export STEAMPIPE_QUERY_TIMEOUT=240 + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all + querytimeout=$(echo $output | jq '."query-timeout"') + cd - # go back to the previous directory + echo "querytimeout: $querytimeout" + # query-timeout should be 240 + assert_equal $querytimeout 240 + unset STEAMPIPE_QUERY_TIMEOUT # unset the env var + + #### test workspace profile #### + + # steampipe query with no query-timeout set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so query-timeout should be set from the "default" workspace profile + run steampipe query "select 1" + querytimeout=$(echo $output | jq '."query-timeout"') + echo "querytimeout: $querytimeout" + # query-timeout should be 180(since query-timeout=180 in "default" workspace) + assert_equal $querytimeout 180 + + # steampipe query with no query-timeout set, but --workspace is set to "sample", + # so query-timeout should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + querytimeout=$(echo $output | jq '."query-timeout"') + echo "querytimeout: $querytimeout" + # query-timeout should be 200(since query-timeout=200 in "sample" workspace) + assert_equal $querytimeout 200 + + # steampipe check with no query-timeout set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so query-timeout should be set from the "default" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all + querytimeout=$(echo $output | jq '."query-timeout"') + cd - # go back to the previous directory + echo "querytimeout: $querytimeout" + # query-timeout should be 180(since query-timeout=180 in "default" workspace) + assert_equal $querytimeout 180 + + # steampipe check with no query-timeout set, but --workspace is set to "sample", + # so query-timeout should be set from the "sample" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --workspace=sample + querytimeout=$(echo $output | jq '."query-timeout"') + cd - # go back to the previous directory + echo "querytimeout: $querytimeout" + # query-timeout should be 200(since query-timeout=200 in "sample" workspace) + assert_equal $querytimeout 200 +} + +@test "output" { + + #### test command line args #### + + # steampipe query with output set to json + run steampipe query "select 1" --output=json + op=$(echo $output | jq .output) + echo "output: $op" + # output should be json + assert_equal $op '"json"' + + # steampipe check with output set to line + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --output=line + op=$(echo $output | jq .output) + cd - # go back to the previous directory + echo "output: $op" + # output should be line + assert_equal $op '"line"' + + #### test workspace profile options #### + + # steampipe query with no output set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so output should be set from the "default" workspace profile + run steampipe query "select 1" + op=$(echo $output | jq .output) + echo "output: $op" + # output should be json(since options.query.output=json in "default" workspace) + assert_equal $op '"json"' + + # steampipe query with no output set, but --workspace is set to "sample", + # so output should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + op=$(echo $output | jq .output) + echo "output: $op" + # output should be csv(since options.query.output=csv in "sample" workspace) + assert_equal $op '"csv"' + + # steampipe check with no output set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so output should be set from the "default" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all + op=$(echo $output | jq .output) + cd - # go back to the previous directory + echo "output: $op" + # output should be json(since options.check.output=json in "default" workspace) + assert_equal $op '"json"' + + # steampipe check with no output set, but --workspace is set to "sample", + # so output should be set from the "sample" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --workspace=sample + op=$(echo $output | jq .output) + cd - # go back to the previous directory + echo "output: $op" + # output should be csv(since options.check.output=csv in "sample" workspace) + assert_equal $op '"csv"' +} + +@test "header" { + + #### test command line args #### + + # steampipe query with header set + run steampipe query "select 1" --header + header=$(echo $output | jq .header) + echo "header: $header" + # header should be true + assert_equal $header true + + # steampipe check with header set + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --header + header=$(echo $output | jq .header) + cd - # go back to the previous directory + echo "header: $header" + # header should be true + assert_equal $header true + + #### test workspace profile options #### + + # steampipe query with no header set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so header should be set from the "default" workspace profile + run steampipe query "select 1" + header=$(echo $output | jq .header) + echo "header: $header" + # header should be false(since options.query.header=false in "default" workspace) + assert_equal $header false + + # steampipe query with no header set, but --workspace is set to "sample", + # so header should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + header=$(echo $output | jq .header) + echo "header: $header" + # header should be true(since options.query.header=true in "sample" workspace) + assert_equal $header true + + # steampipe check with no header set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so header should be set from the "default" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all + header=$(echo $output | jq .header) + cd - # go back to the previous directory + echo "header: $header" + # header should be false(since options.check.header=false in "default" workspace) + assert_equal $header false + + # steampipe check with no header set, but --workspace is set to "sample", + # so header should be set from the "sample" workspace profile + cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check + run steampipe check all --workspace=sample + header=$(echo $output | jq .header) + cd - # go back to the previous directory + echo "header: $header" + # header should be true(since options.check.header=true in "sample" workspace) + assert_equal $header true +} + +@test "multi" { + + #### test workspace profile options #### + + # steampipe query with no multi set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so multi should be set from the "default" workspace profile + run steampipe query "select 1" + multi=$(echo $output | jq .multi) + echo "multi: $multi" + # multi should be true(since options.query.multi=true in "default" workspace) + assert_equal $multi true + + # steampipe query with no multi set, but --workspace is set to "sample", + # so multi should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + multi=$(echo $output | jq .multi) + echo "multi: $multi" + # multi should be false(since options.query.multi=false in "sample" workspace) + assert_equal $multi false +} + +@test "autocomplete" { + + #### test workspace profile options #### + + # steampipe query with no autocomplete set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so autocomplete should be set from the "default" workspace profile + run steampipe query "select 1" + autocomplete=$(echo $output | jq .autocomplete) + echo "autocomplete: $autocomplete" + # autocomplete should be false(since options.query.autocomplete=false in "default" workspace) + assert_equal $autocomplete false + + # steampipe query with no autocomplete set, but --workspace is set to "sample", + # so autocomplete should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + autocomplete=$(echo $output | jq .autocomplete) + echo "autocomplete: $autocomplete" + # autocomplete should be true(since options.query.autocomplete=true in "sample" workspace) + assert_equal $autocomplete true +} From df1bac64a259b06d8f3ba998bc3f9431786ee713 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 11:53:01 +0530 Subject: [PATCH 4/8] add new test to workflows --- .github/workflows/release_cli_and_assets.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/release_cli_and_assets.yml b/.github/workflows/release_cli_and_assets.yml index 10a21752c7..aa473da62e 100644 --- a/.github/workflows/release_cli_and_assets.yml +++ b/.github/workflows/release_cli_and_assets.yml @@ -317,6 +317,7 @@ jobs: - "service" - "settings" - "search_path" + - "config" - "chaos_and_query" - "dynamic_schema" - "dynamic_aggregators" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 868facbdab..b1a4a50082 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,6 +95,7 @@ jobs: - "installation" - "service_and_plugin" - "blank_aggregators" + - "config" - "service" - "settings" - "search_path" From 8e5f5920672d2187cd469c86b707a540f7d64855 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 13:12:28 +0530 Subject: [PATCH 5/8] add debug --- tests/acceptance/test_files/config.bats | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/acceptance/test_files/config.bats b/tests/acceptance/test_files/config.bats index 55b2b5777f..1015e23cff 100644 --- a/tests/acceptance/test_files/config.bats +++ b/tests/acceptance/test_files/config.bats @@ -13,6 +13,7 @@ function setup_file() { # steampipe query with timing set run steampipe query "select 1" --timing + echo $output timing=$(echo $output | jq .timing) echo "timing: $timing" # timing should be true @@ -21,6 +22,7 @@ function setup_file() { # steampipe check with timing set cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --timing + echo $output timing=$(echo $output | jq .timing) cd - # go back to the previous directory echo "timing: $timing" @@ -32,6 +34,7 @@ function setup_file() { # steampipe query with no timing set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so timing should be set from the "default" workspace profile run steampipe query "select 1" + echo $output timing=$(echo $output | jq .timing) echo "timing: $timing" # timing should be true(since options.query.timing=true in "default" workspace) @@ -40,6 +43,7 @@ function setup_file() { # steampipe query with no timing set, but --workspace is set to "sample", # so timing should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output timing=$(echo $output | jq .timing) echo "timing: $timing" # timing should be false(since options.query.timing=false in "sample" workspace) @@ -49,6 +53,7 @@ function setup_file() { # so timing should be set from the "default" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all + echo $output timing=$(echo $output | jq .timing) cd - # go back to the previous directory echo "timing: $timing" @@ -59,6 +64,7 @@ function setup_file() { # so timing should be set from the "sample" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample + echo $output timing=$(echo $output | jq .timing) cd - # go back to the previous directory echo "timing: $timing" @@ -72,6 +78,7 @@ function setup_file() { # steampipe query with query-timeout set to 250 run steampipe query "select 1" --query-timeout=250 + echo $output querytimeout=$(echo $output | jq '."query-timeout"') echo "querytimeout: $querytimeout" # query-timeout should be 250 @@ -80,6 +87,7 @@ function setup_file() { # steampipe check with query-timeout set to 240 cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --query-timeout=240 + echo $output querytimeout=$(echo $output | jq '."query-timeout"') cd - # go back to the previous directory echo "querytimeout: $querytimeout" @@ -91,6 +99,7 @@ function setup_file() { # steampipe query with STEAMPIPE_QUERY_TIMEOUT set to 250 export STEAMPIPE_QUERY_TIMEOUT=250 run steampipe query "select 1" + echo $output querytimeout=$(echo $output | jq '."query-timeout"') echo "querytimeout: $querytimeout" # query-timeout should be 250 @@ -100,6 +109,7 @@ function setup_file() { export STEAMPIPE_QUERY_TIMEOUT=240 cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all + echo $output querytimeout=$(echo $output | jq '."query-timeout"') cd - # go back to the previous directory echo "querytimeout: $querytimeout" @@ -112,6 +122,7 @@ function setup_file() { # steampipe query with no query-timeout set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so query-timeout should be set from the "default" workspace profile run steampipe query "select 1" + echo $output querytimeout=$(echo $output | jq '."query-timeout"') echo "querytimeout: $querytimeout" # query-timeout should be 180(since query-timeout=180 in "default" workspace) @@ -120,6 +131,7 @@ function setup_file() { # steampipe query with no query-timeout set, but --workspace is set to "sample", # so query-timeout should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output querytimeout=$(echo $output | jq '."query-timeout"') echo "querytimeout: $querytimeout" # query-timeout should be 200(since query-timeout=200 in "sample" workspace) @@ -129,6 +141,7 @@ function setup_file() { # so query-timeout should be set from the "default" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all + echo $output querytimeout=$(echo $output | jq '."query-timeout"') cd - # go back to the previous directory echo "querytimeout: $querytimeout" @@ -139,6 +152,7 @@ function setup_file() { # so query-timeout should be set from the "sample" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample + echo $output querytimeout=$(echo $output | jq '."query-timeout"') cd - # go back to the previous directory echo "querytimeout: $querytimeout" @@ -152,6 +166,7 @@ function setup_file() { # steampipe query with output set to json run steampipe query "select 1" --output=json + echo $output op=$(echo $output | jq .output) echo "output: $op" # output should be json @@ -160,6 +175,7 @@ function setup_file() { # steampipe check with output set to line cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --output=line + echo $output op=$(echo $output | jq .output) cd - # go back to the previous directory echo "output: $op" @@ -171,6 +187,7 @@ function setup_file() { # steampipe query with no output set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so output should be set from the "default" workspace profile run steampipe query "select 1" + echo $output op=$(echo $output | jq .output) echo "output: $op" # output should be json(since options.query.output=json in "default" workspace) @@ -179,6 +196,7 @@ function setup_file() { # steampipe query with no output set, but --workspace is set to "sample", # so output should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output op=$(echo $output | jq .output) echo "output: $op" # output should be csv(since options.query.output=csv in "sample" workspace) @@ -188,6 +206,7 @@ function setup_file() { # so output should be set from the "default" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all + echo $output op=$(echo $output | jq .output) cd - # go back to the previous directory echo "output: $op" @@ -198,6 +217,7 @@ function setup_file() { # so output should be set from the "sample" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample + echo $output op=$(echo $output | jq .output) cd - # go back to the previous directory echo "output: $op" @@ -211,6 +231,7 @@ function setup_file() { # steampipe query with header set run steampipe query "select 1" --header + echo $output header=$(echo $output | jq .header) echo "header: $header" # header should be true @@ -219,6 +240,7 @@ function setup_file() { # steampipe check with header set cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --header + echo $output header=$(echo $output | jq .header) cd - # go back to the previous directory echo "header: $header" @@ -230,6 +252,7 @@ function setup_file() { # steampipe query with no header set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so header should be set from the "default" workspace profile run steampipe query "select 1" + echo $output header=$(echo $output | jq .header) echo "header: $header" # header should be false(since options.query.header=false in "default" workspace) @@ -238,6 +261,7 @@ function setup_file() { # steampipe query with no header set, but --workspace is set to "sample", # so header should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output header=$(echo $output | jq .header) echo "header: $header" # header should be true(since options.query.header=true in "sample" workspace) @@ -247,6 +271,7 @@ function setup_file() { # so header should be set from the "default" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all + echo $output header=$(echo $output | jq .header) cd - # go back to the previous directory echo "header: $header" @@ -257,6 +282,7 @@ function setup_file() { # so header should be set from the "sample" workspace profile cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample + echo $output header=$(echo $output | jq .header) cd - # go back to the previous directory echo "header: $header" @@ -271,6 +297,7 @@ function setup_file() { # steampipe query with no multi set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so multi should be set from the "default" workspace profile run steampipe query "select 1" + echo $output multi=$(echo $output | jq .multi) echo "multi: $multi" # multi should be true(since options.query.multi=true in "default" workspace) @@ -279,6 +306,7 @@ function setup_file() { # steampipe query with no multi set, but --workspace is set to "sample", # so multi should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output multi=$(echo $output | jq .multi) echo "multi: $multi" # multi should be false(since options.query.multi=false in "sample" workspace) @@ -292,6 +320,7 @@ function setup_file() { # steampipe query with no autocomplete set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so autocomplete should be set from the "default" workspace profile run steampipe query "select 1" + echo $output autocomplete=$(echo $output | jq .autocomplete) echo "autocomplete: $autocomplete" # autocomplete should be false(since options.query.autocomplete=false in "default" workspace) @@ -300,6 +329,7 @@ function setup_file() { # steampipe query with no autocomplete set, but --workspace is set to "sample", # so autocomplete should be set from the "sample" workspace profile run steampipe query "select 1" --workspace=sample + echo $output autocomplete=$(echo $output | jq .autocomplete) echo "autocomplete: $autocomplete" # autocomplete should be true(since options.query.autocomplete=true in "sample" workspace) From 016d038b9e7b75e61237420e27a2d7bcb04c6631 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 13:38:32 +0530 Subject: [PATCH 6/8] fix tests --- .../sp_install_dir_default/README.md | 1 + .../config_tests/sp_install_dir_env/README.md | 1 + .../sp_install_dir_sample/README.md | 1 + tests/acceptance/test_files/config.bats | 26 ------------------- 4 files changed, 3 insertions(+), 26 deletions(-) create mode 100644 tests/acceptance/test_data/source_files/config_tests/sp_install_dir_default/README.md create mode 100644 tests/acceptance/test_data/source_files/config_tests/sp_install_dir_env/README.md create mode 100644 tests/acceptance/test_data/source_files/config_tests/sp_install_dir_sample/README.md diff --git a/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_default/README.md b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_default/README.md new file mode 100644 index 0000000000..c36adcdbb4 --- /dev/null +++ b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_default/README.md @@ -0,0 +1 @@ +This is a test directory created to run acceptance tests. \ No newline at end of file diff --git a/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_env/README.md b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_env/README.md new file mode 100644 index 0000000000..c36adcdbb4 --- /dev/null +++ b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_env/README.md @@ -0,0 +1 @@ +This is a test directory created to run acceptance tests. \ No newline at end of file diff --git a/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_sample/README.md b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_sample/README.md new file mode 100644 index 0000000000..c36adcdbb4 --- /dev/null +++ b/tests/acceptance/test_data/source_files/config_tests/sp_install_dir_sample/README.md @@ -0,0 +1 @@ +This is a test directory created to run acceptance tests. \ No newline at end of file diff --git a/tests/acceptance/test_files/config.bats b/tests/acceptance/test_files/config.bats index 1015e23cff..d96360da2c 100644 --- a/tests/acceptance/test_files/config.bats +++ b/tests/acceptance/test_files/config.bats @@ -20,11 +20,9 @@ function setup_file() { assert_equal $timing true # steampipe check with timing set - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --timing echo $output timing=$(echo $output | jq .timing) - cd - # go back to the previous directory echo "timing: $timing" # timing should be true assert_equal $timing true @@ -51,22 +49,18 @@ function setup_file() { # steampipe check with no timing set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so timing should be set from the "default" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all echo $output timing=$(echo $output | jq .timing) - cd - # go back to the previous directory echo "timing: $timing" # timing should be true(since options.check.timing=true in "default" workspace) assert_equal $timing true # steampipe check with no timing set, but --workspace is set to "sample", # so timing should be set from the "sample" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample echo $output timing=$(echo $output | jq .timing) - cd - # go back to the previous directory echo "timing: $timing" # timing should be false(since options.check.timing=false in "sample" workspace) assert_equal $timing false @@ -85,11 +79,9 @@ function setup_file() { assert_equal $querytimeout 250 # steampipe check with query-timeout set to 240 - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --query-timeout=240 echo $output querytimeout=$(echo $output | jq '."query-timeout"') - cd - # go back to the previous directory echo "querytimeout: $querytimeout" # query-timeout should be 240 assert_equal $querytimeout 240 @@ -107,11 +99,9 @@ function setup_file() { # steampipe check with STEAMPIPE_QUERY_TIMEOUT set to 240 export STEAMPIPE_QUERY_TIMEOUT=240 - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all echo $output querytimeout=$(echo $output | jq '."query-timeout"') - cd - # go back to the previous directory echo "querytimeout: $querytimeout" # query-timeout should be 240 assert_equal $querytimeout 240 @@ -139,22 +129,18 @@ function setup_file() { # steampipe check with no query-timeout set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so query-timeout should be set from the "default" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all echo $output querytimeout=$(echo $output | jq '."query-timeout"') - cd - # go back to the previous directory echo "querytimeout: $querytimeout" # query-timeout should be 180(since query-timeout=180 in "default" workspace) assert_equal $querytimeout 180 # steampipe check with no query-timeout set, but --workspace is set to "sample", # so query-timeout should be set from the "sample" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample echo $output querytimeout=$(echo $output | jq '."query-timeout"') - cd - # go back to the previous directory echo "querytimeout: $querytimeout" # query-timeout should be 200(since query-timeout=200 in "sample" workspace) assert_equal $querytimeout 200 @@ -173,11 +159,9 @@ function setup_file() { assert_equal $op '"json"' # steampipe check with output set to line - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --output=line echo $output op=$(echo $output | jq .output) - cd - # go back to the previous directory echo "output: $op" # output should be line assert_equal $op '"line"' @@ -204,22 +188,18 @@ function setup_file() { # steampipe check with no output set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so output should be set from the "default" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all echo $output op=$(echo $output | jq .output) - cd - # go back to the previous directory echo "output: $op" # output should be json(since options.check.output=json in "default" workspace) assert_equal $op '"json"' # steampipe check with no output set, but --workspace is set to "sample", # so output should be set from the "sample" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample echo $output op=$(echo $output | jq .output) - cd - # go back to the previous directory echo "output: $op" # output should be csv(since options.check.output=csv in "sample" workspace) assert_equal $op '"csv"' @@ -238,11 +218,9 @@ function setup_file() { assert_equal $header true # steampipe check with header set - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --header echo $output header=$(echo $output | jq .header) - cd - # go back to the previous directory echo "header: $header" # header should be true assert_equal $header true @@ -269,22 +247,18 @@ function setup_file() { # steampipe check with no header set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, # so header should be set from the "default" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all echo $output header=$(echo $output | jq .header) - cd - # go back to the previous directory echo "header: $header" # header should be false(since options.check.header=false in "default" workspace) assert_equal $header false # steampipe check with no header set, but --workspace is set to "sample", # so header should be set from the "sample" workspace profile - cd $FILE_PATH/test_data/mods/functionality_test_mod # cd to a mod directory to run check run steampipe check all --workspace=sample echo $output header=$(echo $output | jq .header) - cd - # go back to the previous directory echo "header: $header" # header should be true(since options.check.header=true in "sample" workspace) assert_equal $header true From c65ecf2ded45d872aafe8485a261c0b2fc22d5c1 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 13:54:08 +0530 Subject: [PATCH 7/8] diagnostic check --- pkg/cmdconfig/builder.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/cmdconfig/builder.go b/pkg/cmdconfig/builder.go index b92e8f40e7..541e779b30 100644 --- a/pkg/cmdconfig/builder.go +++ b/pkg/cmdconfig/builder.go @@ -2,10 +2,12 @@ package cmdconfig import ( "fmt" + "os" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" + "github.com/turbot/steampipe/pkg/constants" "github.com/turbot/steampipe/pkg/utils" ) @@ -46,6 +48,11 @@ func OnCmd(cmd *cobra.Command) *CmdBuilder { utils.LogTime(fmt.Sprintf("cmd.%s.Run start", cmd.CommandPath())) defer utils.LogTime(fmt.Sprintf("cmd.%s.Run end", cmd.CommandPath())) + // if diagnostic mode is set, print out config and return + if _, ok := os.LookupEnv(constants.EnvDiagnostics); ok { + DisplayConfig() + return + } // run the original Run if originalRun != nil { originalRun(cmd, args) From b1d72c9aecf5acd45591e837f93d5c144c0a5258 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Tue, 1 Aug 2023 18:04:18 +0530 Subject: [PATCH 8/8] add tests --- .../config_tests/default_config.spc | 21 +++ tests/acceptance/test_files/config.bats | 170 ++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 tests/acceptance/test_data/source_files/config_tests/default_config.spc diff --git a/tests/acceptance/test_data/source_files/config_tests/default_config.spc b/tests/acceptance/test_data/source_files/config_tests/default_config.spc new file mode 100644 index 0000000000..ca9e8a0d32 --- /dev/null +++ b/tests/acceptance/test_data/source_files/config_tests/default_config.spc @@ -0,0 +1,21 @@ +options "database" { + port = 9193 + listen = "local" + search_path = "abc,def" + search_path_prefix = "def" + start_timeout = 30 + cache = true + cache_max_ttl = 900 + cache_max_size_mb = 1024 +} + +options "dashboard" { + port = 9193 + listen = "local" +} + +options "general" { + update_check = true + telemetry = "info" + max_parallel = 1 +} \ No newline at end of file diff --git a/tests/acceptance/test_files/config.bats b/tests/acceptance/test_files/config.bats index d96360da2c..aedbf0de49 100644 --- a/tests/acceptance/test_files/config.bats +++ b/tests/acceptance/test_files/config.bats @@ -309,3 +309,173 @@ function setup_file() { # autocomplete should be true(since options.query.autocomplete=true in "sample" workspace) assert_equal $autocomplete true } + +@test "separator" { + + #### test command line args #### + + # steampipe query with separator set + run steampipe query "select 1" --separator="|" + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be | + assert_equal $separator '"|"' + + # steampipe check with separator set + run steampipe check all --separator="," + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be , + assert_equal $separator '","' + + #### test workspace profile options #### + + # steampipe query with no separator set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so separator should be set from the "default" workspace profile + run steampipe query "select 1" + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be |(since options.query.separator="|" in "default" workspace) + assert_equal $separator '"|"' + + # steampipe query with no separator set, but --workspace is set to "sample", + # so separator should be set from the "sample" workspace profile + run steampipe query "select 1" --workspace=sample + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be ,(since options.query.separator="," in "sample" workspace) + assert_equal $separator '","' + + # steampipe check with no separator set, but STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set, + # so separator should be set from the "default" workspace profile + run steampipe check all + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be |(since options.check.separator="|" in "default" workspace) + assert_equal $separator '"|"' + + # steampipe check with no separator set, but --workspace is set to "sample", + # so separator should be set from the "sample" workspace profile + run steampipe check all --workspace=sample + echo $output + separator=$(echo $output | jq .separator) + echo "separator: $separator" + # separator should be ,(since options.check.separator="," in "sample" workspace) + assert_equal $separator '","' +} + +@test "database-password" { + + #### test command line args #### + + # steampipe service start with database-password set + run steampipe service start --database-password=redhood + echo $output + databasepassword=$(echo $output | jq '."database-password"') + echo "databasepassword: $databasepassword" + # database-password should be redhood + assert_equal $databasepassword '"redhood"' + + #### test ENV vars #### + + # steampipe query with STEAMPIPE_DATABASE_PASSWORD set + export STEAMPIPE_DATABASE_PASSWORD=deathstroke + run steampipe service start + echo $output + databasepassword=$(echo $output | jq '."database-password"') + echo "databasepassword: $databasepassword" + # database-password should be deathstroke + assert_equal $databasepassword '"deathstroke"' + + unset STEAMPIPE_DATABASE_PASSWORD # unset the env var +} + +@test "show-password" { + + #### test command line args #### + + # steampipe service start with show-password set + run steampipe service start --show-password + echo $output + showpassword=$(echo $output | jq '."show-password"') + echo "showpassword: $showpassword" + # show-password should be true + assert_equal $showpassword true +} + +@test "database-port" { + + #### test command line args #### + + # steampipe service start with database-port set + run steampipe service start --database-port=123 + echo $output + databaseport=$(echo $output | jq '."database-port"') + echo "databaseport: $databaseport" + # database-port should be 123 + assert_equal $databaseport 123 + + #### global options(default.spc) #### + + cp $FILE_PATH/test_data/source_files/config_tests/default_config.spc $STEAMPIPE_INSTALL_DIR/config/default.spc + + # steampipe service start with no database-port set, but database.port is set in default.spc(global config), + # so database-port should be set from there + run steampipe service start + echo $output + databaseport=$(echo $output | jq '."database-port"') + echo "databaseport: $databaseport" + # database-port should be 9193 + assert_equal $databaseport 9193 + + rm -f $STEAMPIPE_INSTALL_DIR/config/default.spc +} + +@test "database-listen" { + + #### test command line args #### + + # steampipe service start with database-listen set + run steampipe service start --database-listen=network + echo $output + databaselisten=$(echo $output | jq '."database-listen"') + echo "databaselisten: $databaselisten" + # database-listen should be network + assert_equal $databaselisten '"network"' + + #### global options(default.spc) #### + + cp $FILE_PATH/test_data/source_files/config_tests/default_config.spc $STEAMPIPE_INSTALL_DIR/config/default.spc + + # steampipe service start with no database-listen set, but database.listen is set in default.spc(global config), + # so database-listen should be set from there + run steampipe service start + echo $output + databaselisten=$(echo $output | jq '."database-listen"') + echo "databaselisten: $databaselisten" + # database-listen should be local + assert_equal $databaselisten '"local"' + + rm -f $STEAMPIPE_INSTALL_DIR/config/default.spc +} + +@test "cache-max-ttl" { + + #### test ENV vars #### + + # steampipe query with STEAMPIPE_CACHE_MAX_TTL set + export STEAMPIPE_CACHE_MAX_TTL=1000 + run steampipe service start + echo $output + cachemaxttl=$(echo $output | jq '."cache-max-ttl"') + echo "cachemaxttl: $cachemaxttl" + # cache-max-ttl should be 1000 + assert_equal $cachemaxttl 1000 + + unset STEAMPIPE_CACHE_MAX_TTL # unset the env var +}