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

Better snapshot output and JSON content-type verification #32

Merged
merged 4 commits into from
Mar 14, 2018

Conversation

meydjer
Copy link
Contributor

@meydjer meydjer commented Mar 7, 2018

When you have a lot of snapshots with similar outputs is a little bit hard to differentiate them.

This commit improves readability by adding the snapshot ID to the output.

meydjer added 3 commits March 7, 2018 17:11
For cases like:
- Parameters, such as `application/json; charset=utf-8`
- Vendors, like `application/vnd.foo.bar.v2+json`
@meydjer meydjer changed the title Improve new/existing snapshot output Better snapshot output and JSON content-type verification Mar 8, 2018
Copy link
Collaborator

@sjkaliski sjkaliski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hey! Thank you so much for adding this, and sorry for taking a few days, was offline for a bit. Just a few comments, otherwise LGTM!

Also, would love to hear more about how you're using the package and any other features/improvements you'd like to see!

assert.go Outdated
@@ -132,16 +154,18 @@ func compareResults(t *testing.T, existing, new string) string {
return dmp.DiffPrettyText(allDiffs)
}

func didNotMatchMessage(diff string) string {
msg := "\n\nExisting snapshot does not match results...\n\n"
func didNotMatchMessage(id string, diff string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since id and diff are both strings, let's collapse the function signature.

func didNotMatchMessage(id, diff string) string {

assert.go Outdated

isJSON := strings.HasSuffix(firstPart, "+json")

if isVendor && isJSON {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return isVendor && isJSON

assert.go Outdated
msg += diff
msg += "\n\n"
msg += "If this change was intentional, run tests again, $ go test -v -- -u\n"
return msg
}

func newSnapshotMessage(body string) string {
msg := "\n\nNew snapshot found...\n\n"
func newSnapshotMessage(id string, body string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

assert_test.go Outdated
@@ -0,0 +1,31 @@
package abide

import "testing"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import (
  "testing"
)

assert_test.go Outdated

import "testing"

var contentTypeTestCases = []struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since only this test would use this particular set of cases (e.g. different set if we had contentTypeIsXML), let's move this directly into TestContentTypeIsJSON. It may also be easier to use map[string]bool as well.

assert_test.go Outdated

func TestContentTypeIsJSON(test *testing.T) {
for _, testCase := range contentTypeTestCases {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline please

@sjkaliski
Copy link
Collaborator

LGTM! Thanks @meydjer

@sjkaliski sjkaliski merged commit d831b87 into beme:master Mar 14, 2018
@meydjer
Copy link
Contributor Author

meydjer commented Mar 14, 2018

You are welcome @sjkaliski, it's a great package.

I'm using it to test JSON outputs for an API i'm building with Gin Gonic.

I just started using it so I don't have much feedback yet (apart from this Pull Request). But I will keep in touch with you.

Thanks for your time and for sharing this tool with us.

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

Successfully merging this pull request may close these issues.

2 participants