Skip to content

Commit 35d8593

Browse files
authored
bugfix evaluating csv template string (#1125)
* bugfix evaluating csv template string * add unit tests
1 parent 16d621f commit 35d8593

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

core/templating/template_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func getEvaluationString(helperName string, options *raymond.Options) string {
327327

328328
evaluationString := "{{ " + helperName + " "
329329
for _, params := range options.Params() {
330-
evaluationString = evaluationString + params.(string) + ` `
330+
evaluationString = evaluationString + fmt.Sprint(params) + ` `
331331
}
332332
return evaluationString + "}}"
333333
}

core/templating/templating_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ func Test_ApplyTemplate_ParseCsvByPassingRequestParamAndReturnMatchValue(t *test
4949
Expect(template).To(Equal(`55`))
5050
}
5151

52+
func Test_ApplyTemplate_ParseCsv_WithMissingDataSource(t *testing.T) {
53+
RegisterTestingT(t)
54+
55+
template, err := ApplyTemplate(&models.RequestDetails{
56+
Query: map[string][]string{"Id": {"1"}},
57+
}, make(map[string]string), `{{csv 'test-csv3' 'Id' 55 'Marks'}}`)
58+
59+
Expect(err).To(BeNil())
60+
Expect(template).To(Equal(`{{ csv test-csv3 Id 55 Marks }}`))
61+
}
62+
63+
func Test_ApplyTemplate_ParseCsv_WithEachBlockAndMissingDataSource(t *testing.T) {
64+
RegisterTestingT(t)
65+
66+
template, err := ApplyTemplate(&models.RequestDetails{
67+
Body: `{"products": [1, 2]}`,
68+
}, make(map[string]string), `{{#each (Request.Body 'jsonpath' '$.products')}} {{@index}} : Product Name with productId {{this}} is {{csv 'products' 'productId' this 'productName'}} {{/each}}`)
69+
70+
Expect(err).To(BeNil())
71+
Expect(template).To(Equal(` 0 : Product Name with productId 1 is {{ csv products productId 1 productName }} 1 : Product Name with productId 2 is {{ csv products productId 2 productName }} `))
72+
}
73+
5274
func Test_ApplyTemplate_EachBlockWithSplitTemplatingFunction(t *testing.T) {
5375
RegisterTestingT(t)
5476

@@ -719,6 +741,7 @@ func ApplyTemplate(requestDetails *models.RequestDetails, state map[string]strin
719741
templator.TemplateHelper.TemplateDataSource.SetDataSource("test-csv1", dataSource1)
720742
templator.TemplateHelper.TemplateDataSource.SetDataSource("test-csv2", dataSource2)
721743

722-
template, _ := templator.ParseTemplate(responseBody)
744+
template, err := templator.ParseTemplate(responseBody)
745+
Expect(err).To(BeNil())
723746
return templator.RenderTemplate(template, requestDetails, &models.Literals{}, &models.Variables{}, state, &journal.Journal{})
724747
}

0 commit comments

Comments
 (0)