Skip to content

Commit

Permalink
Merge pull request #6 from armosec/middleware
Browse files Browse the repository at this point in the history
cmpopts
  • Loading branch information
avrahams authored Aug 29, 2023
2 parents 38dabab + a22cea9 commit 883d0ab
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/armosec/ca-test/utils"
"github.com/google/go-cmp/cmp"
)

type RequestHandler func(w http.ResponseWriter, r *http.Request, reqBody string)
Expand Down Expand Up @@ -112,7 +113,7 @@ var WithTestRequest = func(t *testing.T, updateExpected bool, expectedRequest []
}
}

var WithTestRequestV1 = func(t *testing.T, updateExpected bool, expectedRequest []byte, expectedRequestFile string) RequestHandlerOption {
var WithTestRequestV1 = func(t *testing.T, updateExpected bool, expectedRequest []byte, expectedRequestFile string, compareOptions ...cmp.Option) RequestHandlerOption {
return func(o *requestHandlerOptions) error {
if expectedRequest == nil || t == nil {
return fmt.Errorf("test, expected request must be provided")
Expand All @@ -125,6 +126,7 @@ var WithTestRequestV1 = func(t *testing.T, updateExpected bool, expectedRequest
o.updateExpected = updateExpected
o.expectedRequest = expectedRequest
o.expectedRequestFile = expectedRequestFile
o.requestCompareOptions = compareOptions
return nil
}
}
Expand All @@ -135,6 +137,7 @@ type requestHandlerOptions struct {
response []byte
responses [][]byte
expectedRequest []byte
requestCompareOptions []cmp.Option
expectedRequestFile string
updateExpected bool
reqNum int
Expand Down Expand Up @@ -162,7 +165,7 @@ func (o *requestHandlerOptions) getOrCreateHandler() RequestHandler {
if o.deprecatedTestResponse && len(o.expectedRequest) != 0 {
utils.DeepEqualOrUpdate(o.t, []byte(reqBody), o.expectedRequest, o.expectedRequestFile, o.updateExpected)
} else if len(o.expectedRequest) != 0 {
utils.CompareAndUpdate(o.t, []byte(reqBody), o.expectedRequest, o.expectedRequestFile, o.updateExpected)
utils.CompareAndUpdate(o.t, []byte(reqBody), o.expectedRequest, o.expectedRequestFile, o.updateExpected, o.requestCompareOptions...)
}
if len(o.response) != 0 {
w.Write(o.response)
Expand Down

0 comments on commit 883d0ab

Please sign in to comment.