Merge pull request #15448 from hashicorp/jbardin/state-meta-equal
make sure marshaled Meta fields are still equal
This commit is contained in:
commit
593bf683dc
|
@ -1685,7 +1685,20 @@ func (s *InstanceState) Equal(other *InstanceState) bool {
|
|||
// We only do the deep check if both are non-nil. If one is nil
|
||||
// we treat it as equal since their lengths are both zero (check
|
||||
// above).
|
||||
if !reflect.DeepEqual(s.Meta, other.Meta) {
|
||||
//
|
||||
// Since this can contain numeric values that may change types during
|
||||
// serialization, let's compare the serialized values.
|
||||
sMeta, err := json.Marshal(s.Meta)
|
||||
if err != nil {
|
||||
// marshaling primitives shouldn't ever error out
|
||||
panic(err)
|
||||
}
|
||||
otherMeta, err := json.Marshal(other.Meta)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(sMeta, otherMeta) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,6 +467,50 @@ func TestStateEqual(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Meta with complex types that have been altered during serialization
|
||||
{
|
||||
"same meta with complex types that have been json-ified",
|
||||
true,
|
||||
&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"test_instance.foo": &ResourceState{
|
||||
Primary: &InstanceState{
|
||||
Meta: map[string]interface{}{
|
||||
"timeouts": map[string]interface{}{
|
||||
"create": int(42),
|
||||
"read": "27",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"test_instance.foo": &ResourceState{
|
||||
Primary: &InstanceState{
|
||||
Meta: map[string]interface{}{
|
||||
"timeouts": map[string]interface{}{
|
||||
"create": float64(42),
|
||||
"read": "27",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue