MCPcopy
hub / github.com/opentofu/opentofu / TestFixUpBlockAttrs

Function TestFixUpBlockAttrs

internal/lang/blocktoattr/fixup_test.go:20–526  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func 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: `
67foo = [
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"),

Callers

nothing calls this directly

Calls 8

HasErrorsMethod · 0.95
FixUpBlockAttrsFunction · 0.85
ObjectMethod · 0.80
DecoderSpecMethod · 0.80
RunMethod · 0.65
ListMethod · 0.45
ParseMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected