-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix some missing log informations and add VerifyJSON assert method #15
base: master
Are you sure you want to change the base?
Conversation
heralight
commented
Oct 15, 2017
- fix line source code stackstrace in error (check log.go)
- fix some compare data on error
- fix missing refill body in JSON unmarshall
- add VerifyJSON assert method (check JSON example) to have access json directly and test it
- add dump of response on error
- fix line source code stackstrace - fix some compare data on error - fix missing refill body in JSON unmarshall - add VerifyJSON assert method (check JSON example) to have access json directly and test it - add dump of response on error
assert/json.go
Outdated
@@ -109,3 +113,17 @@ func JSON(data interface{}) Func { | |||
return compare(body, data) | |||
} | |||
} | |||
|
|||
// VerifyJSON extract Json in body and call fn with result |
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.
Json
-> JSON
assert/json.go
Outdated
@@ -10,6 +10,9 @@ import ( | |||
"reflect" | |||
) | |||
|
|||
// convert types take an int and return a string value. | |||
type FnJsonVerify func(map[string]interface{}) error |
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.
JSON can be a slice
or map
. Enforcing it as map
structure would restrict its use cases. We should use interface{}
type here, and let developers to perform the type assertion it as needed.
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.
I see your point, I'm agree, but in this case data come from unmarshalBody which return a map[string]interface{} , we have 2 possibilities:
- Change unmarshalBody signature and usage
- Duplicate method
expect.go
Outdated
@@ -196,7 +203,10 @@ func (e *Expect) Done() error { | |||
// Run assertions | |||
err = e.run(res.RawResponse, res.RawRequest) | |||
if err != nil { | |||
e.test.Error(err) | |||
logerrorf(e.test, err.Error()) | |||
//e.test.Error(err) |
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.
Let's remove dead code.
_examples/assert_json/json_test.go
Outdated
Type("json"). | ||
JSON(`{"user-agent":"baloo/` + baloo.Version + `"}`). | ||
VerifyJSON(func(data map[string]interface{}) error { | ||
// check your json response here |
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.
We possibly want to run some assertion logic here.
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.
Do you mean a more complex sample ?
With something like "github.com/mitchellh/mapstructure"
err := mapstructure.Decode(data, destStruct)
?
Thanks for the PR. Please, take a look to my comments. |
You're welcome, I apply your proposals, there remains the 'map' problem and the example of the beginning to decide on your side. |
Add full example with mapstructure
I fix golint and add a full example. |
Hi, Any Update ? |
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.
Can you pull from master? We have released recently V3, which introduces breaking changes in the JSON assertion interface.
# Conflicts: # _examples/assert_json/json_test.go # assert/json.go
Upgraded to v3 and rename to OnJSON |
Thanks! Will take a look soon. |