Merge pull request #1127 from hashicorp/f-deprecation

helper/schema: [tests] add names to Validate tests
This commit is contained in:
Paul Hinze 2015-03-05 13:36:14 -06:00
commit 31529be403
1 changed files with 28 additions and 51 deletions

View File

@ -2583,15 +2583,14 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
} }
func TestSchemaMap_Validate(t *testing.T) { func TestSchemaMap_Validate(t *testing.T) {
cases := []struct { cases := map[string]struct {
Schema map[string]*Schema Schema map[string]*Schema
Config map[string]interface{} Config map[string]interface{}
Vars map[string]string Vars map[string]string
Warn bool Warn bool
Err bool Err bool
}{ }{
// #0 Good "Good": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2606,8 +2605,7 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
}, },
// #1 Good, because the var is not set and that error will come elsewhere "Good, because the var is not set and that error will come elsewhere": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"size": &Schema{ "size": &Schema{
Type: TypeInt, Type: TypeInt,
@ -2624,8 +2622,7 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
}, },
// #2 Required field not set "Required field not set": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2638,8 +2635,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #3 Invalid type "Invalid basic type": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"port": &Schema{ "port": &Schema{
Type: TypeInt, Type: TypeInt,
@ -2654,8 +2650,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #4 "Invalid complex type": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"user_data": &Schema{ "user_data": &Schema{
Type: TypeString, Type: TypeString,
@ -2674,8 +2669,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #5 Bad type, interpolated "Bad type, interpolated": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"size": &Schema{ "size": &Schema{
Type: TypeInt, Type: TypeInt,
@ -2694,8 +2688,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #6 Required but has DefaultFunc "Required but has DefaultFunc": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2709,8 +2702,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Config: nil, Config: nil,
}, },
// #7 Required but has DefaultFunc return nil "Required but has DefaultFunc return nil": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2726,8 +2718,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #8 Optional sub-resource "Optional sub-resource": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -2747,8 +2738,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: false, Err: false,
}, },
// #9 Not a list "Not a list": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -2770,8 +2760,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #10 Required sub-resource field "Required sub-resource field": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -2795,8 +2784,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #11 Good sub-resource "Good sub-resource": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -2823,8 +2811,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: false, Err: false,
}, },
// #12 Invalid/unknown field "Invalid/unknown field": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2841,8 +2828,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #13 Computed field set "Computed field set": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{
Type: TypeString, Type: TypeString,
@ -2857,8 +2843,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #14 Not a set "Not a set": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ports": &Schema{ "ports": &Schema{
Type: TypeSet, Type: TypeSet,
@ -2877,8 +2862,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #15 Maps "Maps": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"user_data": &Schema{ "user_data": &Schema{
Type: TypeMap, Type: TypeMap,
@ -2893,8 +2877,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #16 "Good map: data surrounded by extra slice": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"user_data": &Schema{ "user_data": &Schema{
Type: TypeMap, Type: TypeMap,
@ -2911,8 +2894,7 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
}, },
// #17 "Good map": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"user_data": &Schema{ "user_data": &Schema{
Type: TypeMap, Type: TypeMap,
@ -2927,8 +2909,7 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
}, },
// #18 "Bad map: just a slice": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"user_data": &Schema{ "user_data": &Schema{
Type: TypeMap, Type: TypeMap,
@ -2945,8 +2926,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #19 "Good set: config has slice with single interpolated value": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"security_groups": &Schema{ "security_groups": &Schema{
Type: TypeSet, Type: TypeSet,
@ -2967,8 +2947,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: false, Err: false,
}, },
// #20 "Bad set: config has single interpolated value": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"security_groups": &Schema{ "security_groups": &Schema{
Type: TypeSet, Type: TypeSet,
@ -2986,8 +2965,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #21 Bad, subresource should not allow unknown elements "Bad, subresource should not allow unknown elements": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -3015,8 +2993,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// #22 Bad, subresource should not allow invalid types "Bad, subresource should not allow invalid types": {
{
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"ingress": &Schema{ "ingress": &Schema{
Type: TypeList, Type: TypeList,
@ -3044,7 +3021,7 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
} }
for i, tc := range cases { for tn, tc := range cases {
c, err := config.NewRawConfig(tc.Config) c, err := config.NewRawConfig(tc.Config)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
@ -3063,18 +3040,18 @@ func TestSchemaMap_Validate(t *testing.T) {
ws, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c)) ws, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c))
if (len(es) > 0) != tc.Err { if (len(es) > 0) != tc.Err {
if len(es) == 0 { if len(es) == 0 {
t.Errorf("%d: no errors", i) t.Errorf("%q: no errors", tn)
} }
for _, e := range es { for _, e := range es {
t.Errorf("%d: err: %s", i, e) t.Errorf("%q: err: %s", tn, e)
} }
t.FailNow() t.FailNow()
} }
if (len(ws) > 0) != tc.Warn { if (len(ws) > 0) != tc.Warn {
t.Fatalf("%d: ws: %#v", i, ws) t.Fatalf("%q: ws: %#v", tn, ws)
} }
} }
} }