Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Stitt committed Sep 6, 2018
1 parent 6fda7e9 commit 87f6e3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/interpolation/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func TestInterpolationFuncJSONEncode(t *testing.T) {
text: `${jsonencode(list("foo", "bar"))}`,
expectation: `["foo","bar"]`,
},
{
description: "Advanced list encoding",
text: `${jsonencode(list(map("foo", "bar")))}`,
expectation: `[{"foo":"bar"}]`,
},
{
description: "Map encoding",
text: `${jsonencode(map("foo", "bar"))}`,
Expand Down
2 changes: 1 addition & 1 deletion internal/interpolation/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func testInterpolationFunc(funcMap keyFuncs) func(t *testing.T, testCase functio

if _, ok := testCase.expectation.(string); ok {
if actual.Value.(string) != testCase.expectation.(string) {
t.Fatalf("wrong result\ngiven %s\ngot: %#v\nwant: %#v", testCase.text, actual.Value, testCase.expectation)
t.Fatalf("wrong result\ngiven %s\ngot: %#v\nwant: %#v", testCase.text, actual.Value, testCase.expectation)
}
} else {
if !reflect.DeepEqual(actual.Value, testCase.expectation) {
Expand Down
18 changes: 16 additions & 2 deletions internal/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestTemplate_Render(t *testing.T) {
t.Fatalf("Unexpected err: %s", err)
}

result, err := tmpl.Render(`${has(var.foo, "bar")}`)
result, err := tmpl.Render(`${has(var.foo, "bar")} ${var.foo["bar"]}`)
if err != nil {
t.Fatalf("Unexpected err: %s", err)
}

if result.Value.(string) != "true" {
if result.Value.(string) != "true Bar" {
t.Fatalf("Unexpected result: Expected %s, got %s", "true", result.Value.(string))
}
})
Expand Down Expand Up @@ -83,4 +83,18 @@ func TestTemplate_Render(t *testing.T) {
t.Fatalf("Unexpected result: Expected %s, got %s", "foo", result.Value.(string))
}
})

t.Run("Test missing template", func(t *testing.T) {
tmpl, err := NewTemplate(&config.Result{
Variables: nil,
Templates: nil,
})
if err != nil {
t.Fatalf("Unexpected err: %s", err)
}
_, err = tmpl.Render(`${tmpl.foo}`)
if err == nil {
t.Fatal("unexpected nil err")
}
})
}

0 comments on commit 87f6e3f

Please # to comment.