From f032ce6c1bf26653935fa1aabb058ff8f3e7afa1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Jun 2014 18:10:38 -0700 Subject: [PATCH] terraform: ResourceDiff tests --- terraform/diff.go | 4 ++++ terraform/diff_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/terraform/diff.go b/terraform/diff.go index bef052827..4baf2ebbc 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -98,6 +98,10 @@ type ResourceAttrDiff struct { // RequiresNew returns true if the diff requires the creation of a new // resource (implying the destruction of the old). func (d *ResourceDiff) RequiresNew() bool { + if d == nil { + return false + } + for _, rd := range d.Attributes { if rd.RequiresNew { return true diff --git a/terraform/diff_test.go b/terraform/diff_test.go index 7e7acda21..0e4d951d7 100644 --- a/terraform/diff_test.go +++ b/terraform/diff_test.go @@ -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 = ` CREATE: nodeA bar: "foo" => ""