@ -3895,3 +3895,94 @@ func TestSchemaSet_ValidateMaxItems(t *testing.T) {
}
}
}
func TestSchemaSet_ValidateMinItems ( 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 ,
MinItems : 2 ,
Elem : & Schema { Type : TypeString } ,
} ,
} ,
State : nil ,
Config : map [ string ] interface { } {
"aliases" : [ ] interface { } { "foo" , "bar" } ,
} ,
Diff : nil ,
Err : false ,
Errors : nil ,
} ,
"#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 ,
MinItems : 2 ,
Elem : & Schema { Type : TypeString } ,
} ,
} ,
State : nil ,
Config : map [ string ] interface { } {
"aliases" : [ ] interface { } { "foo" } ,
} ,
Diff : nil ,
Err : true ,
Errors : [ ] error {
fmt . Errorf ( "aliases: attribute supports 2 item as a minimum, config has 1 declared" ) ,
} ,
} ,
}
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 )
}
}
}
}