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

Improvement: (optionally) print response body if assertion fails #31

Open
zak905 opened this issue Nov 3, 2023 · 0 comments
Open

Improvement: (optionally) print response body if assertion fails #31

zak905 opened this issue Nov 3, 2023 · 0 comments

Comments

@zak905
Copy link
Contributor

zak905 commented Nov 3, 2023

An issue that has been bothering me for a while is that when a status assertion (it can be other assertion as well) fails, the response is not printed. Most of the time (at the least in the case of Rest APIs), the response contains a hint about why the status assertion fails, and it makes it easy to debug when the response is printed. Currently, I need to add parse and print response code everytime I need it, and it gets more annoying when tests are running in the CI. I am aware of the plugin https://github.com/izumin5210/gentleman-logger, but with the plugin the response is printed in all cases (and also it seems very old and not maintained). Example:

func TestXxx(t *testing.T) {
	baloo.New("https://httpbin.org").Post("/anything").BodyString(`{"error":"db connection failed"}`).
		Expect(t).Status(500).Done()
}

The assertion error in this case is Unexpected status code for: POST https://httpbin.org/anything => 200 != 500

To be able to see the error, one has to add some boilerplate code:

func TestXxx(t *testing.T) {
	resp, _ := baloo.New("https://httpbin.org").Post("/anything").BodyString(`{"error":"db connection failed"}`).
		Expect(t).Status(500).Send()
	fmt.Println(resp.String())
}

It would be nice if this is provided out of the box, and only when the assertion fails.

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

No branches or pull requests

1 participant