Skip to content

Commit

Permalink
Bump apitest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Stein Fletcher committed May 17, 2021
1 parent bc1a295 commit 49f06f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
18 changes: 4 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 12 additions & 13 deletions jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ import (
"fmt"
"net/http"
"strings"

"github.com/steinfletcher/apitest"
)

const (
jwtHeaderIndex = 0
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 {
Expand Down

0 comments on commit 49f06f7

Please sign in to comment.