terraform: MergeDiff can take nil diff
This commit is contained in:
parent
d93df76f66
commit
7eacacbff2
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue