mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-24 02:00:29 -05:00
Update check to te-add implicit conversion of named query name to named query, so setting the SQL field to a query name would work. Update reflection tables to fix JSONB arrays Workspace loads and watches files recursively if a mod.sp file exists in the workspace folder Update reflection tables - 'labels' and 'links' are now JSONB columns rename control property Query to SQL and do NOT try to resolve this as a named query Add documentation property to control_group
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package parse
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/turbot/go-kit/helpers"
|
|
)
|
|
|
|
type dependencyTreeTest struct {
|
|
input [][]string
|
|
expected []string
|
|
}
|
|
|
|
var testCasesDependencyTree = map[string]dependencyTreeTest{
|
|
"no overlap": {
|
|
input: [][]string{{"a", "b", "c"}, {"d", "e", "f"}},
|
|
expected: []string{"a", "b", "c", "d", "e", "f"},
|
|
},
|
|
"overlap": {
|
|
input: [][]string{{"a", "b", "c"}, {"b", "c"}},
|
|
expected: []string{"a", "b", "c"},
|
|
},
|
|
"multiple overlaps": {
|
|
input: [][]string{{"a", "b", "c"}, {"b", "c"}, {"d", "e", "f", "g", "h", "i"}, {"g", "h", "i"}, {"h", "i"}},
|
|
expected: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i"},
|
|
},
|
|
}
|
|
|
|
func TestDependencyTree(t *testing.T) {
|
|
|
|
for name, test := range testCasesDependencyTree {
|
|
|
|
res := combineDependencyOrders(test.input)
|
|
if !reflect.DeepEqual(res, test.expected) {
|
|
t.Errorf("Test %s FAILED. Expected %v, got %v", name, test.expected, res)
|
|
}
|
|
}
|
|
}
|
|
|
|
func combineDependencyOrders(deps [][]string) []string {
|
|
|
|
// we assume every dep is unique
|
|
// for each dep, if first element exists in any other dep, then it cannot be the longest
|
|
// first dedupe
|
|
var longestDeps []string
|
|
for i, d1 := range deps {
|
|
longest := true
|
|
for j, d2 := range deps {
|
|
if i == j {
|
|
continue
|
|
}
|
|
if helpers.StringSliceContains(d2, d1[0]) {
|
|
longest = false
|
|
continue
|
|
}
|
|
}
|
|
if longest {
|
|
longestDeps = append(longestDeps, d1...)
|
|
}
|
|
}
|
|
|
|
return longestDeps
|
|
}
|