Skip to content

Commit

Permalink
final error test no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Aug 16, 2019
1 parent de524fb commit 5b56d40
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions configs/configschema/coerce_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ import (

func TestCoerceValue(t *testing.T) {
tests := map[string]struct {
Schema *Block
Input cty.Value
WantValue cty.Value
WantErr string
ValidateErr string
CoercedValidateErr string
Schema *Block
Input cty.Value
WantValue cty.Value
WantErr string
ValidateErr string
}{
"empty schema and value": {
&Block{},
cty.EmptyObjectVal,
cty.EmptyObjectVal,
``,
``,
``,
},
"attribute present": {
&Block{
Expand All @@ -43,7 +41,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
`attribute "foo" expected type cty.String, got cty.Bool`,
``,
},
"single block present": {
&Block{
Expand All @@ -62,7 +59,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"single block wrong type": {
&Block{
Expand All @@ -79,7 +75,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`.foo: an object is required`,
``,
``,
},
"list block with one item": {
&Block{
Expand All @@ -98,7 +93,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"set block with one item": {
&Block{
Expand All @@ -117,7 +111,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
`expected set for block "foo", got cty.ListVal([]cty.Value{cty.EmptyObjectVal})`,
``,
},
"map block with one item": {
&Block{
Expand All @@ -136,7 +129,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"list block with one item having an attribute": {
&Block{
Expand Down Expand Up @@ -166,7 +158,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"list block with one item having a missing attribute": {
&Block{
Expand All @@ -190,7 +181,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`.foo[0]: attribute "bar" is required`,
``,
``,
},
"list block with one item having an extraneous attribute": {
&Block{
Expand All @@ -209,7 +199,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`.foo[0]: unexpected attribute "bar"`,
``,
``,
},
"missing optional attribute": {
&Block{
Expand All @@ -226,7 +215,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"missing optional single block": {
&Block{
Expand All @@ -241,7 +229,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`value must be an object, got cty.NilType`,
``,
},
"missing optional list block": {
&Block{
Expand All @@ -256,7 +243,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`expected list for block "foo", got cty.NilVal`,
``,
},
"missing optional set block": {
&Block{
Expand All @@ -271,7 +257,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`expected set for block "foo", got cty.NilVal`,
``,
},
"missing optional map block": {
&Block{
Expand All @@ -286,7 +271,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`expected map or object for block "foo", got cty.NilVal`,
``,
},
"missing required attribute": {
&Block{
Expand All @@ -301,7 +285,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`attribute "foo" is required`,
``,
``,
},
"missing required single block": {
&Block{
Expand All @@ -318,7 +301,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`insufficient items for attribute "foo"; must have at least 1`,
``,
},
"missing required list block": {
&Block{
Expand All @@ -334,7 +316,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`insufficient items for attribute "foo"; must have at least 1`,
``,
},
"missing required set block": {
&Block{
Expand All @@ -350,7 +331,6 @@ func TestCoerceValue(t *testing.T) {
cty.EmptyObjectVal,
``,
`insufficient items for attribute "foo"; must have at least 1`,
``,
},
"unknown nested list": {
&Block{
Expand Down Expand Up @@ -378,7 +358,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
"",
``,
},
"unknowns in nested list": {
&Block{
Expand Down Expand Up @@ -413,7 +392,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
``, // unknowns in a list will prevent the length validation
``,
},
"less than min items": {
&Block{
Expand Down Expand Up @@ -448,7 +426,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
`insufficient items for attribute "foo"; must have at least 2`,
``,
},
"more than max items": {
&Block{
Expand Down Expand Up @@ -489,7 +466,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
`too many items for attribute "foo"; cannot have more than 1`,
``,
},
"unknown nested set": {
&Block{
Expand Down Expand Up @@ -517,7 +493,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
"",
"",
},
"unknown nested map": {
&Block{
Expand Down Expand Up @@ -545,7 +520,6 @@ func TestCoerceValue(t *testing.T) {
}),
"",
"",
"",
},
"extraneous attribute": {
&Block{},
Expand All @@ -555,7 +529,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`unexpected attribute "foo"`,
``,
``,
},
"wrong attribute type": {
&Block{
Expand All @@ -572,7 +545,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`.foo: number required`,
``,
``,
},
"unset computed value": {
&Block{
Expand All @@ -590,7 +562,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"dynamic value attributes": {
&Block{
Expand Down Expand Up @@ -639,7 +610,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
"dynamic attributes in map": {
// Convert a block represented as a map to an object if a
Expand Down Expand Up @@ -689,7 +659,6 @@ func TestCoerceValue(t *testing.T) {
}),
``,
``,
``,
},
}

Expand Down Expand Up @@ -731,19 +700,8 @@ func TestCoerceValue(t *testing.T) {
// is there was no error validating the input, make sure the
// coerced value also validates
if test.WantErr == "" && test.ValidateErr == "" {
validateErr := test.Schema.Validate(gotValue)

if validateErr == nil {
if test.CoercedValidateErr != "" {
t.Fatalf("validate succeeded; want error: %q", test.CoercedValidateErr)
}
} else {
if test.CoercedValidateErr == "" {
t.Fatal("unexpected error:", validateErr)
}
if !strings.Contains(validateErr.Error(), test.ValidateErr) {
t.Fatalf("wrong validate error\ngot: %s\nwant: %s", validateErr, test.ValidateErr)
}
if err := test.Schema.Validate(gotValue); err != nil {
t.Fatal("unexpected error:", validateErr)
}
}
})
Expand Down

0 comments on commit 5b56d40

Please sign in to comment.