@@ -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 ("\n expected:\n %q\n got:\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 ("\n expected managed resources to be equal:\n %q\n got:\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 ("\n expected:\n %q\n got:\n %q\n " , state , stateCopy )
275+ }
276+
277+ if ! state .ManagedResourcesEqual (stateCopy ) {
278+ t .Fatalf ("\n expected managed resources to be equal:\n %q\n got:\n %q\n " , state , stateCopy )
279+ }
250280}
251281
252282func TestStateHasResourceInstanceObjects (t * testing.T ) {
0 commit comments