2014-06-05 08:57:06 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResourceState_MergeDiff(t *testing.T) {
|
|
|
|
rs := ResourceState{
|
|
|
|
ID: "foo",
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diff := map[string]*ResourceAttrDiff{
|
|
|
|
"foo": &ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
"bar": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
2014-06-05 09:01:51 -05:00
|
|
|
"baz": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
2014-06-05 08:57:06 -05:00
|
|
|
}
|
|
|
|
|
2014-06-05 09:01:51 -05:00
|
|
|
rs2 := rs.MergeDiff(diff, "what")
|
2014-06-05 08:57:06 -05:00
|
|
|
|
|
|
|
expected := map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
"bar": "foo",
|
2014-06-05 09:01:51 -05:00
|
|
|
"baz": "what",
|
2014-06-05 08:57:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, rs2.Attributes) {
|
|
|
|
t.Fatalf("bad: %#v", rs2.Attributes)
|
|
|
|
}
|
|
|
|
}
|
2014-06-05 09:04:44 -05:00
|
|
|
|
|
|
|
func TestResourceState_MergeDiff_nil(t *testing.T) {
|
|
|
|
var rs *ResourceState = nil
|
|
|
|
|
|
|
|
diff := map[string]*ResourceAttrDiff{
|
|
|
|
"foo": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
rs2 := rs.MergeDiff(diff, "computed")
|
|
|
|
|
|
|
|
expected := map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, rs2.Attributes) {
|
|
|
|
t.Fatalf("bad: %#v", rs2.Attributes)
|
|
|
|
}
|
|
|
|
}
|