terraform: test case for if diff returns nil

This commit is contained in:
Mitchell Hashimoto 2014-06-10 10:50:23 -07:00
parent 743c3684c5
commit 061d96a08b
3 changed files with 20 additions and 1 deletions

View File

@ -154,7 +154,7 @@ func (t *Terraform) diffWalkFn(
}
// If there were no diff items, return right away
if len(diff.Attributes) == 0 {
if diff == nil || len(diff.Attributes) == 0 {
return nil
}

View File

@ -202,6 +202,18 @@ func TestTerraformDiff(t *testing.T) {
}
}
func TestTerraformDiff_nil(t *testing.T) {
tf := testTerraform(t, "diff-nil")
diff, err := tf.Diff(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if len(diff.Resources) != 0 {
t.Fatalf("bad: %#v", diff.Resources)
}
}
func TestTerraformDiff_computed(t *testing.T) {
tf := testTerraform(t, "diff-computed")
@ -269,6 +281,10 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
continue
}
if k == "nil" {
return nil, nil
}
if k == "compute" {
diff.Attributes[v.(string)] = &ResourceAttrDiff{
Old: "",

View File

@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
nil = "1"
}