mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-16 16:01:49 -04:00
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>
63 lines
2.7 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|