mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
Consolidates acceptance tests. Exclude force_stop and migration tests for Macos. Closes #2497
This commit is contained in:
26
.acceptance.goreleaser.yml
Normal file
26
.acceptance.goreleaser.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
- go clean -testcache && go test -timeout 30s ./...
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
- GO111MODULE=on
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
|
||||
id: "steampipe"
|
||||
binary: "steampipe"
|
||||
|
||||
archives:
|
||||
- files:
|
||||
- none*
|
||||
format: zip
|
||||
id: homebrew
|
||||
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
|
||||
format_overrides:
|
||||
- goos: linux
|
||||
format: tar.gz
|
||||
49
.github/workflows/test.yml
vendored
49
.github/workflows/test.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.19
|
||||
|
||||
|
||||
- name: Fetching Go Cache Paths
|
||||
id: go-cache-paths
|
||||
run: |
|
||||
@@ -46,16 +46,11 @@ jobs:
|
||||
path: ${{ steps.go-cache-paths.outputs.go-mod }}
|
||||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
|
||||
|
||||
- name: Run CLI Unit Tests
|
||||
run: |
|
||||
go clean -testcache
|
||||
go test -timeout 30s ./...
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v3
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist --skip-publish
|
||||
args: release --rm-dist --snapshot --parallelism 2 --config=.acceptance.goreleaser.yml
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -83,11 +78,30 @@ jobs:
|
||||
if-no-files-found: error
|
||||
|
||||
acceptance_test:
|
||||
name: Acceptance tests
|
||||
name: Test
|
||||
needs: goreleaser
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform: [macos-latest, ubuntu-latest]
|
||||
test_block:
|
||||
- "migration"
|
||||
- "service_and_plugin"
|
||||
- "search_path"
|
||||
- "chaos_and_query"
|
||||
- "dynamic_schema"
|
||||
- "cache"
|
||||
- "mod_install"
|
||||
- "mod"
|
||||
- "check"
|
||||
- "performance"
|
||||
- "exit_codes"
|
||||
- "force_stop"
|
||||
exclude:
|
||||
- platform: macos-latest
|
||||
test_block: migration
|
||||
- platform: macos-latest
|
||||
test_block: force_stop
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -131,9 +145,11 @@ jobs:
|
||||
echo "PATH=$PATH:$HOME/build:$GTIHUB_WORKSPACE/tests/acceptance/lib/bats/libexec" >> $GITHUB_ENV
|
||||
|
||||
- name: Install DB
|
||||
id: install-db
|
||||
continue-on-error: false
|
||||
run: |
|
||||
steampipe service start
|
||||
steampipe plugin install chaos
|
||||
steampipe service stop
|
||||
|
||||
- name: Run Test Suite
|
||||
@@ -142,19 +158,21 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: |
|
||||
chmod +x $GITHUB_WORKSPACE/tests/acceptance/run.sh
|
||||
$GITHUB_WORKSPACE/tests/acceptance/run.sh
|
||||
$GITHUB_WORKSPACE/tests/acceptance/run.sh ${{ matrix.test_block }}.bats
|
||||
steampipe service stop --force
|
||||
|
||||
|
||||
- name: Save Test Suite Logs
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: test-logs
|
||||
path: ~/.steampipe/logs
|
||||
if-no-files-found: error
|
||||
|
||||
|
||||
# This job checks whether the test suite has passed or not.
|
||||
# Since the exit_code is set only when the bats test suite pass, so we have added the if-conditional block
|
||||
# Since the exit_code is set only when the bats test suite pass,
|
||||
# we have added the if-conditional block
|
||||
- name: Check Test Passed/Failed
|
||||
if: ${{ success() }}
|
||||
continue-on-error: false
|
||||
run: |
|
||||
if [ ${{ steps.run-test-suite.outputs.exit_code }} -eq 0 ]; then
|
||||
@@ -171,6 +189,7 @@ jobs:
|
||||
# https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts#downloading-and-deleting-artifacts-after-a-workflow-run-is-complete
|
||||
name: Clean Up Artifacts
|
||||
needs: acceptance_test
|
||||
if: ${{ needs.acceptance_test.result == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Clean up Linux Build
|
||||
@@ -185,12 +204,6 @@ jobs:
|
||||
name: build-artifact-darwin
|
||||
failOnError: true
|
||||
|
||||
- name: Clean up Test Suite
|
||||
uses: geekyeggo/delete-artifact@v1
|
||||
with:
|
||||
name: test-artifact
|
||||
failOnError: true
|
||||
|
||||
- name: Clean up Test Suite Logs
|
||||
uses: geekyeggo/delete-artifact@v1
|
||||
with:
|
||||
|
||||
@@ -56,7 +56,12 @@ fi
|
||||
|
||||
echo "Running with STEAMPIPE_INSTALL_DIR set to $STEAMPIPE_INSTALL_DIR"
|
||||
|
||||
bats --tap $MY_PATH/test_files
|
||||
if [ $# -eq 0 ]; then
|
||||
# Run all test files
|
||||
bats --tap $MY_PATH/test_files
|
||||
else
|
||||
bats --tap $MY_PATH/test_files/${1}
|
||||
fi
|
||||
|
||||
# Setting the exit_code, to use in the github workflow(This only gets set to 0 when the above bats test suite passes)
|
||||
echo "::set-output name=exit_code::$(echo $?)"
|
||||
@@ -1,89 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
# If the installation fails, using 'return 1' from the global scope will halt the entire test suite.
|
||||
if [[ -z "$(steampipe query 'select 1 as val')" ]]; then
|
||||
echo "Steampipe installation failed" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
@test "steampipe plugin help is displayed when no sub command given" {
|
||||
run steampipe plugin
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_plugin_help_output.txt)"
|
||||
}
|
||||
|
||||
@test "steampipe service help is displayed when no sub command given" {
|
||||
run steampipe service
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_service_help_output.txt)"
|
||||
}
|
||||
|
||||
# Check that when disabled in config, we do not perform HTTP requests for update checks,
|
||||
# but we perform other scheduled operations
|
||||
@test "scheduled task run - no update check when disabled in config - TEST DISABLED" {
|
||||
# mkdir -p $STEAMPIPE_INSTALL_DIR/internal
|
||||
# mkdir -p $STEAMPIPE_INSTALL_DIR/config
|
||||
# mkdir -p $STEAMPIPE_INSTALL_DIR/logs
|
||||
#
|
||||
# echo "" > $STEAMPIPE_INSTALL_DIR/internal/update-check.json
|
||||
#
|
||||
# # set the `lastChecked` date in the update-check.json file to a past date
|
||||
# echo $(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json | jq '.lastChecked="2021-04-10T17:53:40+05:30"') > $STEAMPIPE_INSTALL_DIR/internal/update-check.json
|
||||
#
|
||||
# # extract the content of the current state file
|
||||
# checkFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json)
|
||||
#
|
||||
# # put in the config file with update disabled
|
||||
# cp ${SRC_DATA_DIR}/update_check_disabled.spc $STEAMPIPE_INSTALL_DIR/config/default.spc
|
||||
#
|
||||
# # put a dummy file for log - which should get deleted
|
||||
# touch $STEAMPIPE_INSTALL_DIR/logs/database-2021-03-16.log
|
||||
#
|
||||
# # setup trace logging
|
||||
# STEAMPIPE_LOG=TRACE
|
||||
#
|
||||
# # run steampipe
|
||||
# run steampipe plugin list
|
||||
#
|
||||
# # verify update request HTTP call was not made - the following TRACE output SHOULD NOT appear: "Sending HTTP Request"
|
||||
# [ $(echo $output | grep "Sending HTTP Request" | wc -l | tr -d ' ') -eq 0 ]
|
||||
#
|
||||
# # get the content of the new update-check.json file
|
||||
# newCheckFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json)
|
||||
#
|
||||
# # verify that the last check time was not updated.
|
||||
# assert_equal "$(echo $checkFileContent | jq '.lastChecked')" "$(echo $newCheckFileContent | jq '.lastChecked')"
|
||||
#
|
||||
}
|
||||
|
||||
# Check that when disabled in environment, we do not perform HTTP requests for update checks,
|
||||
# but we perform other scheduled operations
|
||||
#@test "scheduled task run - no update check when disabled in ENV - TEST DISABLED" {
|
||||
# # set the `lastChecked` date in the update-check.json file to a past date
|
||||
# echo $(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json| jq '.lastChecked="2021-04-10T17:53:40+05:30"') > $STEAMPIPE_INSTALL_DIR/internal/update-check.json
|
||||
#
|
||||
# # extract the content of the current state file
|
||||
# checkFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json)
|
||||
#
|
||||
# # update ENV to disable update check
|
||||
# echo "" > $STEAMPIPE_INSTALL_DIR/config/default.spc
|
||||
# STEAMPIPE_UPDATE_CHECK=false
|
||||
#
|
||||
# # put a dummy file for log - which should get deleted
|
||||
# touch $STEAMPIPE_INSTALL_DIR/logs/database-2021-03-16.log
|
||||
#
|
||||
# # setup trace logging
|
||||
# STEAMPIPE_LOG=TRACE
|
||||
#
|
||||
# # run steampipe
|
||||
# run steampipe plugin list
|
||||
#
|
||||
# # verify update request HTTP call was not made - the following TRACE output SHOULD NOT appear: "Sending HTTP Request"
|
||||
# [ $(echo $output | grep "Sending HTTP Request" | wc -l | tr -d ' ') -eq 0 ]
|
||||
#
|
||||
# # get the content of the new update-check.json file
|
||||
# newCheckFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update-check.json)
|
||||
#
|
||||
# # verify that the last check time was not updated.
|
||||
# assert_equal "$(echo $checkFileContent | jq '.lastChecked')" "$(echo $newCheckFileContent | jq '.lastChecked')"
|
||||
#
|
||||
#}
|
||||
@@ -1,109 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "steampipe service start" {
|
||||
run steampipe service start
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe service restart" {
|
||||
run steampipe service restart
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe service stop" {
|
||||
run steampipe service stop
|
||||
assert_success
|
||||
}
|
||||
|
||||
#upodate
|
||||
|
||||
# @test "steampipe service start --database-port 8765" {
|
||||
# run steampipe service start --database-port 8765
|
||||
# assert_equal $(netstat -an tcp | grep LISTEN | grep tcp | grep 8765 | wc -l) 2
|
||||
# steampipe service stop
|
||||
# }
|
||||
|
||||
# @test "steampipe service start --database-listen local --database-port 8765" {
|
||||
# run steampipe service start --database-listen local --database-port 8765
|
||||
# assert_equal $(netstat -an tcp | grep LISTEN | grep tcp | grep 8765 | wc -l) 2
|
||||
# assert_equal $(netstat -an tcp | grep LISTEN | grep tcp | grep 127.0.0.1 | grep 8765 | wc -l) 1
|
||||
# assert_equal $(netstat -an tcp | grep LISTEN | grep tcp | grep ::1 | grep 8765 | wc -l) 1
|
||||
# steampipe service stop
|
||||
# }
|
||||
|
||||
@test "custom database name" {
|
||||
# Set the STEAMPIPE_INITDB_DATABASE_NAME env variable
|
||||
export STEAMPIPE_INITDB_DATABASE_NAME="custom_db_name"
|
||||
|
||||
target_install_directory=$(mktemp -d)
|
||||
|
||||
# Start the service
|
||||
run steampipe service start --install-dir $target_install_directory
|
||||
echo $output
|
||||
# Check if database name in the output is the same
|
||||
assert_output --partial 'custom_db_name'
|
||||
|
||||
# Extract password from the state file
|
||||
db_name=$(cat $target_install_directory/internal/steampipe.json | jq .database)
|
||||
echo $db_name
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$db_name" "\"custom_db_name\""
|
||||
|
||||
run steampipe service stop --install-dir $target_install_directory
|
||||
|
||||
rm -rf $target_install_directory
|
||||
}
|
||||
|
||||
@test "custom database name - should not start with uppercase characters" {
|
||||
# Set the STEAMPIPE_INITDB_DATABASE_NAME env variable
|
||||
export STEAMPIPE_INITDB_DATABASE_NAME="Custom_db_name"
|
||||
|
||||
target_install_directory=$(mktemp -d)
|
||||
|
||||
# Start the service
|
||||
run steampipe service start --install-dir $target_install_directory
|
||||
|
||||
assert_failure
|
||||
run steampipe service stop --force
|
||||
rm -rf $target_install_directory
|
||||
}
|
||||
|
||||
@test "steampipe service stop should not trigger daily checks and tasks" {
|
||||
run steampipe service start
|
||||
|
||||
# set the `lastChecked` date in the update-check.json file to a past date
|
||||
echo $(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json | jq '.last_checked="2021-04-10T17:53:40+05:30"') > $STEAMPIPE_INSTALL_DIR/internal/update_check.json
|
||||
|
||||
# get the content of the current update-check.json file
|
||||
checkFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json)
|
||||
|
||||
run steampipe service stop
|
||||
|
||||
# get the content of the new update-check.json file
|
||||
newCheckFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json)
|
||||
|
||||
assert_equal "$(echo $newCheckFileContent | jq '.last_checked')" '"2021-04-10T17:53:40+05:30"'
|
||||
}
|
||||
|
||||
@test "start service, install plugin and query" {
|
||||
# start service
|
||||
steampipe service start
|
||||
|
||||
# install plugin
|
||||
steampipe plugin install chaos
|
||||
|
||||
# query the plugin
|
||||
run steampipe query "select time_col from chaos_cache_check limit 1"
|
||||
# check if the query passes
|
||||
assert_success
|
||||
|
||||
# stop service
|
||||
steampipe service stop
|
||||
|
||||
# check service status
|
||||
run steampipe service status
|
||||
|
||||
assert_output "$output" "Service is not running"
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "start service and verify that passwords stored in .passwd and steampipe.json are same" {
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
pass_file_pass=\"${pass_file_pass}\"
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "$pass_file_pass"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and verify that the password used in flag and stored in steampipe.json are same" {
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"abcd-efgh-ijkl\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with password in env variable and verify that the password used in env and stored in steampipe.json are same" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"dcba-hgfe-lkji\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and env variable set, verify that the password used in flag gets higher precedence and is stored in steampipe.json" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"abcd-efgh-ijkl\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service after removing .passwd file, verify new .passwd file gets created and also passwords stored in .passwd and steampipe.json are same" {
|
||||
# Remove the .passwd file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/internal/.passwd
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Extract password stored in new .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
pass_file_pass=\"${pass_file_pass}\"
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "$pass_file_pass"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and verify that the password used in flag is not stored in .passwd file" {
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should not be equal
|
||||
if [[ "$pass_file_pass" != "abcd-efgh-ijkl" ]]
|
||||
then
|
||||
temp=1
|
||||
fi
|
||||
|
||||
assert_equal "$temp" "1"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with password in env variable and verify that the password used in env is not stored in .passwd file" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should not be equal
|
||||
if [[ "$pass_file_pass" != "dcba-hgfe-lkji" ]]
|
||||
then
|
||||
temp=1
|
||||
fi
|
||||
|
||||
assert_equal "$temp" "1"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "steampipe plugin install" {
|
||||
run steampipe plugin install chaos
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe plugin list" {
|
||||
run steampipe plugin list
|
||||
assert_success
|
||||
}
|
||||
|
||||
#@test "steampipe plugin uninstall" {
|
||||
# run steampipe plugin uninstall
|
||||
# assert_success
|
||||
#}
|
||||
@@ -1,67 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "select * from chaos.chaos_high_row_count order by column_0" {
|
||||
run steampipe query --output json "select * from chaos.chaos_high_row_count order by column_0 limit 10"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_1.json)"
|
||||
}
|
||||
|
||||
@test "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'" {
|
||||
run steampipe query --output json "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_2.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_high_column_count order by column_0" {
|
||||
run steampipe query --output json "select * from chaos.chaos_high_column_count order by column_0 limit 10"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_3.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_hydrate_columns_dependency where id='0'" {
|
||||
run steampipe query --output json "select * from chaos.chaos_hydrate_columns_dependency where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_5.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_list_error" {
|
||||
run steampipe query "select fatal_error from chaos.chaos_list_errors"
|
||||
assert_output --partial 'fatalError'
|
||||
}
|
||||
|
||||
@test "select panic from chaos.chaos_get_errors where id=0" {
|
||||
run steampipe query --output json "select panic from chaos.chaos_get_errors where id=0"
|
||||
assert_output --partial 'Panic'
|
||||
}
|
||||
|
||||
@test "select error from chaos_transform_errors" {
|
||||
run steampipe query "select error from chaos_transform_errors"
|
||||
assert_output --partial 'TRANSFORM ERROR'
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_hydrate_delay" {
|
||||
run steampipe query --output json "select delay from chaos.chaos_hydrate_errors order by id"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_parallel_hydrate_columns where id='0'" {
|
||||
run steampipe query --output json "select * from chaos.chaos_parallel_hydrate_columns where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_11.json)"
|
||||
}
|
||||
|
||||
@test "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'" {
|
||||
run steampipe query --output json "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_12.json)"
|
||||
}
|
||||
|
||||
@test "select transform_method_column from chaos_transforms order by id" {
|
||||
run steampipe query --output json "select transform_method_column from chaos_transforms order by id"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_14.json)"
|
||||
}
|
||||
|
||||
@test "select parent_should_ignore_error from chaos.chaos_list_parent_child" {
|
||||
run steampipe query "select parent_should_ignore_error from chaos.chaos_list_parent_child"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "select from_qual_column from chaos_transforms where id=2" {
|
||||
run steampipe query --output json "select from_qual_column from chaos_transforms where id=2"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_13.json)"
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_4 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_5 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path and search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_6 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "check whether the plugin is crashing or not" {
|
||||
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 ]
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "steampipe cache functionality check ON" {
|
||||
run steampipe plugin install chaos
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
|
||||
run steampipe check benchmark.check_cache_benchmark --export json --max-parallel 1
|
||||
|
||||
# store the unique number from 1st control in `content`
|
||||
content=$(cat benchmark.*.json | jq '.groups[].controls[0].results[0].resource')
|
||||
# store the unique number from 2nd control in `new_content`
|
||||
new_content=$(cat benchmark.*.json | jq '.groups[].controls[1].results[0].resource')
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# verify that `content` and `new_content` are the same
|
||||
assert_equal "$new_content" "$content"
|
||||
rm -f benchmark.*.json
|
||||
}
|
||||
|
||||
@test "steampipe cache functionality check OFF" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
|
||||
# set the env variable to false
|
||||
export STEAMPIPE_CACHE=false
|
||||
run steampipe check benchmark.check_cache_benchmark --export json --max-parallel 1
|
||||
|
||||
# store the unique number from 1st control in `content`
|
||||
content=$(cat benchmark.*.json | jq '.groups[].controls[0].results[0].resource')
|
||||
# store the unique number from 2nd control in `new_content`
|
||||
new_content=$(cat benchmark.*.json | jq '.groups[].controls[1].results[0].resource')
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# verify that `content` and `new_content` are not the same
|
||||
if [[ "$content" == "$new_content" ]]; then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
rm -f benchmark.*.json
|
||||
}
|
||||
|
||||
@test "steampipe cache functionality check ON(check content of results, not just the unique column)" {
|
||||
# start service to turn on caching
|
||||
steampipe service start
|
||||
|
||||
steampipe query "select unique_col, a, b from chaos_cache_check" --output json &> output1.json
|
||||
# store the result from 1st query in `content`
|
||||
content=$(cat output1.json)
|
||||
|
||||
steampipe query "select unique_col, a, b from chaos_cache_check" --output json &> output2.json
|
||||
# store the result from 2nd query in `new_content`
|
||||
new_content=$(cat output2.json)
|
||||
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# stop service
|
||||
steampipe service stop
|
||||
|
||||
# verify that `content` and `new_content` are the same
|
||||
assert_equal "$new_content" "$content"
|
||||
|
||||
rm -f output1.json
|
||||
rm -f output2.json
|
||||
}
|
||||
@@ -1,244 +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 '.[].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 '.[].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 '.[].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 '.[].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 '.[].reason')
|
||||
|
||||
# assert_equal "$content" '"default_p1_element_02"'
|
||||
}
|
||||
|
||||
@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 '.[].reason')
|
||||
|
||||
assert_equal "$content" '"default_property_value_01"'
|
||||
}
|
||||
|
||||
@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'
|
||||
}
|
||||
|
||||
############### 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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"default_parameter_1 default_parameter_2 default_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"default_parameter_1 command_parameter_2 default_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 default_parameter_2 default_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# # store the reason field in `content`
|
||||
# content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
# assert_equal "$content" '"default_p1_element_02"'
|
||||
# rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "control to access specific property from map" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.query_params_map_with_default --export json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"default_property_value_01"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 default_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 default_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"default_parameter_1 default_parameter_2 default_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.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 json
|
||||
|
||||
# store the reason field in `content`
|
||||
content=$(cat control.*.json | jq '.controls[0].results[0].reason')
|
||||
|
||||
assert_equal "$content" '"command_parameter_1 command_parameter_2 command_parameter_3"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
|
||||
@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" ""
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "ensure mod name in introspection table is <mod_name> not mod.<mod_name>" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extract the first mod_name from the list
|
||||
mod_name=$(echo $output | jq '.[0].mod_name')
|
||||
|
||||
# check if mod_name starts with "mod."
|
||||
if [[ "$mod_name" == *"mod."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
}
|
||||
|
||||
@test "ensure query pseudo resources, i.e. sql files, have resource name <query_name> not <query.query_name>" {
|
||||
cd $WORKSPACE_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extract the first encountered sql file's file_name from the list
|
||||
sql_file_name=$(echo $output | jq '.[].file_name' | grep ".sql" | head -1)
|
||||
|
||||
#extract the resource_name of the above extracted file_name
|
||||
resource_name=$(echo $output | jq --arg FILENAME "$sql_file_name" '.[] | select(.file_name=="$FILENAME") | .resource_name')
|
||||
|
||||
# check if resource_name starts with "query."
|
||||
if [[ "$resource_name" == *"query."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
}
|
||||
|
||||
@test "ensure the reference_to and reference_from columns are populated correctly" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_reference" --output json
|
||||
|
||||
# extract the refs and the referenced_by
|
||||
refs=$(echo $output | jq '.[0].reference_to')
|
||||
referenced_by=$(echo $output | jq '.[0].reference_from')
|
||||
|
||||
assert_equal "$refs" '"var.sample_var_1"'
|
||||
assert_equal "$referenced_by" '"query.sample_query_1"'
|
||||
}
|
||||
|
||||
@test "ensure the reference_to column includes variable references" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_reference" --output json
|
||||
|
||||
# extract the refs
|
||||
refs=$(echo $output | jq '.[0].reference_to')
|
||||
echo $refs
|
||||
|
||||
# check if refs contains variables(start with "var.")
|
||||
if [[ "$refs" == *"var."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "1"
|
||||
}
|
||||
|
||||
@test "introspection tables should get populated in query batch mode" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extracting only description from the list, which is enough to prove that there is an output
|
||||
description=$(echo $output | jq '.[].description')
|
||||
assert_equal "$description" '"query 1 - 3 params all with defaults"'
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
# 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'
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
# tests for tablefunc module
|
||||
|
||||
@test "test crosstab function" {
|
||||
# create table and insert values
|
||||
steampipe query "CREATE TABLE ct(id SERIAL, rowid TEXT, attribute TEXT, value TEXT);"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att1','val1');"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att2','val2');"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att3','val3');"
|
||||
|
||||
# crosstab function
|
||||
run steampipe query "SELECT * FROM crosstab('select rowid, attribute, value from ct where attribute = ''att2'' or attribute = ''att3'' order by 1,2') AS ct(row_name text, category_1 text, category_2 text);"
|
||||
echo $output
|
||||
|
||||
# drop table
|
||||
steampipe query "DROP TABLE ct"
|
||||
|
||||
# match output with expected
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_crosstab_results.txt)"
|
||||
}
|
||||
|
||||
@test "test normal_rand function" {
|
||||
# normal_rand function
|
||||
steampipe query "SELECT * FROM normal_rand(10, 5, 3);"
|
||||
|
||||
# previous query should pass
|
||||
assert_success
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
# 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/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/nested_mod/folder1
|
||||
|
||||
run steampipe check all
|
||||
assert_equal "$output" "Error: this command requires a mod definition file - 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/nested_mod_no_mod_file/folder1/folder11
|
||||
|
||||
run steampipe check all
|
||||
assert_equal "$output" "Error: this command requires a mod definition file - could not find in the current directory tree"
|
||||
|
||||
run steampipe query control.check_1
|
||||
assert_success
|
||||
cd -
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "running steampipe query with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe query "select 1"
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe check with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe check all
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe dashboard with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe dashboard
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe query with steampipe CLI version requirement not met" {
|
||||
cd $FILE_PATH/test_data/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/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/bad_mod_with_sp_version_require_not_met
|
||||
|
||||
run steampipe 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/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/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/bad_mod_with_dep_mod_version_require_not_met
|
||||
|
||||
run steampipe 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 -
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "mod parsing" {
|
||||
# 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-ibm-insights
|
||||
steampipe mod install github.com/turbot/steampipe-mod-ibm-insights
|
||||
# go to the mod directory and run steampipe query to verify parsing
|
||||
cd .steampipe/mods/github.com/turbot/steampipe-mod-ibm-insights@*
|
||||
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 -
|
||||
}
|
||||
|
||||
function setup() {
|
||||
# install necessary plugins
|
||||
steampipe plugin install aws
|
||||
steampipe plugin install ibm
|
||||
steampipe plugin install oci
|
||||
steampipe plugin install azure
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
# remove the directory
|
||||
cd ..
|
||||
rm -rf $target_directory
|
||||
}
|
||||
@@ -1,113 +1,6 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "steampipe aggregator connection wildcard check" {
|
||||
run steampipe plugin install chaos
|
||||
run steampipe plugin install steampipe
|
||||
cp $SRC_DATA_DIR/aggregator.spc $STEAMPIPE_INSTALL_DIR/config/chaos.spc
|
||||
run steampipe query "select * from chaos_group.chaos_all_column_types"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe aggregator connection check total results" {
|
||||
run steampipe query "select * from chaos.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos` connection
|
||||
length_chaos=$(echo $output | jq length)
|
||||
|
||||
run steampipe query "select * from chaos2.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos2` connection
|
||||
length_chaos_2=$(echo $output | jq length)
|
||||
|
||||
run steampipe query "select * from chaos_group.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos_group` aggregated connection
|
||||
length_chaos_agg=$(echo $output | jq length)
|
||||
|
||||
# since the aggregator connection `chaos_group` contains two chaos connections, we expect
|
||||
# the number of results returned will be the summation of the two
|
||||
assert_equal "$length_chaos_agg" "$((length_chaos+length_chaos_2))"
|
||||
}
|
||||
|
||||
@test "steampipe aggregator connections should fail when querying a different plugin" {
|
||||
run steampipe query "select * from chaos_group.chaos_all_numeric_column order by id"
|
||||
|
||||
# this should pass since the aggregator contains only chaos connections
|
||||
assert_success
|
||||
|
||||
run steampipe query "select * from chaos_group.steampipe_registry_plugin order by id"
|
||||
|
||||
# this should fail since the aggregator contains only chaos connections, and we are
|
||||
# querying a steampipe table
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "steampipe json connection config" {
|
||||
cp $SRC_DATA_DIR/chaos2.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
run steampipe query "select time_col from chaos4.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe should return an error for duplicate connection name" {
|
||||
cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
# this should fail because of duplicate connection name
|
||||
run steampipe query "select time_col from chaos.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
assert_output --partial 'Error: duplicate connection name'
|
||||
}
|
||||
|
||||
@test "steampipe yaml connection config" {
|
||||
cp $SRC_DATA_DIR/chaos2.yml $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
|
||||
|
||||
run steampipe query "select time_col from chaos5.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(hcl)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(yml)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(json)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe check options config is being parsed and used(cache=true; hcl)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
@@ -399,56 +292,69 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
assert_equal "$flag" "0"
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(hcl)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
@test "steampipe cache functionality check ON" {
|
||||
run steampipe plugin install chaos
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
run steampipe check benchmark.check_cache_benchmark --export json --max-parallel 1
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
# store the unique number from 1st control in `content`
|
||||
content=$(cat benchmark.*.json | jq '.groups[].controls[0].results[0].resource')
|
||||
# store the unique number from 2nd control in `new_content`
|
||||
new_content=$(cat benchmark.*.json | jq '.groups[].controls[1].results[0].resource')
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# verify that `content` and `new_content` are the same
|
||||
assert_equal "$new_content" "$content"
|
||||
rm -f benchmark.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(yml)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
@test "steampipe cache functionality check OFF" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
# set the env variable to false
|
||||
export STEAMPIPE_CACHE=false
|
||||
run steampipe check benchmark.check_cache_benchmark --export json --max-parallel 1
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
# store the unique number from 1st control in `content`
|
||||
content=$(cat benchmark.*.json | jq '.groups[].controls[0].results[0].resource')
|
||||
# store the unique number from 2nd control in `new_content`
|
||||
new_content=$(cat benchmark.*.json | jq '.groups[].controls[1].results[0].resource')
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# verify that `content` and `new_content` are not the same
|
||||
if [[ "$content" == "$new_content" ]]; then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
rm -f benchmark.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(json)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
@test "steampipe cache functionality check ON(check content of results, not just the unique column)" {
|
||||
# start service to turn on caching
|
||||
steampipe service start
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
steampipe query "select unique_col, a, b from chaos_cache_check" --output json &> output1.json
|
||||
# store the result from 1st query in `content`
|
||||
content=$(cat output1.json)
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
steampipe query "select unique_col, a, b from chaos_cache_check" --output json &> output2.json
|
||||
# store the result from 2nd query in `new_content`
|
||||
new_content=$(cat output2.json)
|
||||
|
||||
}
|
||||
|
||||
@test "connection name escaping" {
|
||||
cp $SRC_DATA_DIR/chaos_conn_name_escaping.spc $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
|
||||
|
||||
# steampipe should accept default keyword in the connection configuration file, keywords should be escaped properly
|
||||
run steampipe query "select * from \"default\".chaos_limit limit 1"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
|
||||
|
||||
assert_success
|
||||
echo $content
|
||||
echo $new_content
|
||||
|
||||
# stop service
|
||||
steampipe service stop
|
||||
|
||||
# verify that `content` and `new_content` are the same
|
||||
assert_equal "$new_content" "$content"
|
||||
|
||||
rm -f output1.json
|
||||
rm -f output2.json
|
||||
}
|
||||
@@ -1,6 +1,71 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "select * from chaos.chaos_high_row_count order by column_0" {
|
||||
run steampipe query --output json "select * from chaos.chaos_high_row_count order by column_0 limit 10"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_1.json)"
|
||||
}
|
||||
|
||||
@test "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'" {
|
||||
run steampipe query --output json "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_2.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_high_column_count order by column_0" {
|
||||
run steampipe query --output json "select * from chaos.chaos_high_column_count order by column_0 limit 10"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_3.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_hydrate_columns_dependency where id='0'" {
|
||||
run steampipe query --output json "select * from chaos.chaos_hydrate_columns_dependency where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_5.json)"
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_list_error" {
|
||||
run steampipe query "select fatal_error from chaos.chaos_list_errors"
|
||||
assert_output --partial 'fatalError'
|
||||
}
|
||||
|
||||
@test "select panic from chaos.chaos_get_errors where id=0" {
|
||||
run steampipe query --output json "select panic from chaos.chaos_get_errors where id=0"
|
||||
assert_output --partial 'Panic'
|
||||
}
|
||||
|
||||
@test "select error from chaos_transform_errors" {
|
||||
run steampipe query "select error from chaos_transform_errors"
|
||||
assert_output --partial 'TRANSFORM ERROR'
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_hydrate_delay" {
|
||||
run steampipe query --output json "select delay from chaos.chaos_hydrate_errors order by id"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "select * from chaos.chaos_parallel_hydrate_columns where id='0'" {
|
||||
run steampipe query --output json "select * from chaos.chaos_parallel_hydrate_columns where id='0'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_11.json)"
|
||||
}
|
||||
|
||||
@test "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'" {
|
||||
run steampipe query --output json "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_12.json)"
|
||||
}
|
||||
|
||||
@test "select transform_method_column from chaos_transforms order by id" {
|
||||
run steampipe query --output json "select transform_method_column from chaos_transforms order by id"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_14.json)"
|
||||
}
|
||||
|
||||
@test "select parent_should_ignore_error from chaos.chaos_list_parent_child" {
|
||||
run steampipe query "select parent_should_ignore_error from chaos.chaos_list_parent_child"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "select from_qual_column from chaos_transforms where id=2" {
|
||||
run steampipe query --output json "select from_qual_column from chaos_transforms where id=2"
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_13.json)"
|
||||
}
|
||||
|
||||
@test "public schema insert select all types" {
|
||||
steampipe query "drop table if exists all_columns"
|
||||
steampipe query "create table all_columns (nullcolumn CHAR(2), booleancolumn boolean, textcolumn1 CHAR(20), textcolumn2 VARCHAR(20), textcolumn3 text, integercolumn1 smallint, integercolumn2 int, integercolumn3 SERIAL, integercolumn4 bigint, integercolumn5 bigserial, numericColumn numeric(6,4), realColumn real, floatcolumn float, date1 DATE, time1 TIME, timestamp1 TIMESTAMP, timestamp2 TIMESTAMPTZ, interval1 INTERVAL, array1 text[], jsondata jsonb, jsondata2 json, uuidcolumn UUID, ipAddress inet, macAddress macaddr, cidrRange cidr, xmlData xml, currency money)"
|
||||
@@ -129,4 +194,4 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
steampipe query "select 1 as a" --output json
|
||||
run steampipe query "select 1 as a" --output json
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_15.json)"
|
||||
}
|
||||
}
|
||||
@@ -163,3 +163,69 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
rm -f test.json
|
||||
cd -
|
||||
}
|
||||
|
||||
## 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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.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 json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_4 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_5 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path and search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_6 --output json --export json
|
||||
assert_equal "$(cat control.*.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f control.*.json
|
||||
}
|
||||
|
||||
## plugin crash
|
||||
|
||||
@test "check whether the plugin is crashing or not" {
|
||||
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'
|
||||
}
|
||||
@@ -38,9 +38,3 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
run steampipe service stop --force
|
||||
assert_success
|
||||
}
|
||||
|
||||
# this test is added to make sure the above don't time-out
|
||||
@test "check status" {
|
||||
run steampipe service status
|
||||
assert_success
|
||||
}
|
||||
@@ -1,8 +1,27 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "migrate legacy lock file" {
|
||||
cd tests/acceptance/test_data/dependent_mod_with_legacy_lock
|
||||
# run steampipe query twice - the bug we are testing for caused the workspace lock to be deleted after the first query
|
||||
steampipe query "select 1 as a" --output json
|
||||
run steampipe query "select 1 as a" --output json
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_15.json)"
|
||||
}
|
||||
|
||||
## public schema migration
|
||||
|
||||
@test "verify data is properly migrated when upgrading from v0.13.6" {
|
||||
skip
|
||||
# setup sql statements
|
||||
setup_sql[0]="create table sample(sample_col_1 char(10), sample_col_2 char(10))"
|
||||
setup_sql[1]="insert into sample(sample_col_1,sample_col_2) values ('foo','bar')"
|
||||
setup_sql[2]="insert into sample(sample_col_1,sample_col_2) values ('foo1','bar1')"
|
||||
setup_sql[3]="create function sample_func() returns integer as 'select 1 as result;' language sql;"
|
||||
|
||||
# verify sql statements
|
||||
verify_sql[0]="select * from sample"
|
||||
verify_sql[1]="select * from sample_func()"
|
||||
|
||||
# create a temp directory to install steampipe(0.13.6)
|
||||
tmpdir="$(mktemp -d)"
|
||||
mkdir -p "${tmpdir}"
|
||||
@@ -43,11 +62,12 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
# stop the service
|
||||
$tmpdir/steampipe --install-dir $tmpdir service stop
|
||||
|
||||
# Now run this version(0.14.*) - which should migrate the data
|
||||
# Now run this version - which should migrate the data
|
||||
steampipe --install-dir $tmpdir service start
|
||||
|
||||
# store the result of the verification statements(0.14.*)
|
||||
for ((i = 0; i < ${#verify_sql[@]}; i++)); do
|
||||
echo "VerifySQL: ${verify_sql[$i]}"
|
||||
steampipe --install-dir $tmpdir query "${verify_sql[$i]}" --output json > verify$i$i.json
|
||||
done
|
||||
|
||||
@@ -59,22 +79,6 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
assert_equal "$(cat verify$i.json)" "$(cat verify$i$i.json)"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# add the setup and verify sql statements here
|
||||
function setup() {
|
||||
# setup sql statements
|
||||
setup_sql[0]="create table sample(sample_col_1 char(10), sample_col_2 char(10))"
|
||||
setup_sql[1]="insert into sample(sample_col_1,sample_col_2) values ('foo','bar')"
|
||||
setup_sql[2]="insert into sample(sample_col_1,sample_col_2) values ('foo1','bar1')"
|
||||
setup_sql[3]="create function sample_func() returns integer as 'select 1 as result;' language sql;"
|
||||
|
||||
# verify sql statements
|
||||
verify_sql[0]="select * from sample"
|
||||
verify_sql[1]="select * from sample_func()"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
rm -rf $tmpdir
|
||||
rm -f verify*
|
||||
}
|
||||
583
tests/acceptance/test_files/mod.bats
Normal file
583
tests/acceptance/test_files/mod.bats
Normal file
@@ -0,0 +1,583 @@
|
||||
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 '.[].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 '.[].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 '.[].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 '.[].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 '.[].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 '.[].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" ""
|
||||
}
|
||||
|
||||
## introspection
|
||||
|
||||
@test "ensure mod name in introspection table is <mod_name> not mod.<mod_name>" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extract the first mod_name from the list
|
||||
mod_name=$(echo $output | jq '.[0].mod_name')
|
||||
|
||||
# check if mod_name starts with "mod."
|
||||
if [[ "$mod_name" == *"mod."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
}
|
||||
|
||||
@test "ensure query pseudo resources, i.e. sql files, have resource name <query_name> not <query.query_name>" {
|
||||
cd $WORKSPACE_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extract the first encountered sql file's file_name from the list
|
||||
sql_file_name=$(echo $output | jq '.[].file_name' | grep ".sql" | head -1)
|
||||
|
||||
#extract the resource_name of the above extracted file_name
|
||||
resource_name=$(echo $output | jq --arg FILENAME "$sql_file_name" '.[] | select(.file_name=="$FILENAME") | .resource_name')
|
||||
|
||||
# check if resource_name starts with "query."
|
||||
if [[ "$resource_name" == *"query."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "0"
|
||||
}
|
||||
|
||||
@test "ensure the reference_to and reference_from columns are populated correctly" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_reference" --output json
|
||||
|
||||
# extract the refs and the referenced_by
|
||||
refs=$(echo $output | jq '.[0].reference_to')
|
||||
referenced_by=$(echo $output | jq '.[0].reference_from')
|
||||
|
||||
assert_equal "$refs" '"var.sample_var_1"'
|
||||
assert_equal "$referenced_by" '"query.sample_query_1"'
|
||||
}
|
||||
|
||||
@test "ensure the reference_to column includes variable references" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_reference" --output json
|
||||
|
||||
# extract the refs
|
||||
refs=$(echo $output | jq '.[0].reference_to')
|
||||
echo $refs
|
||||
|
||||
# check if refs contains variables(start with "var.")
|
||||
if [[ "$refs" == *"var."* ]];
|
||||
then
|
||||
flag=1
|
||||
else
|
||||
flag=0
|
||||
fi
|
||||
assert_equal "$flag" "1"
|
||||
}
|
||||
|
||||
@test "introspection tables should get populated in query batch mode" {
|
||||
cd $SIMPLE_MOD_DIR
|
||||
run steampipe query "select * from steampipe_query" --output json
|
||||
|
||||
# extracting only description from the list, which is enough to prove that there is an output
|
||||
description=$(echo $output | jq '.[].description')
|
||||
assert_equal "$description" '"query 1 - 3 params all with defaults"'
|
||||
}
|
||||
|
||||
## 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/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/nested_mod/folder1
|
||||
|
||||
run steampipe check all
|
||||
assert_equal "$output" "Error: this command requires a mod definition file - 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/nested_mod_no_mod_file/folder1/folder11
|
||||
|
||||
run steampipe check all
|
||||
assert_equal "$output" "Error: this command requires a mod definition file - could not find in the current directory tree"
|
||||
|
||||
run steampipe query control.check_1
|
||||
assert_success
|
||||
cd -
|
||||
}
|
||||
|
||||
## require
|
||||
|
||||
@test "running steampipe query with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe query "select 1"
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe check with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe check all
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe dashboard with mod plugin requirement not met" {
|
||||
cd $FILE_PATH/test_data/bad_mod_with_plugin_require_not_met
|
||||
|
||||
run steampipe dashboard
|
||||
assert_output --partial 'Error: 1 mod plugin requirement not satisfied.'
|
||||
cd -
|
||||
}
|
||||
|
||||
@test "running steampipe query with steampipe CLI version requirement not met" {
|
||||
cd $FILE_PATH/test_data/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/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/bad_mod_with_sp_version_require_not_met
|
||||
|
||||
run steampipe 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/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/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/bad_mod_with_dep_mod_version_require_not_met
|
||||
|
||||
run steampipe 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 -
|
||||
}
|
||||
|
||||
## parsing
|
||||
|
||||
@test "mod parsing" {
|
||||
# install necessary plugins
|
||||
steampipe plugin install aws
|
||||
steampipe plugin install ibm
|
||||
steampipe plugin install oci
|
||||
steampipe plugin install azure
|
||||
|
||||
# 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-ibm-insights
|
||||
steampipe mod install github.com/turbot/steampipe-mod-ibm-insights
|
||||
# go to the mod directory and run steampipe query to verify parsing
|
||||
cd .steampipe/mods/github.com/turbot/steampipe-mod-ibm-insights@*
|
||||
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
|
||||
}
|
||||
|
||||
431
tests/acceptance/test_files/service_and_plugin.bats
Normal file
431
tests/acceptance/test_files/service_and_plugin.bats
Normal file
@@ -0,0 +1,431 @@
|
||||
load "$LIB_BATS_ASSERT/load.bash"
|
||||
load "$LIB_BATS_SUPPORT/load.bash"
|
||||
|
||||
@test "steampipe plugin help is displayed when no sub command given" {
|
||||
run steampipe plugin
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_plugin_help_output.txt)"
|
||||
}
|
||||
|
||||
@test "steampipe service help is displayed when no sub command given" {
|
||||
run steampipe service
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_service_help_output.txt)"
|
||||
}
|
||||
|
||||
@test "steampipe service start" {
|
||||
run steampipe service start
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe service restart" {
|
||||
run steampipe service restart
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe service stop" {
|
||||
run steampipe service stop
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "custom database name" {
|
||||
# Set the STEAMPIPE_INITDB_DATABASE_NAME env variable
|
||||
export STEAMPIPE_INITDB_DATABASE_NAME="custom_db_name"
|
||||
|
||||
target_install_directory=$(mktemp -d)
|
||||
|
||||
# Start the service
|
||||
run steampipe service start --install-dir $target_install_directory
|
||||
echo $output
|
||||
# Check if database name in the output is the same
|
||||
assert_output --partial 'custom_db_name'
|
||||
|
||||
# Extract password from the state file
|
||||
db_name=$(cat $target_install_directory/internal/steampipe.json | jq .database)
|
||||
echo $db_name
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$db_name" "\"custom_db_name\""
|
||||
|
||||
run steampipe service stop --install-dir $target_install_directory
|
||||
|
||||
rm -rf $target_install_directory
|
||||
}
|
||||
|
||||
@test "custom database name - should not start with uppercase characters" {
|
||||
# Set the STEAMPIPE_INITDB_DATABASE_NAME env variable
|
||||
export STEAMPIPE_INITDB_DATABASE_NAME="Custom_db_name"
|
||||
|
||||
target_install_directory=$(mktemp -d)
|
||||
|
||||
# Start the service
|
||||
run steampipe service start --install-dir $target_install_directory
|
||||
|
||||
assert_failure
|
||||
run steampipe service stop --force
|
||||
rm -rf $target_install_directory
|
||||
}
|
||||
|
||||
@test "steampipe service stop should not trigger daily checks and tasks" {
|
||||
run steampipe service start
|
||||
|
||||
# set the `lastChecked` date in the update-check.json file to a past date
|
||||
echo $(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json | jq '.last_checked="2021-04-10T17:53:40+05:30"') > $STEAMPIPE_INSTALL_DIR/internal/update_check.json
|
||||
|
||||
# get the content of the current update-check.json file
|
||||
checkFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json)
|
||||
|
||||
run steampipe service stop
|
||||
|
||||
# get the content of the new update-check.json file
|
||||
newCheckFileContent=$(cat $STEAMPIPE_INSTALL_DIR/internal/update_check.json)
|
||||
|
||||
assert_equal "$(echo $newCheckFileContent | jq '.last_checked')" '"2021-04-10T17:53:40+05:30"'
|
||||
}
|
||||
|
||||
@test "start service, install plugin and query" {
|
||||
# start service
|
||||
steampipe service start
|
||||
|
||||
# install plugin
|
||||
steampipe plugin install chaos
|
||||
|
||||
# query the plugin
|
||||
run steampipe query "select time_col from chaos_cache_check limit 1"
|
||||
# check if the query passes
|
||||
assert_success
|
||||
|
||||
# stop service
|
||||
steampipe service stop
|
||||
|
||||
# check service status
|
||||
run steampipe service status
|
||||
|
||||
assert_output "$output" "Service is not running"
|
||||
}
|
||||
|
||||
@test "start service and verify that passwords stored in .passwd and steampipe.json are same" {
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
pass_file_pass=\"${pass_file_pass}\"
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "$pass_file_pass"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and verify that the password used in flag and stored in steampipe.json are same" {
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"abcd-efgh-ijkl\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with password in env variable and verify that the password used in env and stored in steampipe.json are same" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"dcba-hgfe-lkji\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and env variable set, verify that the password used in flag gets higher precedence and is stored in steampipe.json" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "\"abcd-efgh-ijkl\""
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service after removing .passwd file, verify new .passwd file gets created and also passwords stored in .passwd and steampipe.json are same" {
|
||||
# Remove the .passwd file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/internal/.passwd
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password from the state file
|
||||
state_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/steampipe.json | jq .password)
|
||||
echo $state_file_pass
|
||||
|
||||
# Extract password stored in new .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
pass_file_pass=\"${pass_file_pass}\"
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should be equal
|
||||
assert_equal "$state_file_pass" "$pass_file_pass"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with --database-password flag and verify that the password used in flag is not stored in .passwd file" {
|
||||
# Start the service with --database-password flag
|
||||
run steampipe service start --database-password "abcd-efgh-ijkl"
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should not be equal
|
||||
if [[ "$pass_file_pass" != "abcd-efgh-ijkl" ]]
|
||||
then
|
||||
temp=1
|
||||
fi
|
||||
|
||||
assert_equal "$temp" "1"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "start service with password in env variable and verify that the password used in env is not stored in .passwd file" {
|
||||
# Set the STEAMPIPE_DATABASE_PASSWORD env variable
|
||||
export STEAMPIPE_DATABASE_PASSWORD="dcba-hgfe-lkji"
|
||||
|
||||
# Start the service
|
||||
run steampipe service start
|
||||
|
||||
# Extract password stored in .passwd file
|
||||
pass_file_pass=$(cat $STEAMPIPE_INSTALL_DIR/internal/.passwd)
|
||||
echo "$pass_file_pass"
|
||||
|
||||
# Both should not be equal
|
||||
if [[ "$pass_file_pass" != "dcba-hgfe-lkji" ]]
|
||||
then
|
||||
temp=1
|
||||
fi
|
||||
|
||||
assert_equal "$temp" "1"
|
||||
|
||||
run steampipe service stop
|
||||
}
|
||||
|
||||
@test "steampipe plugin list" {
|
||||
run steampipe plugin list
|
||||
assert_success
|
||||
}
|
||||
|
||||
## connection config
|
||||
|
||||
@test "steampipe aggregator connection wildcard check" {
|
||||
run steampipe plugin install chaos
|
||||
run steampipe plugin install steampipe
|
||||
cp $SRC_DATA_DIR/aggregator.spc $STEAMPIPE_INSTALL_DIR/config/chaos.spc
|
||||
run steampipe query "select * from chaos_group.chaos_all_column_types"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe aggregator connection check total results" {
|
||||
run steampipe query "select * from chaos.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos` connection
|
||||
length_chaos=$(echo $output | jq length)
|
||||
|
||||
run steampipe query "select * from chaos2.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos2` connection
|
||||
length_chaos_2=$(echo $output | jq length)
|
||||
|
||||
run steampipe query "select * from chaos_group.chaos_all_numeric_column" --output json
|
||||
|
||||
# store the length of the result when queried using `chaos_group` aggregated connection
|
||||
length_chaos_agg=$(echo $output | jq length)
|
||||
|
||||
# since the aggregator connection `chaos_group` contains two chaos connections, we expect
|
||||
# the number of results returned will be the summation of the two
|
||||
assert_equal "$length_chaos_agg" "$((length_chaos+length_chaos_2))"
|
||||
}
|
||||
|
||||
@test "steampipe aggregator connections should fail when querying a different plugin" {
|
||||
run steampipe query "select * from chaos_group.chaos_all_numeric_column order by id"
|
||||
|
||||
# this should pass since the aggregator contains only chaos connections
|
||||
assert_success
|
||||
|
||||
run steampipe query "select * from chaos_group.steampipe_registry_plugin order by id"
|
||||
|
||||
# this should fail since the aggregator contains only chaos connections, and we are
|
||||
# querying a steampipe table
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "steampipe json connection config" {
|
||||
cp $SRC_DATA_DIR/chaos2.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
run steampipe query "select time_col from chaos4.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe should return an error for duplicate connection name" {
|
||||
cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
# this should fail because of duplicate connection name
|
||||
run steampipe query "select time_col from chaos.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
|
||||
|
||||
assert_output --partial 'Error: duplicate connection name'
|
||||
}
|
||||
|
||||
@test "steampipe yaml connection config" {
|
||||
cp $SRC_DATA_DIR/chaos2.yml $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
|
||||
|
||||
run steampipe query "select time_col from chaos5.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(hcl)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(yml)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe test connection config with options(json)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
|
||||
run steampipe query "select time_col from chaos6.chaos_cache_check"
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(hcl)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(yml)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
|
||||
}
|
||||
|
||||
@test "steampipe check regions in connection config is being parsed and used(json)" {
|
||||
cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
|
||||
# check regions in connection config is being parsed and used
|
||||
run steampipe query "select * from chaos6.chaos_regions order by id" --output json
|
||||
result=$(echo $output | tr -d '[:space:]')
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
|
||||
# check output
|
||||
assert_equal "$result" '[{"_ctx":{"connection_name":"chaos6"},"id":0,"region_name":"us-east-1"},{"_ctx":{"connection_name":"chaos6"},"id":3,"region_name":"us-west-2"}]'
|
||||
|
||||
}
|
||||
|
||||
@test "connection name escaping" {
|
||||
cp $SRC_DATA_DIR/chaos_conn_name_escaping.spc $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
|
||||
|
||||
# steampipe should accept default keyword in the connection configuration file, keywords should be escaped properly
|
||||
run steampipe query "select * from \"default\".chaos_limit limit 1"
|
||||
|
||||
# remove the config file
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
|
||||
|
||||
assert_success
|
||||
}
|
||||
|
||||
## service extensions
|
||||
|
||||
# tests for tablefunc module
|
||||
|
||||
@test "test crosstab function" {
|
||||
# create table and insert values
|
||||
steampipe query "CREATE TABLE ct(id SERIAL, rowid TEXT, attribute TEXT, value TEXT);"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att1','val1');"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att2','val2');"
|
||||
steampipe query "INSERT INTO ct(rowid, attribute, value) VALUES('test1','att3','val3');"
|
||||
|
||||
# crosstab function
|
||||
run steampipe query "SELECT * FROM crosstab('select rowid, attribute, value from ct where attribute = ''att2'' or attribute = ''att3'' order by 1,2') AS ct(row_name text, category_1 text, category_2 text);"
|
||||
echo $output
|
||||
|
||||
# drop table
|
||||
steampipe query "DROP TABLE ct"
|
||||
|
||||
# match output with expected
|
||||
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_crosstab_results.txt)"
|
||||
}
|
||||
|
||||
@test "test normal_rand function" {
|
||||
# normal_rand function
|
||||
run steampipe query "SELECT * FROM normal_rand(10, 5, 3);"
|
||||
|
||||
# previous query should pass
|
||||
assert_success
|
||||
}
|
||||
Reference in New Issue
Block a user