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

Function TestParseTemplateUnwrap

json/public_test.go:68–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestParseTemplateUnwrap(t *testing.T) {
69 src := `{"greeting": "${true}"}`
70 file, diags := Parse([]byte(src), "")
71 if len(diags) != 0 {
72 t.Errorf("got %d diagnostics on parse; want 0", len(diags))
73 for _, diag := range diags {
74 t.Logf("- %s", diag.Error())
75 }
76 }
77 if file == nil {
78 t.Fatalf("got nil File; want actual file")
79 }
80 if file.Body == nil {
81 t.Fatalf("got nil Body; want actual body")
82 }
83 attrs, diags := file.Body.JustAttributes()
84 if len(diags) != 0 {
85 t.Errorf("got %d diagnostics on decode; want 0", len(diags))
86 for _, diag := range diags {
87 t.Logf("- %s", diag.Error())
88 }
89 }
90
91 val, diags := attrs["greeting"].Expr.Value(&hcl.EvalContext{})
92 if len(diags) != 0 {
93 t.Errorf("got %d diagnostics on eval; want 0", len(diags))
94 for _, diag := range diags {
95 t.Logf("- %s", diag.Error())
96 }
97 }
98
99 if !val.RawEquals(cty.True) {
100 t.Errorf("wrong result %#v; want %#v", val, cty.True)
101 }
102}
103
104func TestParse_malformed(t *testing.T) {
105 src := `{

Callers

nothing calls this directly

Calls 4

ParseFunction · 0.85
JustAttributesMethod · 0.65
ValueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected