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

Function TestParseTemplate

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

Source from the content-addressed store, hash-verified

30}
31
32func TestParseTemplate(t *testing.T) {
33 src := `{"greeting": "hello ${\"world\"}"}`
34 file, diags := Parse([]byte(src), "")
35 if len(diags) != 0 {
36 t.Errorf("got %d diagnostics on parse; want 0", len(diags))
37 for _, diag := range diags {
38 t.Logf("- %s", diag.Error())
39 }
40 }
41 if file == nil {
42 t.Fatalf("got nil File; want actual file")
43 }
44 if file.Body == nil {
45 t.Fatalf("got nil Body; want actual body")
46 }
47 attrs, diags := file.Body.JustAttributes()
48 if len(diags) != 0 {
49 t.Errorf("got %d diagnostics on decode; want 0", len(diags))
50 for _, diag := range diags {
51 t.Logf("- %s", diag.Error())
52 }
53 }
54
55 val, diags := attrs["greeting"].Expr.Value(&hcl.EvalContext{})
56 if len(diags) != 0 {
57 t.Errorf("got %d diagnostics on eval; want 0", len(diags))
58 for _, diag := range diags {
59 t.Logf("- %s", diag.Error())
60 }
61 }
62
63 if !val.RawEquals(cty.StringVal("hello world")) {
64 t.Errorf("wrong result %#v; want %#v", val, cty.StringVal("hello world"))
65 }
66}
67
68func TestParseTemplateUnwrap(t *testing.T) {
69 src := `{"greeting": "${true}"}`

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