Skip to content

Commit

Permalink
fixed warnings (unused parameters, invalid condition checks)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Hempel committed Jul 1, 2024
1 parent 14c21af commit b4c8a14
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
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 @@ -358,7 +358,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 @@ -370,7 +370,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 @@ -137,9 +137,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

0 comments on commit b4c8a14

Please sign in to comment.