Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix templates with backticks 72324 #80

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (testCase Case) runAPITestCase(parentReportElem *report.ReportElement) (suc

// cheRckForBreak Response tests the given response for a so called break response.
// If this break response is present it returns a true
func (testCase Case) breakResponseIsPresent(request api.Request, response api.Response) (bool, error) {
func (testCase Case) breakResponseIsPresent(response api.Response) (bool, error) {

if testCase.BreakResponse != nil {
for _, v := range testCase.BreakResponse {
Expand Down Expand Up @@ -177,7 +177,7 @@ func (testCase Case) breakResponseIsPresent(request api.Request, response api.Re
// checkCollectResponse loops over all given collect responses and than
// If this continue response is present it returns a true.
// If no continue response is set, it also returns true to keep the testsuite running
func (testCase *Case) checkCollectResponse(request api.Request, response api.Response) (int, error) {
func (testCase *Case) checkCollectResponse(response api.Response) (int, error) {

if testCase.CollectResponse != nil {
_, loadedResponses, err := template.LoadManifestDataAsObject(testCase.CollectResponse, testCase.manifestDir, testCase.loader)
Expand Down Expand Up @@ -385,7 +385,7 @@ func (testCase Case) run() (successs bool, apiResponse api.Response, err error)
break
}

breakPresent, err := testCase.breakResponseIsPresent(request, apiResponse)
breakPresent, err := testCase.breakResponseIsPresent(apiResponse)
if err != nil {
testCase.LogReq(request)
testCase.LogResp(apiResponse)
Expand All @@ -398,7 +398,7 @@ func (testCase Case) run() (successs bool, apiResponse api.Response, err error)
return false, apiResponse, fmt.Errorf("Break response found")
}

collectLeft, err := testCase.checkCollectResponse(request, apiResponse)
collectLeft, err := testCase.checkCollectResponse(apiResponse)
if err != nil {
testCase.LogReq(request)
testCase.LogResp(apiResponse)
Expand Down
4 changes: 2 additions & 2 deletions pkg/lib/compare/comparison_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func objectComparison(left, right util.JsonObject, noExtra bool) (res CompareRes
}

// Check for the given key functions
err := keyChecks(k, rv, rOK, *control)
err := keyChecks(rv, rOK, *control)
if err != nil {
res.Failures = append(res.Failures, CompareFailure{Key: k, Message: err.Error()})
res.Equal = false
Expand Down Expand Up @@ -479,7 +479,7 @@ func ArrayEqualWithControl(left, right util.JsonArray, control ComparisonContext
return arrayComparison(left, right, control, nextControl)
}

func keyChecks(lk string, right any, rOK bool, control ComparisonContext) (err error) {
func keyChecks(right any, rOK bool, control ComparisonContext) (err error) {
if control.isString {
if right == nil {
return fmt.Errorf("== nil but should exist")
Expand Down
4 changes: 2 additions & 2 deletions pkg/lib/template/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func loadFileAndRender(rootDir string, loader *Loader) any {

// fileRender loads file from path and renders is as Go template passing
// the arguments as ".Param1", ".Param2" into the template.
func loadFile(rootDir string, loader *Loader) any {
func loadFile(rootDir string) any {
return func(path string, params ...any) (st string, err error) {
data, err := fileReadInternal(path, rootDir)
if err != nil {
Expand All @@ -369,7 +369,7 @@ func loadFile(rootDir string, loader *Loader) any {

// loadFileCSV reads file and parses it in the CSV map. A delimiter can
// be specified. Defaults to ','
func loadFileCSV(rootDir string, loader *Loader) any {
func loadFileCSV(rootDir string) any {
return func(path string, delimiters ...rune) (m []map[string]any, err error) {
var delimiter rune
switch len(delimiters) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/lib/template/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (loader *Loader) Render(
// }
// return data, err
// },
"file": loadFile(rootDir, loader),
"file": loadFile(rootDir),
"file_render": loadFileAndRender(rootDir, loader),
"file_csv": loadFileCSV(rootDir, loader),
"file_csv": loadFileCSV(rootDir),
"file_sqlite": func(path, statement string) ([]map[string]any, error) {
sqliteFile := filepath.Join(rootDir, path)
database, err := sql.Open("sqlite3", sqliteFile)
Expand Down
9 changes: 4 additions & 5 deletions pkg/lib/template/template_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,18 @@ int64,string,"stringer,array","int64,array"`, ``, true},
res, err := loader.Render(root, "", nil)

if err == nil {
if testCase.expectErr {
t.Errorf("Error expected")
}
if string(res) != testCase.expected {
dmp := diffmatchpatch.New()

diffs := dmp.DiffMain(string(res), testCase.expected, false)

t.Errorf("Result differs: %s", dmp.DiffPrettyText(diffs))

}
} else {
if testCase.expectErr && err == nil {
t.Errorf("Error expected")
}
if !testCase.expectErr && err != nil {
if !testCase.expectErr {
t.Errorf("No error expected %q", err)
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/response/preprocess/preprocess_file_exiftool_xml.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@
},
"xmlns:Composite": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/Composite/1.0/"
"match": "http://ns.exiftool.(org|ca)/Composite/1.0/"
}
},
"xmlns:ExifTool": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/ExifTool/1.0/"
"match": "http://ns.exiftool.(org|ca)/ExifTool/1.0/"
}
},
"xmlns:File": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/File/1.0/"
"match": "http://ns.exiftool.(org|ca)/File/1.0/"
}
},
"xmlns:ICC_Profile": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/ICC_Profile/ICC_Profile/1.0/"
"match": "http://ns.exiftool.(org|ca)/ICC_Profile/ICC_Profile/1.0/"
}
},
"xmlns:JFIF": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/JFIF/JFIF/1.0/"
"match": "http://ns.exiftool.(org|ca)/JFIF/JFIF/1.0/"
}
},
"xmlns:et": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/1.0/"
"match": "http://ns.exiftool.(org|ca)/1.0/"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@
},
"xmlns:Composite": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/Composite/1.0/"
"match": "http://ns.exiftool.(org|ca)/Composite/1.0/"
}
},
"xmlns:ExifTool": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/ExifTool/1.0/"
"match": "http://ns.exiftool.(org|ca)/ExifTool/1.0/"
}
},
"xmlns:File": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/File/1.0/"
"match": "http://ns.exiftool.(org|ca)/File/1.0/"
}
},
"xmlns:ICC_Profile": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/ICC_Profile/ICC_Profile/1.0/"
"match": "http://ns.exiftool.(org|ca)/ICC_Profile/ICC_Profile/1.0/"
}
},
"xmlns:JFIF": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/JFIF/JFIF/1.0/"
"match": "http://ns.exiftool.(org|ca)/JFIF/JFIF/1.0/"
}
},
"xmlns:et": {
"#text:control": {
"regex": "http://ns.exiftool.(org|ca)/1.0/"
"match": "http://ns.exiftool.(org|ca)/1.0/"
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions test/semver/test_semver_compare.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
"body": {
"body": {
"semver_easydb_release:control": {
"is_integer": true
"is_number": true
},
"semver_easydb_release": -1,

"semver_easydb_patch:control": {
"is_integer": true
"is_number": true
},
"semver_easydb_patch": -1,

"semver_lt:control": {
"is_integer": true
"is_number": true
},
"semver_lt": -1,

"semver_eq:control": {
"is_integer": true
"is_number": true
},
"semver_eq": 0,

"semver_gt:control": {
"is_integer": true
"is_number": true
},
"semver_gt": 1,

"semver_eq2:control": {
"is_integer": true
"is_number": true
},
"semver_eq2": 0
}
Expand Down
14 changes: 11 additions & 3 deletions test/template/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
"dir": "../_res",
"testmode": false
},
"store": {
"test_int": 123,
"test_text": "lorem ipsum",
"server_endpoint": "bounce-json"
},
"name": "template tests",
"tests": [
/* printf "%s" "@test1.json" | marshal */"<placeholder>",
"@test2.json"
],
/* printf "%s" "@test1.json" | marshal */"<placeholder>"
,"@test2.json"
,"@test3.json"
,"@test4.json"
,"@test5.json"
]
}
22 changes: 22 additions & 0 deletions test/template/test3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// template-delims: {{ }}
{
"name": "delimiter in templates in request endpoint and body: \"",
"request": {
"server_url": "http://localhost:9999",
"endpoint": "{{ datastore "server_endpoint" }}",
"method": "POST",
"body": {
"num": "integer from datastore: {{ datastore "test_int" }}",
"text": "string from datastore: {{ datastore "test_text" }}"
}
},
"response": {
"statuscode": 200,
"body": {
"body": {
"num": "integer from datastore: 123",
"text": "string from datastore: lorem ipsum"
}
}
}
}
22 changes: 22 additions & 0 deletions test/template/test4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// template-delims: {{ }}
{
"name": "delimiter in templates in request endpoint and body: `",
"request": {
"server_url": "http://localhost:9999",
"endpoint": "{{ datastore `server_endpoint` }}",
"method": "POST",
"body": {
"num": "integer from datastore: {{ datastore `test_int` }}",
"text": "string from datastore: {{ datastore `test_text` }}"
}
},
"response": {
"statuscode": 200,
"body": {
"body": {
"num": "integer from datastore: 123",
"text": "string from datastore: lorem ipsum"
}
}
}
}
24 changes: 24 additions & 0 deletions test/template/test5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// template-delims: {{ }}
[
{
"name": "delimiter in templates in request endpoint and body: `",
"request": {
"server_url": "http://localhost:9999",
"endpoint": "{{ datastore `server_endpoint` }}",
"method": "POST",
"body": {
"num": "integer from datastore: {{ datastore `test_int` }}",
"text": "string from datastore: {{ datastore `test_text` }}"
}
},
"response": {
"statuscode": 200,
"body": {
"body": {
"num": "integer from datastore: 123",
"text": "string from datastore: lorem ipsum"
}
}
}
}
]
Loading