Fix various order-dependent tests
This commit is contained in:
parent
4b74ddc9d1
commit
2aed2fd96f
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -95,10 +96,25 @@ func TestLoad_variables(t *testing.T) {
|
||||||
// string value for comparison in tests.
|
// string value for comparison in tests.
|
||||||
func providerConfigsStr(pcs map[string]*ProviderConfig) string {
|
func providerConfigsStr(pcs map[string]*ProviderConfig) string {
|
||||||
result := ""
|
result := ""
|
||||||
for n, pc := range pcs {
|
|
||||||
|
ns := make([]string, 0, len(pcs))
|
||||||
|
for n, _ := range pcs {
|
||||||
|
ns = append(ns, n)
|
||||||
|
}
|
||||||
|
sort.Strings(ns)
|
||||||
|
|
||||||
|
for _, n := range ns {
|
||||||
|
pc := pcs[n]
|
||||||
|
|
||||||
result += fmt.Sprintf("%s\n", n)
|
result += fmt.Sprintf("%s\n", n)
|
||||||
|
|
||||||
|
keys := make([]string, 0, len(pc.RawConfig.Raw))
|
||||||
for k, _ := range pc.RawConfig.Raw {
|
for k, _ := range pc.RawConfig.Raw {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, k := range keys {
|
||||||
result += fmt.Sprintf(" %s\n", k)
|
result += fmt.Sprintf(" %s\n", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +149,13 @@ func resourcesStr(rs []*Resource) string {
|
||||||
r.Type,
|
r.Type,
|
||||||
r.Name)
|
r.Name)
|
||||||
|
|
||||||
|
ks := make([]string, 0, len(r.RawConfig.Raw))
|
||||||
for k, _ := range r.RawConfig.Raw {
|
for k, _ := range r.RawConfig.Raw {
|
||||||
|
ks = append(ks, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ks)
|
||||||
|
|
||||||
|
for _, k := range ks {
|
||||||
result += fmt.Sprintf(" %s\n", k)
|
result += fmt.Sprintf(" %s\n", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +184,15 @@ func resourcesStr(rs []*Resource) string {
|
||||||
// string value for comparison in tests.
|
// string value for comparison in tests.
|
||||||
func variablesStr(vs map[string]*Variable) string {
|
func variablesStr(vs map[string]*Variable) string {
|
||||||
result := ""
|
result := ""
|
||||||
for k, v := range vs {
|
ks := make([]string, 0, len(vs))
|
||||||
|
for k, _ := range vs {
|
||||||
|
ks = append(ks, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ks)
|
||||||
|
|
||||||
|
for _, k := range ks {
|
||||||
|
v := vs[k]
|
||||||
|
|
||||||
if v.Default == "" {
|
if v.Default == "" {
|
||||||
v.Default = "<>"
|
v.Default = "<>"
|
||||||
}
|
}
|
||||||
|
@ -226,13 +256,13 @@ foo
|
||||||
`
|
`
|
||||||
|
|
||||||
const variablesVariablesStr = `
|
const variablesVariablesStr = `
|
||||||
foo
|
|
||||||
<>
|
|
||||||
<>
|
|
||||||
bar
|
bar
|
||||||
<>
|
<>
|
||||||
<>
|
<>
|
||||||
baz
|
baz
|
||||||
foo
|
foo
|
||||||
<>
|
<>
|
||||||
|
foo
|
||||||
|
<>
|
||||||
|
<>
|
||||||
`
|
`
|
||||||
|
|
|
@ -3,6 +3,7 @@ package depgraph
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -152,10 +153,16 @@ d -> b`)
|
||||||
}
|
}
|
||||||
|
|
||||||
cycle := vErr.Cycles[0]
|
cycle := vErr.Cycles[0]
|
||||||
if cycle[0].Name != "d" {
|
cycleNodes := make([]string, len(cycle))
|
||||||
|
for i, c := range cycle {
|
||||||
|
cycleNodes[i] = c.Name
|
||||||
|
}
|
||||||
|
sort.Strings(cycleNodes)
|
||||||
|
|
||||||
|
if cycleNodes[0] != "b" {
|
||||||
t.Fatalf("bad: %v", cycle)
|
t.Fatalf("bad: %v", cycle)
|
||||||
}
|
}
|
||||||
if cycle[1].Name != "b" {
|
if cycleNodes[1] != "d" {
|
||||||
t.Fatalf("bad: %v", cycle)
|
t.Fatalf("bad: %v", cycle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package digraph
|
package digraph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,13 +65,14 @@ g -> a
|
||||||
t.Fatalf("bad: %v", sccs)
|
t.Fatalf("bad: %v", sccs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cycle[0].(*BasicNode).Name != "g" {
|
cycleNodes := make([]string, len(cycle))
|
||||||
t.Fatalf("bad: %v", cycle)
|
for i, c := range cycle {
|
||||||
|
cycleNodes[i] = c.(*BasicNode).Name
|
||||||
}
|
}
|
||||||
if cycle[1].(*BasicNode).Name != "c" {
|
sort.Strings(cycleNodes)
|
||||||
t.Fatalf("bad: %v", cycle)
|
|
||||||
}
|
expected := []string{"a", "c", "g"}
|
||||||
if cycle[2].(*BasicNode).Name != "a" {
|
if !reflect.DeepEqual(cycleNodes, expected) {
|
||||||
t.Fatalf("bad: %v", cycle)
|
t.Fatalf("bad: %#v", cycleNodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,14 @@ func (s *State) String() string {
|
||||||
buf.WriteString(fmt.Sprintf("%s:\n", k))
|
buf.WriteString(fmt.Sprintf("%s:\n", k))
|
||||||
buf.WriteString(fmt.Sprintf(" ID = %s\n", id))
|
buf.WriteString(fmt.Sprintf(" ID = %s\n", id))
|
||||||
|
|
||||||
for ak, av := range rs.Attributes {
|
attrKeys := make([]string, 0, len(rs.Attributes))
|
||||||
|
for ak, _ := range rs.Attributes {
|
||||||
|
attrKeys = append(attrKeys, ak)
|
||||||
|
}
|
||||||
|
sort.Strings(attrKeys)
|
||||||
|
|
||||||
|
for _, ak := range attrKeys {
|
||||||
|
av := rs.Attributes[ak]
|
||||||
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
|
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -675,24 +675,24 @@ func (h *HookRecordApplyOrder) PreApply(
|
||||||
const testTerraformApplyStr = `
|
const testTerraformApplyStr = `
|
||||||
aws_instance.bar:
|
aws_instance.bar:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
foo = bar
|
foo = bar
|
||||||
|
type = aws_instance
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
num = 2
|
num = 2
|
||||||
|
type = aws_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
const testTerraformApplyComputeStr = `
|
const testTerraformApplyComputeStr = `
|
||||||
aws_instance.bar:
|
aws_instance.bar:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
foo = computed_dynamical
|
foo = computed_dynamical
|
||||||
|
type = aws_instance
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
num = 2
|
|
||||||
dynamical = computed_dynamical
|
dynamical = computed_dynamical
|
||||||
|
num = 2
|
||||||
|
type = aws_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
const testTerraformApplyDestroyStr = `
|
const testTerraformApplyDestroyStr = `
|
||||||
|
@ -705,19 +705,19 @@ aws_instance.foo:
|
||||||
const testTerraformApplyUnknownAttrStr = `
|
const testTerraformApplyUnknownAttrStr = `
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
num = 2
|
num = 2
|
||||||
|
type = aws_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
const testTerraformApplyVarsStr = `
|
const testTerraformApplyVarsStr = `
|
||||||
aws_instance.bar:
|
aws_instance.bar:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
foo = bar
|
foo = bar
|
||||||
|
type = aws_instance
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
type = aws_instance
|
|
||||||
num = 2
|
num = 2
|
||||||
|
type = aws_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
const testTerraformPlanStr = `
|
const testTerraformPlanStr = `
|
||||||
|
|
Loading…
Reference in New Issue