Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Fujii committed Sep 28, 2021
1 parent bae6051 commit f3b6b46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runner/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newCallData(
fns[k] = v
}

for k, v := range sprig.TxtFuncMap() {
for k, v := range sprig.FuncMap() {
fns[k] = v
}

Expand Down
14 changes: 14 additions & 0 deletions runner/calldata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,18 @@ func TestCallTemplateData_ExecuteFuncs(t *testing.T) {
assert.Equal(t, "custom-uuid", rm["trace_id"])
assert.Equal(t, "custom-sku", rm["sku"])
})

t.Run("sprig functions", func(t *testing.T) {

ctd := newCallData(md, nil, "worker_id_123", 200)
assert.NotNil(t, ctd)

r, err := ctd.ExecuteData(`{"trace_id":"{{add 1 2}}"}`)
assert.NoError(t, err)
assert.Equal(t, `{"trace_id":"3"}`, string(r))

r, err = ctd.ExecuteData(`{"trace_id":"{{"abc" | upper | repeat 3 }}"}`)
assert.NoError(t, err)
assert.Equal(t, `{"trace_id":"ABCABCABC"}`, string(r))
})
}
4 changes: 2 additions & 2 deletions runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestRunUnary(t *testing.T) {
gs.ResetCounters()

data := make(map[string]interface{})
data["name"] = "{{ add 1 2 }}"
data["name"] = "{{ `test` | upper | repeat 5 }}"

report, err := Run(
"helloworld.Greeter.SayHello",
Expand All @@ -140,7 +140,7 @@ func TestRunUnary(t *testing.T) {
assert.Len(t, calls, 1)

msg := calls[0][0]
assert.Equal(t, msg.GetName(), "3")
assert.Equal(t, msg.GetName(), "TESTTESTTESTTESTTEST")
})

t.Run("test custom template functions", func(t *testing.T) {
Expand Down

0 comments on commit f3b6b46

Please sign in to comment.