From 50afee2a30d88f5829dec86fcdb205454929ea2c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Sep 2016 19:37:19 -0600 Subject: [PATCH] terraform: Diff.Empty should be true for nil Diff --- terraform/diff.go | 4 ++++ terraform/diff_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/terraform/diff.go b/terraform/diff.go index e0e097e80..86be4bb5a 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -72,6 +72,10 @@ func (d *Diff) RootModule() *ModuleDiff { // Empty returns true if the diff has no changes. func (d *Diff) Empty() bool { + if d == nil { + return true + } + for _, m := range d.Modules { if !m.Empty() { return false diff --git a/terraform/diff_test.go b/terraform/diff_test.go index 5234c6aaf..a9cb8b47b 100644 --- a/terraform/diff_test.go +++ b/terraform/diff_test.go @@ -7,7 +7,12 @@ import ( ) func TestDiffEmpty(t *testing.T) { - diff := new(Diff) + var diff *Diff + if !diff.Empty() { + t.Fatal("should be empty") + } + + diff = new(Diff) if !diff.Empty() { t.Fatal("should be empty") }