mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-27 00:46:25 -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
|
||||
}
|
||||
|
||||
// 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
|
||||
// properly set. If not, errors are returned for each unset key.
|
||||
//
|
||||
|
@ -209,22 +209,32 @@ func TestResourceConfigGet(t *testing.T) {
|
||||
rc := NewResourceConfig(rawC)
|
||||
rc.interpolateForce()
|
||||
|
||||
v, _ := rc.Get(tc.Key)
|
||||
if !reflect.DeepEqual(v, tc.Value) {
|
||||
t.Fatalf("%d bad: %#v", i, v)
|
||||
}
|
||||
// Test getting a key
|
||||
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
||||
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 len(tc.Vars) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Test copying
|
||||
t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
|
||||
// Test copying and equality
|
||||
t.Run(fmt.Sprintf("copy-and-equal-%d", i), func(t *testing.T) {
|
||||
copy := rc.DeepCopy()
|
||||
if !reflect.DeepEqual(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