helper/schema: add test for statefunc with nested sets

refs #1759
This commit is contained in:
Paul Hinze 2015-04-30 15:20:33 -05:00
parent 99ce760569
commit cb3cbffb19
1 changed files with 68 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"reflect"
"strconv"
"testing"
"github.com/hashicorp/terraform/config"
@ -2281,6 +2282,72 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
// #59: StateFunc in nested set (#1759)
{
Schema: map[string]*Schema{
"service_account": &Schema{
Type: TypeList,
Optional: true,
ForceNew: true,
Elem: &Resource{
Schema: map[string]*Schema{
"scopes": &Schema{
Type: TypeSet,
Required: true,
ForceNew: true,
Elem: &Schema{
Type: TypeString,
StateFunc: func(v interface{}) string {
return v.(string) + "!"
},
},
Set: func(v interface{}) int {
i, err := strconv.Atoi(v.(string))
if err != nil {
t.Fatalf("err: %s", err)
}
return i
},
},
},
},
},
},
State: nil,
Config: map[string]interface{}{
"service_account": []map[string]interface{}{
{
"scopes": []interface{}{"123"},
},
},
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"service_account.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
RequiresNew: true,
},
"service_account.0.scopes.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
RequiresNew: true,
},
"service_account.0.scopes.123": &terraform.ResourceAttrDiff{
Old: "",
New: "123!",
NewExtra: "123",
RequiresNew: true,
},
},
},
Err: false,
},
}
for i, tc := range cases {
@ -2307,7 +2374,7 @@ func TestSchemaMap_Diff(t *testing.T) {
}
if !reflect.DeepEqual(tc.Diff, d) {
t.Fatalf("#%d: bad:\n\n%#v", i, d)
t.Fatalf("#%d:\n\nexpected: %#v\n\ngot:\n\n%#v", i, tc.Diff, d)
}
}
}