Relax test to focus on the behavior we care about (encoded == encoded)
The specific output order is meaningless, but it should always be the same after two Encode() calls with identical (ignoring in-memory order) dependency sets.
This commit is contained in:
parent
df36a03be1
commit
05d0febf7f
|
@ -12,26 +12,39 @@ func TestResourceInstanceObject_encode(t *testing.T) {
|
||||||
value := cty.ObjectVal(map[string]cty.Value{
|
value := cty.ObjectVal(map[string]cty.Value{
|
||||||
"foo": cty.True,
|
"foo": cty.True,
|
||||||
})
|
})
|
||||||
deps := []addrs.ConfigResource{
|
// The in-memory order of resource dependencies is random, since they're an
|
||||||
|
// unordered set.
|
||||||
|
depsOne := []addrs.ConfigResource{
|
||||||
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"),
|
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"),
|
||||||
addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"),
|
addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"),
|
||||||
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"),
|
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"),
|
||||||
}
|
}
|
||||||
wantDeps := []addrs.ConfigResource{
|
depsTwo := []addrs.ConfigResource{
|
||||||
addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"),
|
addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"),
|
||||||
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"),
|
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"),
|
||||||
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"),
|
addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"),
|
||||||
}
|
}
|
||||||
rio := &ResourceInstanceObject{
|
rioOne := &ResourceInstanceObject{
|
||||||
Value: value,
|
Value: value,
|
||||||
Status: ObjectPlanned,
|
Status: ObjectPlanned,
|
||||||
Dependencies: deps,
|
Dependencies: depsOne,
|
||||||
}
|
}
|
||||||
rios, err := rio.Encode(value.Type(), 0)
|
rioTwo := &ResourceInstanceObject{
|
||||||
|
Value: value,
|
||||||
|
Status: ObjectPlanned,
|
||||||
|
Dependencies: depsTwo,
|
||||||
|
}
|
||||||
|
riosOne, err := rioOne.Encode(value.Type(), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
if diff := cmp.Diff(wantDeps, rios.Dependencies); diff != "" {
|
riosTwo, err := rioTwo.Encode(value.Type(), 0)
|
||||||
t.Errorf("wrong result for deps\n%s", diff)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
}
|
||||||
|
// However, identical sets of dependencies should always be written to state
|
||||||
|
// in an identical order, so we don't do meaningless state updates on refresh.
|
||||||
|
if diff := cmp.Diff(riosOne.Dependencies, riosTwo.Dependencies); diff != "" {
|
||||||
|
t.Errorf("identical dependencies got encoded in different orders:\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue