mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: ResourceConfig.Equal and tests
This commit is contained in:
parent
56901e5cfd
commit
f897fa4701
@ -113,6 +113,26 @@ func (c *ResourceConfig) DeepCopy() *ResourceConfig {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Equal checks the equality of two resource configs.
|
||||||
|
func (c *ResourceConfig) Equal(c2 *ResourceConfig) bool {
|
||||||
|
// Two resource configs if their exported properties are equal.
|
||||||
|
// We don't compare "raw" because it is never used again after
|
||||||
|
// initialization and for all intents and purposes they are equal
|
||||||
|
// if the exported properties are equal.
|
||||||
|
check := [][2]interface{}{
|
||||||
|
{c.ComputedKeys, c2.ComputedKeys},
|
||||||
|
{c.Raw, c2.Raw},
|
||||||
|
{c.Config, c2.Config},
|
||||||
|
}
|
||||||
|
for _, pair := range check {
|
||||||
|
if !reflect.DeepEqual(pair[0], pair[1]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// CheckSet checks that the given list of configuration keys is
|
// CheckSet checks that the given list of configuration keys is
|
||||||
// properly set. If not, errors are returned for each unset key.
|
// properly set. If not, errors are returned for each unset key.
|
||||||
//
|
//
|
||||||
|
@ -209,22 +209,32 @@ func TestResourceConfigGet(t *testing.T) {
|
|||||||
rc := NewResourceConfig(rawC)
|
rc := NewResourceConfig(rawC)
|
||||||
rc.interpolateForce()
|
rc.interpolateForce()
|
||||||
|
|
||||||
v, _ := rc.Get(tc.Key)
|
// Test getting a key
|
||||||
if !reflect.DeepEqual(v, tc.Value) {
|
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
||||||
t.Fatalf("%d bad: %#v", i, v)
|
v, _ := rc.Get(tc.Key)
|
||||||
}
|
if !reflect.DeepEqual(v, tc.Value) {
|
||||||
|
t.Fatalf("%d bad: %#v", i, v)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// If we have vars, we don't test copying
|
// If we have vars, we don't test copying
|
||||||
if len(tc.Vars) > 0 {
|
if len(tc.Vars) > 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test copying
|
// Test copying and equality
|
||||||
t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("copy-and-equal-%d", i), func(t *testing.T) {
|
||||||
copy := rc.DeepCopy()
|
copy := rc.DeepCopy()
|
||||||
if !reflect.DeepEqual(copy, rc) {
|
if !reflect.DeepEqual(copy, rc) {
|
||||||
t.Fatalf("bad:\n\n%#v\n\n%#v", copy, rc)
|
t.Fatalf("bad:\n\n%#v\n\n%#v", copy, rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !copy.Equal(rc) {
|
||||||
|
t.Fatalf("copy != rc:\n\n%#v\n\n%#v", copy, rc)
|
||||||
|
}
|
||||||
|
if !rc.Equal(copy) {
|
||||||
|
t.Fatalf("rc != copy:\n\n%#v\n\n%#v", copy, rc)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user