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