-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple matchers #26
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ type Request struct { | |
Cookies []*http.Cookie | ||
|
||
// BodyBuffer stores the body data to match. | ||
BodyBuffer []byte | ||
BodyMatchers [][]byte | ||
|
||
// Mappers stores the request functions mappers used for matching. | ||
Mappers []MapRequestFunc | ||
|
@@ -125,19 +125,25 @@ func (r *Request) method(method, path string) *Request { | |
|
||
// Body defines the body data to match based on a io.Reader interface. | ||
func (r *Request) Body(body io.Reader) *Request { | ||
r.BodyBuffer, r.Error = ioutil.ReadAll(body) | ||
var bodyBuffer []byte | ||
bodyBuffer, r.Error = ioutil.ReadAll(body) | ||
r.BodyMatchers = append(r.BodyMatchers, bodyBuffer) | ||
return r | ||
} | ||
|
||
// BodyString defines the body to match based on a given string. | ||
func (r *Request) BodyString(body string) *Request { | ||
r.BodyBuffer = []byte(body) | ||
var bodyBuffer []byte | ||
bodyBuffer = []byte(body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the single-line DRYer version: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or even: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. Got a little too zealous with my copy/paste job :) |
||
r.BodyMatchers = append(r.BodyMatchers, bodyBuffer) | ||
return r | ||
} | ||
|
||
// File defines the body to match based on the given file path string. | ||
func (r *Request) File(path string) *Request { | ||
r.BodyBuffer, r.Error = ioutil.ReadFile(path) | ||
var bodyBuffer []byte | ||
bodyBuffer, r.Error = ioutil.ReadFile(path) | ||
r.BodyMatchers = append(r.BodyMatchers, bodyBuffer) | ||
return r | ||
} | ||
|
||
|
@@ -154,7 +160,10 @@ func (r *Request) JSON(data interface{}) *Request { | |
if r.Header.Get("Content-Type") == "" { | ||
r.Header.Set("Content-Type", "application/json") | ||
} | ||
r.BodyBuffer, r.Error = readAndDecode(data, "json") | ||
|
||
var bodyBuffer []byte | ||
bodyBuffer, r.Error = readAndDecode(data, "json") | ||
r.BodyMatchers = append(r.BodyMatchers, bodyBuffer) | ||
return r | ||
} | ||
|
||
|
@@ -163,7 +172,10 @@ func (r *Request) XML(data interface{}) *Request { | |
if r.Header.Get("Content-Type") == "" { | ||
r.Header.Set("Content-Type", "application/xml") | ||
} | ||
r.BodyBuffer, r.Error = readAndDecode(data, "xml") | ||
|
||
var bodyBuffer []byte | ||
bodyBuffer, r.Error = readAndDecode(data, "xml") | ||
r.BodyMatchers = append(r.BodyMatchers, bodyBuffer) | ||
return r | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct godoc:
// BodyBuffer
->// BodyMatchers