terraform: ResourceDiff tests

This commit is contained in:
Mitchell Hashimoto 2014-06-17 18:10:38 -07:00
parent 6bef265514
commit f032ce6c1b
2 changed files with 30 additions and 0 deletions

View File

@ -98,6 +98,10 @@ type ResourceAttrDiff struct {
// RequiresNew returns true if the diff requires the creation of a new // RequiresNew returns true if the diff requires the creation of a new
// resource (implying the destruction of the old). // resource (implying the destruction of the old).
func (d *ResourceDiff) RequiresNew() bool { func (d *ResourceDiff) RequiresNew() bool {
if d == nil {
return false
}
for _, rd := range d.Attributes { for _, rd := range d.Attributes {
if rd.RequiresNew { if rd.RequiresNew {
return true return true

View File

@ -35,6 +35,32 @@ func TestDiff_String(t *testing.T) {
} }
} }
func TestResourceDiff_RequiresNew(t *testing.T) {
rd := &ResourceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{},
},
}
if rd.RequiresNew() {
t.Fatal("should not require new")
}
rd.Attributes["foo"].RequiresNew = true
if !rd.RequiresNew() {
t.Fatal("should require new")
}
}
func TestResourceDiff_RequiresNew_nil(t *testing.T) {
var rd *ResourceDiff
if rd.RequiresNew() {
t.Fatal("should not require new")
}
}
const diffStrBasic = ` const diffStrBasic = `
CREATE: nodeA CREATE: nodeA
bar: "foo" => "<computed>" bar: "foo" => "<computed>"