Files
opentf/internal/states/instance_object_src_test.go
Martin Atkins a803f4cc2f states: go fix various files that changed recently
We already changed these files considerably in opentofu/opentofu#3671, so
we'll take this opportunity to modernize the rest of the code while the
likelihood of successful clean backporting from this file is pretty low
anyway.

In the case of instance_object_src_test.go some additional editing was
required because uint64Ptr becomes unused when we adopt the built-in "new"
function, which would cause this file to fail the dead code lint.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2026-04-01 11:48:31 -07:00

63 lines
2.7 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package states
import (
"testing"
)
func TestResourceInstanceObjectSrcEqual(t *testing.T) {
tests := map[string]struct {
a *ResourceInstanceObjectSrc
b *ResourceInstanceObjectSrc
want bool
}{
"identical base objects": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`)},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`)},
want: true,
},
"identity schema version both nil": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: nil},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: nil},
want: true,
},
"identity schema version first nil": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: nil},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(1))},
want: false,
},
"identity schema version second nil": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(1))},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: nil},
want: false,
},
"identity schema version different values": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(1))},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(2))},
want: false,
},
"identity schema version same values": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(1))},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentitySchemaVersion: new(uint64(1))},
want: true,
},
"same identity json different schema version": {
a: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentityJSON: []byte(`{"name":"bar"}`), IdentitySchemaVersion: new(uint64(1))},
b: &ResourceInstanceObjectSrc{Status: ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), IdentityJSON: []byte(`{"name":"bar"}`), IdentitySchemaVersion: new(uint64(2))},
want: false,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
if got := tc.a.Equal(tc.b); got != tc.want {
t.Fatalf("got %v, want %v", got, tc.want)
}
})
}
}