|
|
|
|
@ -3647,3 +3647,94 @@ func TestSchemaMap_Validate(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSchemaSet_ValidateMaxItems(t *testing.T) {
|
|
|
|
|
cases := map[string]struct {
|
|
|
|
|
Schema map[string]*Schema
|
|
|
|
|
State *terraform.InstanceState
|
|
|
|
|
Config map[string]interface{}
|
|
|
|
|
ConfigVariables map[string]string
|
|
|
|
|
Diff *terraform.InstanceDiff
|
|
|
|
|
Err bool
|
|
|
|
|
Errors []error
|
|
|
|
|
}{
|
|
|
|
|
"#0": {
|
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
|
"aliases": &Schema{
|
|
|
|
|
Type: TypeSet,
|
|
|
|
|
Optional: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
State: nil,
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"aliases": []interface{}{"foo", "bar"},
|
|
|
|
|
},
|
|
|
|
|
Diff: nil,
|
|
|
|
|
Err: true,
|
|
|
|
|
Errors: []error{
|
|
|
|
|
fmt.Errorf("aliases: attribute supports 1 item maximum, config has 2 declared"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"#1": {
|
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
|
"aliases": &Schema{
|
|
|
|
|
Type: TypeSet,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
State: nil,
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"aliases": []interface{}{"foo", "bar"},
|
|
|
|
|
},
|
|
|
|
|
Diff: nil,
|
|
|
|
|
Err: false,
|
|
|
|
|
Errors: nil,
|
|
|
|
|
},
|
|
|
|
|
"#2": {
|
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
|
"aliases": &Schema{
|
|
|
|
|
Type: TypeSet,
|
|
|
|
|
Optional: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
State: nil,
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"aliases": []interface{}{"foo"},
|
|
|
|
|
},
|
|
|
|
|
Diff: nil,
|
|
|
|
|
Err: false,
|
|
|
|
|
Errors: nil,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for tn, tc := range cases {
|
|
|
|
|
c, err := config.NewRawConfig(tc.Config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("%q: err: %s", tn, err)
|
|
|
|
|
}
|
|
|
|
|
_, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c))
|
|
|
|
|
|
|
|
|
|
if len(es) > 0 != tc.Err {
|
|
|
|
|
if len(es) == 0 {
|
|
|
|
|
t.Errorf("%q: no errors", tn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, e := range es {
|
|
|
|
|
t.Errorf("%q: err: %s", tn, e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.FailNow()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if tc.Errors != nil {
|
|
|
|
|
if !reflect.DeepEqual(es, tc.Errors) {
|
|
|
|
|
t.Fatalf("%q: expected: %q\ngot: %q", tn, tc.Errors, es)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|