Merge pull request #1762 from hashicorp/f-add-test-for-nested-set-statefunc
helper/schema: add test for statefunc with nested sets
This commit is contained in:
commit
1671f1e50c
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue