Skip to content

Commit

Permalink
Add test for plugin list with disabled connection. Closes #3561
Browse files Browse the repository at this point in the history
  • Loading branch information
binaek authored Jun 16, 2023
1 parent c950df2 commit 1aec14b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,10 @@ func getPluginList(ctx context.Context) (pluginList []plugin.PluginListItem, fai
return nil, nil, nil, res
}

// TODO do we really need to look at installed plugins - can't we just use the plugin connection map
// get a list of the installed plugins by inspecting the install location
// pass pluginConnectionMap so we can populate the connections for each plugin
// we need to look at installed plugins - we can't just use the plugin connection map
// because the plugin connection map only contains entries for plugins which have connections
pluginList, err := plugin.List(pluginConnectionMap)
if err != nil {
res.Error = err
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func Execute() int {

// create the root context - add a status renderer
func createRootContext() context.Context {
var statusRenderer statushooks.StatusHooks = statushooks.NullHooks
statusRenderer := statushooks.NullHooks
// if the client is a TTY, inject a status spinner
if isatty.IsTerminal(os.Stdout.Fd()) {
statusRenderer = statushooks.NewStatusSpinnerHook()
Expand Down
2 changes: 1 addition & 1 deletion pkg/statushooks/null_hooks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package statushooks

var NullHooks = &NullStatusHook{}
var NullHooks StatusHooks = &NullStatusHook{}

type NullStatusHook struct{}

Expand Down
1 change: 1 addition & 0 deletions pkg/steampipeconfig/connection_state_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (m ConnectionStateMap) Loaded(connections ...string) bool {
// ignore if we have no state loaded for this conneciton name
continue
}
log.Println("[TRACE] Checking state for", connectionName)
if !connectionState.Loaded() {
return false
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/steampipeconfig/modconfig/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/steampipeconfig/options"
"github.com/turbot/steampipe/pkg/utils"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewConnection(block *hcl.Block) *Connection {
}

func (c *Connection) ImportDisabled() bool {
return c.ImportSchema == "disabled"
return c.ImportSchema == constants.ConnectionStateDisabled
}

func (c *Connection) Equals(other *Connection) bool {
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export BLANK_DIMENSION_VALUE_TEST_MOD=$MY_PATH/test_data/mod_with_blank_dimensio
export STEAMPIPE_CONNECTION_WATCHER=false
export STEAMPIPE_INTROSPECTION=info
export DEFAULT_WORKSPACE_PROFILE_LOCATION=$MY_PATH/test_data/source_files/workspace_profile_default
export STEAMPIPE_SYNC_REFRESH=true
# from GH action env variables
export SPIPETOOLS_PG_CONN_STRING=$SPIPETOOLS_PG_CONN_STRING
export SPIPETOOLS_TOKEN=$SPIPETOOLS_TOKEN
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
connection "chaos01" {
plugin = "chaos"
}

connection "chaos02" {
plugin = "chaos"
import_schema = "disabled"
}
4 changes: 4 additions & 0 deletions tests/acceptance/test_files/dynamic_aggregators.bats
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
rm -f $STEAMPIPE_INSTALL_DIR/config/dynamic_aggregator_col_type_mismatch_4.spc
assert_equal "$output" "$(cat $TEST_DATA_DIR/dynamic_aggregators_col_type_mismatch_4.json)"
}

function setup_file() {
export STEAMPIPE_SYNC_REFRESH=true
}
6 changes: 5 additions & 1 deletion tests/acceptance/test_files/dynamic_schema.bats
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ function teardown() {
# remove the files created as part of these tests
rm -f $STEAMPIPE_INSTALL_DIR/config/csv*.spc
rm -f output.*
}
}

function setup_file() {
export STEAMPIPE_SYNC_REFRESH=true
}
17 changes: 16 additions & 1 deletion tests/acceptance/test_files/service_and_plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ load "$LIB_BATS_SUPPORT/load.bash"
assert_success
}

@test "steampipe plugin list works with disabled connections" {
rm -f $STEAMPIPE_INSTALL_DIR/config/*
cp $SRC_DATA_DIR/chaos_conn_import_disabled.spc $STEAMPIPE_INSTALL_DIR/config/chaos_conn_import_disabled.spc
run steampipe plugin list 2>&3 1>&3
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_conn_import_disabled.spc
assert_success
}

## connection config

@test "steampipe aggregator connection wildcard check" {
Expand Down Expand Up @@ -322,12 +330,14 @@ load "$LIB_BATS_SUPPORT/load.bash"

@test "steampipe should return an error for duplicate connection name" {
cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json

cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos3.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
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos3.json

assert_output --partial 'duplicate connection name'
}
Expand Down Expand Up @@ -463,3 +473,8 @@ load "$LIB_BATS_SUPPORT/load.bash"
run steampipe plugin uninstall steampipe
rm -f $STEAMPIPE_INSTALL_DIR/config/steampipe.spc
}

function setup_file() {
export BATS_TEST_TIMEOUT=60
echo "# setup_file()">&3
}

0 comments on commit 1aec14b

Please sign in to comment.