Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

heralight
Copy link

  • 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
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Author

@heralight heralight Oct 15, 2017

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)
Copy link
Owner

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.

Type("json").
JSON(`{"user-agent":"baloo/` + baloo.Version + `"}`).
VerifyJSON(func(data map[string]interface{}) error {
// check your json response here
Copy link
Owner

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.

Copy link
Author

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)
?

@h2non
Copy link
Owner

h2non commented Oct 15, 2017

Thanks for the PR. Please, take a look to my comments.

@heralight
Copy link
Author

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
@heralight
Copy link
Author

heralight commented Oct 16, 2017

I fix golint and add a full example.
About Map / array, adding another assert could be a solution...

@coveralls
Copy link

coveralls commented Oct 16, 2017

Coverage Status

Coverage decreased (-16.7%) to 70.426% when pulling 4129a1b on heralight:master into ea5c148 on h2non:master.

@coveralls
Copy link

coveralls commented Oct 24, 2017

Coverage Status

Coverage decreased (-16.7%) to 70.426% when pulling 6514fb9 on heralight:master into ea5c148 on h2non:master.

@heralight
Copy link
Author

Hi, Any Update ?

Copy link
Owner

@h2non h2non left a 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.

@heralight
Copy link
Author

Upgraded to v3 and rename to OnJSON
add sample and unit test and modify readme...

@coveralls
Copy link

coveralls commented Nov 9, 2017

Coverage Status

Coverage decreased (-16.7%) to 70.426% when pulling 61a33f2 on heralight:master into bcac7e0 on h2non:master.

@h2non
Copy link
Owner

h2non commented Nov 9, 2017

Thanks! Will take a look soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants