From 49f06f7db6dd3cb82d0ec8fbe048179d57ad37e9 Mon Sep 17 00:00:00 2001 From: Stein Fletcher Date: Mon, 17 May 2021 07:35:38 +0100 Subject: [PATCH] Bump apitest version --- go.mod | 2 +- go.sum | 18 ++++-------------- jsonpath.go | 25 ++++++++++++------------- jwt.go | 8 +++----- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 2f203ba..494bccd 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.13 require ( github.com/PaesslerAG/jsonpath v0.1.1 - github.com/steinfletcher/apitest v1.5.3 + github.com/steinfletcher/apitest v1.5.10 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index fc39045..28bc60e 100644 --- a/go.sum +++ b/go.sum @@ -6,25 +6,15 @@ github.com/PaesslerAG/jsonpath v0.1.1 h1:c1/AToHQMVsduPAa4Vh6xp2U0evy4t8SWp8imEs github.com/PaesslerAG/jsonpath v0.1.1/go.mod h1:lVboNxFGal/VwW6d9JzIy56bUsYAP6tH/x80vjnCseY= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/steinfletcher/apitest v1.4.8 h1:9SDVm1MCv6FRCd8xuGgoZA0TCsunN0TrXBon+ZL86wE= -github.com/steinfletcher/apitest v1.4.8/go.mod h1:3nIZfM9GDQWGP9UGx6Zxk+LXc0DZFcZvy6+LfdhZa6U= -github.com/steinfletcher/apitest v1.4.9 h1:8X7G+1m+GngIo5LFfDM0CxLSG9jcJn9LLeDH/Ov144M= -github.com/steinfletcher/apitest v1.4.9/go.mod h1:0MT98QwexQVvf5pIn3fqiC/+8Nyd7A4RShxuSjnpOcE= -github.com/steinfletcher/apitest v1.4.10 h1:uQ79AiO3U1hIM829m8p7ke0NsybrBaTLzv23gsHqjzQ= -github.com/steinfletcher/apitest v1.4.10/go.mod h1:0MT98QwexQVvf5pIn3fqiC/+8Nyd7A4RShxuSjnpOcE= -github.com/steinfletcher/apitest v1.4.11 h1:OsMXiVeIJs5kW5+SvF5fXJuQ4DQqgrDmcQxs4R4gZyg= -github.com/steinfletcher/apitest v1.4.11/go.mod h1:0MT98QwexQVvf5pIn3fqiC/+8Nyd7A4RShxuSjnpOcE= -github.com/steinfletcher/apitest v1.4.15/go.mod h1:0MT98QwexQVvf5pIn3fqiC/+8Nyd7A4RShxuSjnpOcE= -github.com/steinfletcher/apitest v1.5.3/go.mod h1:TrZemFOZ1yNgKoAeAsth3Z3vEavTloE1hP/U2PSd3w0= +github.com/steinfletcher/apitest v1.5.10 h1:uxEm/boegmZI9csm1fLVywB5b07ijcrcHo3PZO6sfns= +github.com/steinfletcher/apitest v1.5.10/go.mod h1:cf7Bneo52IIAgpqhP8xaLlzWgAiQ9fHtsDMjeDnZ3so= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho= -github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/jsonpath.go b/jsonpath.go index ceb8271..858946e 100644 --- a/jsonpath.go +++ b/jsonpath.go @@ -14,11 +14,10 @@ import ( "strings" "github.com/PaesslerAG/jsonpath" - "github.com/steinfletcher/apitest" ) // Contains is a convenience function to assert that a jsonpath expression extracts a value in an array -func Contains(expression string, expected interface{}) apitest.Assert { +func Contains(expression string, expected interface{}) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -37,7 +36,7 @@ func Contains(expression string, expected interface{}) apitest.Assert { } // Equal is a convenience function to assert that a jsonpath expression extracts a value -func Equal(expression string, expected interface{}) apitest.Assert { +func Equal(expression string, expected interface{}) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -52,7 +51,7 @@ func Equal(expression string, expected interface{}) apitest.Assert { } // NotEqual is a function to check json path expression value is not equal to given value -func NotEqual(expression string, expected interface{}) apitest.Assert { +func NotEqual(expression string, expected interface{}) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -67,7 +66,7 @@ func NotEqual(expression string, expected interface{}) apitest.Assert { } // Len asserts that value is the expected length, determined by reflect.Len -func Len(expression string, expectedLength int) apitest.Assert { +func Len(expression string, expectedLength int) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -83,7 +82,7 @@ func Len(expression string, expectedLength int) apitest.Assert { } // GreaterThan asserts that value is greater than the given length, determined by reflect.Len -func GreaterThan(expression string, minimumLength int) apitest.Assert { +func GreaterThan(expression string, minimumLength int) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -99,7 +98,7 @@ func GreaterThan(expression string, minimumLength int) apitest.Assert { } // LessThan asserts that value is less than the given length, determined by reflect.Len -func LessThan(expression string, maximumLength int) apitest.Assert { +func LessThan(expression string, maximumLength int) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, err := jsonPath(res.Body, expression) if err != nil { @@ -115,7 +114,7 @@ func LessThan(expression string, maximumLength int) apitest.Assert { } // Present asserts that value returned by the expression is present -func Present(expression string) apitest.Assert { +func Present(expression string) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, _ := jsonPath(res.Body, expression) if isEmpty(value) { @@ -126,7 +125,7 @@ func Present(expression string) apitest.Assert { } // NotPresent asserts that value returned by the expression is not present -func NotPresent(expression string) apitest.Assert { +func NotPresent(expression string) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { value, _ := jsonPath(res.Body, expression) if !isEmpty(value) { @@ -137,7 +136,7 @@ func NotPresent(expression string) apitest.Assert { } // Matches asserts that the value matches the given regular expression -func Matches(expression string, regexp string) apitest.Assert { +func Matches(expression string, regexp string) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { pattern, err := regex.Compile(regexp) if err != nil { @@ -187,7 +186,7 @@ func Root(expression string) *AssertionChain { // AssertionChain supports chaining assertions and root expressions type AssertionChain struct { rootExpression string - assertions []apitest.Assert + assertions []func(*http.Response, *http.Request) error } // Equal adds an Equal assertion to the chain @@ -226,8 +225,8 @@ func (r *AssertionChain) Matches(expression, regexp string) *AssertionChain { return r } -// End returns an apitest.Assert which is a combination of the registered assertions -func (r *AssertionChain) End() apitest.Assert { +// End returns an func(*http.Response, *http.Request) error which is a combination of the registered assertions +func (r *AssertionChain) End() func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { for _, assertion := range r.assertions { if err := assertion(copyHttpResponse(res), copyHttpRequest(req)); err != nil { diff --git a/jwt.go b/jwt.go index 303f9a0..fc92d35 100644 --- a/jwt.go +++ b/jwt.go @@ -7,8 +7,6 @@ import ( "fmt" "net/http" "strings" - - "github.com/steinfletcher/apitest" ) const ( @@ -16,15 +14,15 @@ const ( jwtPayloadIndex = 1 ) -func JWTHeaderEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}) apitest.Assert { +func JWTHeaderEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}) func(*http.Response, *http.Request) error { return jwtEqual(tokenSelector, expression, expected, jwtHeaderIndex) } -func JWTPayloadEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}) apitest.Assert { +func JWTPayloadEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}) func(*http.Response, *http.Request) error { return jwtEqual(tokenSelector, expression, expected, jwtPayloadIndex) } -func jwtEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}, index int) apitest.Assert { +func jwtEqual(tokenSelector func(*http.Response) (string, error), expression string, expected interface{}, index int) func(*http.Response, *http.Request) error { return func(response *http.Response, request *http.Request) error { token, err := tokenSelector(response) if err != nil {