(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestFixUpBlockAttrs(t *testing.T) { |
| 21 | fooSchema := &configschema.Block{ |
| 22 | Attributes: map[string]*configschema.Attribute{ |
| 23 | "foo": { |
| 24 | Type: cty.List(cty.Object(map[string]cty.Type{ |
| 25 | "bar": cty.String, |
| 26 | })), |
| 27 | Optional: true, |
| 28 | }, |
| 29 | }, |
| 30 | } |
| 31 | |
| 32 | tests := map[string]struct { |
| 33 | src string |
| 34 | json bool |
| 35 | schema *configschema.Block |
| 36 | want cty.Value |
| 37 | wantErrs bool |
| 38 | }{ |
| 39 | "empty": { |
| 40 | src: ``, |
| 41 | schema: &configschema.Block{}, |
| 42 | want: cty.EmptyObjectVal, |
| 43 | }, |
| 44 | "empty JSON": { |
| 45 | src: `{}`, |
| 46 | json: true, |
| 47 | schema: &configschema.Block{}, |
| 48 | want: cty.EmptyObjectVal, |
| 49 | }, |
| 50 | "unset": { |
| 51 | src: ``, |
| 52 | schema: fooSchema, |
| 53 | want: cty.ObjectVal(map[string]cty.Value{ |
| 54 | "foo": cty.NullVal(fooSchema.Attributes["foo"].Type), |
| 55 | }), |
| 56 | }, |
| 57 | "unset JSON": { |
| 58 | src: `{}`, |
| 59 | json: true, |
| 60 | schema: fooSchema, |
| 61 | want: cty.ObjectVal(map[string]cty.Value{ |
| 62 | "foo": cty.NullVal(fooSchema.Attributes["foo"].Type), |
| 63 | }), |
| 64 | }, |
| 65 | "no fixup required, with one value": { |
| 66 | src: ` |
| 67 | foo = [ |
| 68 | { |
| 69 | bar = "baz" |
| 70 | }, |
| 71 | ] |
| 72 | `, |
| 73 | schema: fooSchema, |
| 74 | want: cty.ObjectVal(map[string]cty.Value{ |
| 75 | "foo": cty.ListVal([]cty.Value{ |
| 76 | cty.ObjectVal(map[string]cty.Value{ |
| 77 | "bar": cty.StringVal("baz"), |
nothing calls this directly
no test coverage detected