helper/schema: more tests, todo tests for computedwhen

This commit is contained in:
Mitchell Hashimoto 2014-08-16 13:32:21 -07:00
parent 7bc0be4b81
commit 43e4921bd9
3 changed files with 68 additions and 0 deletions

View File

@ -250,6 +250,26 @@ func TestResourceDataGet(t *testing.T) {
},
},
},
// Computed get
{
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Computed: true,
},
},
State: &terraform.ResourceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
},
Key: "availability_zone",
Value: "foo",
},
}
for i, tc := range cases {

View File

@ -112,12 +112,17 @@ func (m schemaMap) Diff(
}
}
// Remove any nil diffs just to keep things clean
for k, v := range result.Attributes {
if v == nil {
delete(result.Attributes, k)
}
}
// Go through and detect all of the ComputedWhens now that we've
// finished the diff.
// TODO
if result.Empty() {
// If we don't have any diff elements, just return nil
return nil, nil

View File

@ -505,6 +505,49 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
/* TODO
{
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Computed: true,
ComputedWhen: []string{"port"},
},
"port": &Schema{
Type: TypeInt,
Optional: true,
},
},
State: &terraform.ResourceState{
Attributes: map[string]string{
"availability_zone": "foo",
"port": "80",
},
},
Config: map[string]interface{}{
"port": 8080,
},
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "foo",
NewComputed: true,
},
"port": &terraform.ResourceAttrDiff{
Old: "80",
New: "8080",
},
},
},
Err: false,
},
*/
}
for i, tc := range cases {