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

Implement Decode method #192

Closed
gavv opened this issue Dec 5, 2022 · 4 comments · Fixed by #223
Closed

Implement Decode method #192

gavv opened this issue Dec 5, 2022 · 4 comments · Fixed by #223
Assignees
Labels
feature New feature or request help wanted Contributions are welcome
Milestone

Comments

@gavv
Copy link
Owner

gavv commented Dec 5, 2022

Currently almost every struct has Raw() method, that returns the underlying value.

It would be nice to add to each such struct a complementary Decode() method, that will json-decode underlying value into the argument.

Example:

var m map[string]interface{}

m = e.GET("/user").
	Expect().
	Status(http.StatusOK).
	JSON().
	Object().
	Raw()

Is same as:

var m map[string]interface{}

e.GET("/user").
	Expect().
	Status(http.StatusOK).
	JSON().
	Object().
	Decode(&m)

This method becomes useful when you want to use specific type for decoding, e.g. struct:

var user User

e.GET("/fruits/orange").
	Expect().
	Status(http.StatusOK).
	JSON().
	Object().
	Decode(&user)

BTW, this should give the same result:

var user User

e.GET("/fruits/orange").
	Expect().
	Status(http.StatusOK).
	JSON().
	Decode(&user)

If argument is nil, the method should report failure (AssertUsage). If decoding fails, the method should also report failure (AssertValid).

The new method should be documented and covered with unit tests. Also it should be covered in e2e test (e2e_basic_test.go).

Also we should add example to README.

@gavv gavv added feature New feature or request help wanted Contributions are welcome labels Dec 5, 2022
@Rohith-Raju
Copy link
Contributor

@gavv I'd like to give this a shot

@Rohith-Raju
Copy link
Contributor

Rohith-Raju commented Jan 1, 2023

Hey @gavv, I'll be getting back to this after Jan 5th cause of my exams

@gavv
Copy link
Owner Author

gavv commented Jan 1, 2023

Great, thanks, no hurry

@Rohith-Raju Rohith-Raju mentioned this issue Jan 6, 2023
6 tasks
@gavv gavv closed this as completed in #223 Jan 24, 2023
@gavv gavv reopened this Jan 24, 2023
@gavv
Copy link
Owner Author

gavv commented Jan 28, 2023

Landed.

@gavv gavv closed this as completed Jan 28, 2023
@gavv gavv added this to the v2 milestone Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Contributions are welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants