terraform: more state tests, fix a bug

This commit is contained in:
Mitchell Hashimoto 2015-02-23 21:43:54 -08:00
parent cc8e6b6331
commit 57f7507ebd
2 changed files with 19 additions and 0 deletions

View File

@ -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 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 { for _, m := range s.Modules {
// This isn't very optimal currently but works. // This isn't very optimal currently but works.
otherM := other.ModuleByPath(m.Path) otherM := other.ModuleByPath(m.Path)

View File

@ -116,6 +116,19 @@ func TestStateEqual(t *testing.T) {
Result bool Result bool
One, Two *State One, Two *State
}{ }{
// Nils
{
false,
nil,
&State{Version: 2},
},
{
true,
nil,
nil,
},
// Different versions // Different versions
{ {
false, false,
@ -159,6 +172,9 @@ func TestStateEqual(t *testing.T) {
if tc.One.Equal(tc.Two) != tc.Result { 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()) 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())
}
} }
} }