Skip to content

Commit 55e340c

Browse files
committed
more equality testing
1 parent 659d5e2 commit 55e340c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

internal/states/state_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ func TestStateDeepCopy(t *testing.T) {
203203
Private: []byte("private data"),
204204
Dependencies: []addrs.ConfigResource{},
205205
CreateBeforeDestroy: true,
206+
207+
// these may or may not be copied, but should not affect equality of
208+
// the resources.
209+
decodeValueCache: cty.ObjectVal(map[string]cty.Value{
210+
"woozles": cty.StringVal("confuzles"),
211+
}),
212+
decodeIdentityCache: cty.DynamicVal,
206213
},
207214
addrs.AbsProviderConfig{
208215
Provider: addrs.NewDefaultProvider("test"),
@@ -242,11 +249,34 @@ func TestStateDeepCopy(t *testing.T) {
242249
)
243250

244251
state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey))
245-
246252
stateCopy := state.DeepCopy()
247253
if !state.Equal(stateCopy) {
248254
t.Fatalf("\nexpected:\n%q\ngot:\n%q\n", state, stateCopy)
249255
}
256+
257+
// this is implied by the above, but has previously used a different
258+
// codepath for comparison.
259+
if !state.ManagedResourcesEqual(stateCopy) {
260+
t.Fatalf("\nexpected managed resources to be equal:\n%q\ngot:\n%q\n", state, stateCopy)
261+
}
262+
263+
// remove the cached values and ensure equality still holds
264+
for _, mod := range stateCopy.Modules {
265+
for _, res := range mod.Resources {
266+
for _, inst := range res.Instances {
267+
inst.Current.decodeValueCache = cty.NilVal
268+
inst.Current.decodeIdentityCache = cty.NilVal
269+
}
270+
}
271+
}
272+
273+
if !state.Equal(stateCopy) {
274+
t.Fatalf("\nexpected:\n%q\ngot:\n%q\n", state, stateCopy)
275+
}
276+
277+
if !state.ManagedResourcesEqual(stateCopy) {
278+
t.Fatalf("\nexpected managed resources to be equal:\n%q\ngot:\n%q\n", state, stateCopy)
279+
}
250280
}
251281

252282
func TestStateHasResourceInstanceObjects(t *testing.T) {

0 commit comments

Comments
 (0)