Skip to content

Commit

Permalink
body:control: fixed with no "body" check
Browse files Browse the repository at this point in the history
If no "body" was given for the response, "body:control" would not work..
  • Loading branch information
martinrode committed Nov 24, 2022
1 parent 7c088c0 commit bea85b4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion api_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ func (testCase Case) responsesEqual(expected, got api.Response) (compare.Compare
if err != nil {
return compare.CompareResult{}, fmt.Errorf("error loading expected generic json: %s", err)
}
if len(expected.Body) < 1 {
if len(expected.Body) == 0 && len(expected.BodyControl) == 0 {
expected.Format.IgnoreBody = true
} else {
expected.Format.IgnoreBody = false
}
gotJSON, err := got.ServerResponseToGenericJSON(expected.Format, false)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/lib/api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Response struct {
headerControl util.JsonObject
Cookies []*http.Cookie
Body []byte
bodyControl util.JsonObject
BodyControl util.JsonObject
Format ResponseFormat

ReqDur time.Duration
Expand All @@ -36,7 +36,7 @@ func (res Response) NeedsCheck() bool {
if res.StatusCode != http.StatusOK {
return true
}
if len(res.Headers) > 0 || len(res.Cookies) > 0 || len(res.Body) > 0 {
if len(res.Headers) > 0 || len(res.Cookies) > 0 || len(res.Body) > 0 || len(res.BodyControl) > 0 {
return true
}
return false
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewResponse(statusCode int, headers map[string]any, headerControl util.Json
StatusCode: statusCode,
Headers: headers,
Cookies: cookies,
bodyControl: bodyControl,
BodyControl: bodyControl,
headerControl: headerControl,
Format: bodyFormat,
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func (response Response) ToGenericJSON() (interface{}, error) {
}
responseJSON := ResponseSerialization{
StatusCode: response.StatusCode,
BodyControl: response.bodyControl,
BodyControl: response.BodyControl,
Headers: headers,
HeaderControl: response.headerControl,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/compare/comparison_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func getJsonType(value interface{}) string {
case util.JsonBool:
return "Bool"
default:
return "No JSON Type"
return "No JSON Type: " + fmt.Sprintf("%v", value)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
)

//Get information
// Get information
type info struct {
name string
format string
Expand Down
6 changes: 3 additions & 3 deletions pkg/lib/report/parsing_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func (groups statsGroups) getLowestRuntimeGroup() (group int) {
return
}

//ParseJSONResult Print the result to the console
// ParseJSONResult Print the result to the console
func ParseJSONResult(baseResult *ReportElement) []byte {
jsonResult, _ := json.MarshalIndent(baseResult, "", " ")

return jsonResult
}

//ParseJSONResult Print the result to the console
// ParseJSONResult Print the result to the console
func ParseJSONStatsResult(baseResult *ReportElement) []byte {

currUsername := "unknown"
Expand Down Expand Up @@ -149,7 +149,7 @@ func ParseJSONStatsResult(baseResult *ReportElement) []byte {
return jsonResult
}

//ParseJUnitResult Print the result to the console
// ParseJUnitResult Print the result to the console
func ParseJUnitResult(baseResult *ReportElement) []byte {

testName := time.Now().Format("2006-01-02 15:04")
Expand Down

0 comments on commit bea85b4

Please sign in to comment.