helper/schema: add clarifying GetOk test

Wrote this test to verify behavior, committing and commenting to help me
get the answer faster in the future.
This commit is contained in:
Paul Hinze 2015-05-04 14:58:12 -05:00
parent fad08081b2
commit a3101568c5
1 changed files with 28 additions and 1 deletions

View File

@ -987,6 +987,33 @@ func TestResourceDataGetOk(t *testing.T) {
Value: []interface{}{},
Ok: false,
},
// Further illustrates and clarifiies the GetOk semantics from #933, and
// highlights the limitation that zero-value config is currently
// indistinguishable from unset config.
{
Schema: map[string]*Schema{
"from_port": &Schema{
Type: TypeInt,
Optional: true,
},
},
State: nil,
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"from_port": &terraform.ResourceAttrDiff{
Old: "",
New: "0",
},
},
},
Key: "from_port",
Value: 0,
Ok: false,
},
}
for i, tc := range cases {
@ -1004,7 +1031,7 @@ func TestResourceDataGetOk(t *testing.T) {
t.Fatalf("Bad: %d\n\n%#v", i, v)
}
if ok != tc.Ok {
t.Fatalf("Bad: %d\n\n%#v", i, ok)
t.Fatalf("%d: expected ok: %t, got: %t", i, tc.Ok, ok)
}
}
}