MCPcopy
hub / github.com/hashicorp/hcl / TestDecodeBody

Function TestDecodeBody

gohcl/decode_test.go:19–780  ·  gohcl/decode_test.go::TestDecodeBody
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestDecodeBody(t *testing.T) {
20 deepEquals := func(other interface{}) func(v interface{}) bool {
21 return func(v interface{}) bool {
22 return reflect.DeepEqual(v, other)
23 }
24 }
25
26 type withNameExpression struct {
27 Name hcl.Expression `hcl:"name"`
28 }
29
30 type withTwoAttributes struct {
31 A string `hcl:"a,optional"`
32 B string `hcl:"b,optional"`
33 }
34
35 type withNestedBlock struct {
36 Plain string `hcl:"plain,optional"`
37 Nested *withTwoAttributes `hcl:"nested,block"`
38 }
39
40 type withListofNestedBlocks struct {
41 Nested []*withTwoAttributes `hcl:"nested,block"`
42 }
43
44 type withListofNestedBlocksNoPointers struct {
45 Nested []withTwoAttributes `hcl:"nested,block"`
46 }
47
48 tests := []struct {
49 Body map[string]interface{}
50 Target func() interface{}
51 Check func(v interface{}) bool
52 DiagCount int
53 }{
54 {
55 map[string]interface{}{},
56 makeInstantiateType(struct{}{}),
57 deepEquals(struct{}{}),
58 0,
59 },
60 {
61 map[string]interface{}{},
62 makeInstantiateType(struct {
63 Name string `hcl:"name"`
64 }{}),
65 deepEquals(struct {
66 Name string `hcl:"name"`
67 }{}),
68 1, // name is required
69 },
70 {
71 map[string]interface{}{},
72 makeInstantiateType(struct {
73 Name *string `hcl:"name"`
74 }{}),
75 deepEquals(struct {
76 Name *string `hcl:"name"`

Callers

nothing calls this directly

Calls 7

makeInstantiateTypeFunction · 0.85
makeRangeFunction · 0.85
DecodeBodyFunction · 0.85
RunMethod · 0.80
ValueMethod · 0.65
JustAttributesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected