helper/schema: some more test cases, revert some weird behavior from

dbfb95fcd5

I don't know why that behavior was in there, but it was breaking a lot
of existing Terraform states. Let's circle back on it.
This commit is contained in:
Mitchell Hashimoto 2015-02-18 12:54:08 -08:00
parent c7e536680d
commit 17680bb7ff
2 changed files with 50 additions and 6 deletions

View File

@ -702,7 +702,6 @@ func (m schemaMap) diffSet(
return nil
}
oRaw := o
if o == nil {
o = &Set{F: schema.Set}
}
@ -751,7 +750,7 @@ func (m schemaMap) diffSet(
// If the counts are not the same, then record that diff
changed := oldLen != newLen
if changed || all || oRaw == nil {
if changed || all {
countSchema := &Schema{
Type: TypeInt,
Computed: schema.Computed,
@ -812,7 +811,7 @@ func (m schemaMap) diffString(
n = schema.StateFunc(n)
}
nraw := n
if nraw == nil {
if nraw == nil && o != nil {
nraw = schema.Type.Zero()
}
if err := mapstructure.WeakDecode(o, &os); err != nil {

View File

@ -1967,7 +1967,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
// #49 Set - Same as #47 but for sets
// #49 Set - Same as #48 but for sets
{
Schema: map[string]*Schema{
"route": &Schema{
@ -2047,14 +2047,19 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: nil,
State: &terraform.InstanceState{
Attributes: map[string]string{
"instances.#": "1",
"instances.3": "foo",
},
},
Config: map[string]interface{}{},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"instances.#": &terraform.ResourceAttrDiff{
Old: "0",
Old: "1",
New: "0",
RequiresNew: true,
},
@ -2095,6 +2100,46 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
// #53 - Unset bool, not in state
{
Schema: map[string]*Schema{
"force": &Schema{
Type: TypeBool,
Optional: true,
ForceNew: true,
},
},
State: nil,
Config: map[string]interface{}{},
Diff: nil,
Err: false,
},
// #54 - Unset set, not in state
{
Schema: map[string]*Schema{
"metadata_keys": &Schema{
Type: TypeSet,
Optional: true,
ForceNew: true,
Elem: &Schema{Type: TypeInt},
Set: func(interface{}) int { return 0 },
},
},
State: nil,
Config: map[string]interface{}{},
Diff: nil,
Err: false,
},
}
for i, tc := range cases {