(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func 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 | |
| 68 | func TestParseTemplateUnwrap(t *testing.T) { |
| 69 | src := `{"greeting": "${true}"}` |
nothing calls this directly
no test coverage detected