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

Function TestDeep

ext/transform/transform_test.go:19–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17var _ hcl.Body = deepWrapper{}
18
19func TestDeep(t *testing.T) {
20
21 testTransform := TransformerFunc(func(body hcl.Body) hcl.Body {
22 _, remain, diags := body.PartialContent(&hcl.BodySchema{
23 Blocks: []hcl.BlockHeaderSchema{
24 {
25 Type: "remove",
26 },
27 },
28 })
29
30 return BodyWithDiagnostics(remain, diags)
31 })
32
33 src := hcltest.MockBody(&hcl.BodyContent{
34 Attributes: hcltest.MockAttrs(map[string]hcl.Expression{
35 "true": hcltest.MockExprLiteral(cty.True),
36 }),
37 Blocks: []*hcl.Block{
38 {
39 Type: "remove",
40 Body: hcl.EmptyBody(),
41 },
42 {
43 Type: "child",
44 Body: hcltest.MockBody(&hcl.BodyContent{
45 Blocks: []*hcl.Block{
46 {
47 Type: "remove",
48 },
49 },
50 }),
51 },
52 },
53 })
54
55 wrapped := Deep(src, testTransform)
56
57 rootContent, diags := wrapped.Content(&hcl.BodySchema{
58 Attributes: []hcl.AttributeSchema{
59 {
60 Name: "true",
61 },
62 },
63 Blocks: []hcl.BlockHeaderSchema{
64 {
65 Type: "child",
66 },
67 },
68 })
69 if len(diags) != 0 {
70 t.Errorf("unexpected diagnostics for root content")
71 for _, diag := range diags {
72 t.Logf("- %s", diag)
73 }
74 }
75
76 wantAttrs := hcltest.MockAttrs(map[string]hcl.Expression{

Callers

nothing calls this directly

Calls 8

MockBodyFunction · 0.92
MockAttrsFunction · 0.92
MockExprLiteralFunction · 0.92
TransformerFuncFuncType · 0.85
BodyWithDiagnosticsFunction · 0.85
DeepFunction · 0.85
PartialContentMethod · 0.65
ContentMethod · 0.65

Tested by

no test coverage detected