mirror of
https://github.com/turbot/steampipe.git
synced 2026-05-05 00:00:22 -04:00
Fix for plugin list failing with 'invalid memory address'. Closes #984
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
"github.com/turbot/steampipe/constants"
|
||||
"github.com/turbot/steampipe/steampipeconfig/modconfig"
|
||||
"github.com/turbot/steampipe/utils"
|
||||
)
|
||||
|
||||
@@ -33,16 +34,16 @@ var testCasesGetConnectionsToUpdate = map[string]getConnectionsToUpdateTest{
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -58,26 +59,26 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -93,26 +94,26 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -127,26 +128,26 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -161,26 +162,26 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -192,22 +193,22 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
}, Delete: ConnectionDataMap{}, RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -224,39 +225,39 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
Delete: ConnectionDataMap{},
|
||||
RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -272,38 +273,38 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}, Delete: ConnectionDataMap{},
|
||||
RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -318,39 +319,39 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{Update: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
Delete: ConnectionDataMap{},
|
||||
RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -365,40 +366,40 @@ connection "b" {
|
||||
`},
|
||||
current: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: "xxxxxx",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
},
|
||||
expected: &ConnectionUpdates{
|
||||
Update: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
},
|
||||
Delete: ConnectionDataMap{},
|
||||
RequiredConnections: ConnectionDataMap{
|
||||
"a": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
ConnectionName: "a",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-1@latest",
|
||||
CheckSum: connectionTest1Checksum,
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
},
|
||||
"b": {
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
ConnectionName: "b",
|
||||
Plugin: "hub.steampipe.io/plugins/turbot/connection-test-2@latest",
|
||||
CheckSum: connectionTest2Checksum,
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -450,6 +451,42 @@ func TestGetConnectionsToUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type connectionDataEqual struct {
|
||||
data1 *ConnectionData
|
||||
data2 *ConnectionData
|
||||
expectation bool
|
||||
}
|
||||
|
||||
var data1 ConnectionData = ConnectionData{
|
||||
Plugin: "plugin",
|
||||
CheckSum: "checksum",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
}
|
||||
var data1_duplicate ConnectionData = ConnectionData{
|
||||
Plugin: "plugin",
|
||||
CheckSum: "checksum",
|
||||
Connection: &modconfig.Connection{Name: "a"},
|
||||
}
|
||||
var data2 ConnectionData = ConnectionData{
|
||||
Plugin: "plugin2",
|
||||
CheckSum: "checksum2",
|
||||
Connection: &modconfig.Connection{Name: "b"},
|
||||
}
|
||||
|
||||
var connectionDataEqualCases map[string]connectionDataEqual = map[string]connectionDataEqual{
|
||||
"expected_equal": {data1: &data1, data2: &data1_duplicate, expectation: true},
|
||||
"not_expected_equal": {data1: &data1, data2: &data2, expectation: false},
|
||||
}
|
||||
|
||||
func TestConnectionsUpdateEqual(t *testing.T) {
|
||||
for caseName, caseData := range connectionDataEqualCases {
|
||||
isEqual := caseData.data1.Equals(caseData.data2)
|
||||
if caseData.expectation != isEqual {
|
||||
t.Errorf(`Test: '%s' FAILED: expected: %v, actual: %v`, caseName, caseData.expectation, isEqual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setup(test getConnectionsToUpdateTest) {
|
||||
|
||||
os.RemoveAll(constants.PluginDir())
|
||||
|
||||
@@ -3,12 +3,9 @@ package steampipeconfig
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/turbot/go-kit/helpers"
|
||||
"github.com/turbot/steampipe/steampipeconfig/modconfig"
|
||||
"github.com/turbot/steampipe/steampipeconfig/options"
|
||||
"github.com/turbot/steampipe/utils"
|
||||
)
|
||||
|
||||
@@ -32,31 +29,25 @@ func newConnectionUpdates() *ConnectionUpdates {
|
||||
// ConnectionData is a struct containing all details for a connection - the plugin name and checksum, the connection config and options
|
||||
type ConnectionData struct {
|
||||
// the fully qualified name of the plugin
|
||||
Plugin string `yaml:"plugin"`
|
||||
Plugin string
|
||||
// the checksum of the plugin file
|
||||
CheckSum string `yaml:"checkSum"`
|
||||
CheckSum string
|
||||
// the underlying connection object
|
||||
Connection *modconfig.Connection `json:"-"`
|
||||
// connection name
|
||||
ConnectionName string
|
||||
// connection data (unparsed)
|
||||
ConnectionConfig string
|
||||
// steampipe connection options
|
||||
ConnectionOptions *options.Connection
|
||||
DeclRange hcl.Range
|
||||
Connection *modconfig.Connection
|
||||
}
|
||||
|
||||
func (p *ConnectionData) Equals(other *ConnectionData) bool {
|
||||
connectionOptionsEqual := (p.ConnectionOptions == nil) == (other.ConnectionOptions == nil)
|
||||
if p.ConnectionOptions != nil {
|
||||
connectionOptionsEqual = p.ConnectionOptions.Equals(other.ConnectionOptions)
|
||||
if p.Connection == nil || other.Connection == nil {
|
||||
// if any one them has a `nil` Connection, then
|
||||
// this is data from an old connection state file.
|
||||
// return false, so that connections get refreshed
|
||||
// and this file gets written in the new format in the process
|
||||
return false
|
||||
}
|
||||
|
||||
return p.Plugin == other.Plugin &&
|
||||
p.CheckSum == other.CheckSum &&
|
||||
p.ConnectionName == other.ConnectionName &&
|
||||
connectionOptionsEqual &&
|
||||
reflect.DeepEqual(p.ConnectionConfig, other.ConnectionConfig)
|
||||
p.Connection.Equals(other.Connection)
|
||||
}
|
||||
|
||||
type ConnectionDataMap map[string]*ConnectionData
|
||||
@@ -153,12 +144,9 @@ func getRequiredConnections(connectionConfig map[string]*modconfig.Connection) (
|
||||
}
|
||||
|
||||
requiredConnections[name] = &ConnectionData{
|
||||
Plugin: remoteSchema,
|
||||
CheckSum: checksum,
|
||||
Connection: connection,
|
||||
ConnectionConfig: connection.Config,
|
||||
ConnectionName: connection.Name,
|
||||
DeclRange: connection.DeclRange,
|
||||
Plugin: remoteSchema,
|
||||
CheckSum: checksum,
|
||||
Connection: connection,
|
||||
}
|
||||
}
|
||||
utils.LogTime("steampipeconfig.getRequiredConnections config-iteration end")
|
||||
|
||||
@@ -50,6 +50,17 @@ func NewConnection(block *hcl.Block) *Connection {
|
||||
}
|
||||
}
|
||||
|
||||
// Equals
|
||||
func (c *Connection) Equals(other *Connection) bool {
|
||||
connectionOptionsEqual := (c.Options == nil) == (other.Options == nil)
|
||||
if c.Options != nil {
|
||||
connectionOptionsEqual = c.Options.Equals(other.Options)
|
||||
}
|
||||
return c.Name == other.Name &&
|
||||
connectionOptionsEqual &&
|
||||
reflect.DeepEqual(c.Config, other.Config)
|
||||
}
|
||||
|
||||
// SetOptions sets the options on the connection
|
||||
// verify the options object is a valid options type (only options.Connection currently supported)
|
||||
func (c *Connection) SetOptions(opts options.Options, block *hcl.Block) hcl.Diagnostics {
|
||||
|
||||
38
steampipeconfig/modconfig/connection_test.go
Normal file
38
steampipeconfig/modconfig/connection_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package modconfig
|
||||
|
||||
import "testing"
|
||||
|
||||
type connectionEquality struct {
|
||||
connection1 *Connection
|
||||
connection2 *Connection
|
||||
expectation bool
|
||||
}
|
||||
|
||||
var conn1 *Connection = &Connection{
|
||||
Name: "connection",
|
||||
Config: "connection_config",
|
||||
}
|
||||
|
||||
var conn1_duplicate *Connection = &Connection{
|
||||
Name: "connection",
|
||||
Config: "connection_config",
|
||||
}
|
||||
|
||||
var other_conn *Connection = &Connection{
|
||||
Name: "connection2",
|
||||
Config: "connection_config2",
|
||||
}
|
||||
|
||||
var equalsCases = map[string]connectionEquality{
|
||||
"expected_equal": {connection1: conn1, connection2: conn1_duplicate, expectation: true},
|
||||
"not_expected_equal": {connection1: conn1, connection2: other_conn, expectation: false},
|
||||
}
|
||||
|
||||
func TestConnectionEquals(t *testing.T) {
|
||||
for caseName, caseData := range equalsCases {
|
||||
isEqual := caseData.connection1.Equals(caseData.connection2)
|
||||
if caseData.expectation != isEqual {
|
||||
t.Errorf(`Test: '%s' FAILED: expected: %v, actual: %v`, caseName, caseData.expectation, isEqual)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user