helper/schema: test with DiffSuppress and Default

This commit is contained in:
Mitchell Hashimoto 2016-10-24 22:23:13 -07:00
parent f6873be4f1
commit fa9758e162
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 68 additions and 16 deletions

View File

@ -2970,6 +2970,7 @@ func TestSchemaMap_DiffSuppress(t *testing.T) {
Err: false,
},
"#1 - Don't suppress diff by returning false": {
Schema: map[string]*Schema{
"availability_zone": {
@ -2999,9 +3000,59 @@ func TestSchemaMap_DiffSuppress(t *testing.T) {
Err: false,
},
"Default with suppress makes no diff": {
Schema: map[string]*Schema{
"availability_zone": {
Type: TypeString,
Optional: true,
Default: "foo",
DiffSuppressFunc: func(k, old, new string, d *ResourceData) bool {
return true
},
},
},
State: nil,
Config: map[string]interface{}{},
ExpectedDiff: nil,
Err: false,
},
"Default with false suppress makes diff": {
Schema: map[string]*Schema{
"availability_zone": {
Type: TypeString,
Optional: true,
Default: "foo",
DiffSuppressFunc: func(k, old, new string, d *ResourceData) bool {
return false
},
},
},
State: nil,
Config: map[string]interface{}{},
ExpectedDiff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": {
Old: "",
New: "foo",
},
},
},
Err: false,
},
}
for tn, tc := range cases {
t.Run(tn, func(t *testing.T) {
c, err := config.NewRawConfig(tc.Config)
if err != nil {
t.Fatalf("#%q err: %s", tn, err)
@ -3022,6 +3073,7 @@ func TestSchemaMap_DiffSuppress(t *testing.T) {
if !reflect.DeepEqual(tc.ExpectedDiff, d) {
t.Fatalf("#%q:\n\nexpected:\n%#v\n\ngot:\n%#v", tn, tc.ExpectedDiff, d)
}
})
}
}