(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func 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 | |
| 104 | func TestParse_malformed(t *testing.T) { |
| 105 | src := `{ |
nothing calls this directly
no test coverage detected