From 57f7507ebd7161a12559673024cba345d5fc66cc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Feb 2015 21:43:54 -0800 Subject: [PATCH] terraform: more state tests, fix a bug --- terraform/state.go | 3 +++ terraform/state_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/terraform/state.go b/terraform/state.go index f94d9bedc..5b695c33c 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -172,6 +172,9 @@ func (s *State) Equal(other *State) bool { } // If any of the modules are not equal, then this state isn't equal + if len(s.Modules) != len(other.Modules) { + return false + } for _, m := range s.Modules { // This isn't very optimal currently but works. otherM := other.ModuleByPath(m.Path) diff --git a/terraform/state_test.go b/terraform/state_test.go index aaa049f4b..ef2aa0b59 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -116,6 +116,19 @@ func TestStateEqual(t *testing.T) { Result bool One, Two *State }{ + // Nils + { + false, + nil, + &State{Version: 2}, + }, + + { + true, + nil, + nil, + }, + // Different versions { false, @@ -159,6 +172,9 @@ func TestStateEqual(t *testing.T) { if tc.One.Equal(tc.Two) != tc.Result { t.Fatalf("Bad: %d\n\n%s\n\n%s", i, tc.One.String(), tc.Two.String()) } + if tc.Two.Equal(tc.One) != tc.Result { + t.Fatalf("Bad: %d\n\n%s\n\n%s", i, tc.One.String(), tc.Two.String()) + } } }