terraform: MergeDiff can take nil diff

This commit is contained in:
Mitchell Hashimoto 2014-06-23 12:32:04 -07:00
parent d93df76f66
commit 7eacacbff2
2 changed files with 27 additions and 6 deletions

View File

@ -131,6 +131,7 @@ func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState {
result.Attributes[k] = v
}
}
if d != nil {
for k, diff := range d.Attributes {
if diff.NewComputed {
result.Attributes[k] = config.UnknownVariableValue
@ -139,6 +140,7 @@ func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState {
result.Attributes[k] = diff.New
}
}
return &result
}

View File

@ -70,6 +70,25 @@ func TestResourceState_MergeDiff_nil(t *testing.T) {
}
}
func TestResourceState_MergeDiff_nilDiff(t *testing.T) {
rs := ResourceState{
ID: "foo",
Attributes: map[string]string{
"foo": "bar",
},
}
rs2 := rs.MergeDiff(nil)
expected := map[string]string{
"foo": "bar",
}
if !reflect.DeepEqual(expected, rs2.Attributes) {
t.Fatalf("bad: %#v", rs2.Attributes)
}
}
func TestReadWriteState(t *testing.T) {
state := &State{
Resources: map[string]*ResourceState{