Files
steampipe/steampipeconfig/parse/dependency_test.go
kai 7e3ae0a386 Add parsing support for variable references, functions and locals. Closes #405
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
2021-05-20 16:11:13 +01:00

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
}