-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
For cases like: - Parameters, such as `application/json; charset=utf-8` - Vendors, like `application/vnd.foo.bar.v2+json`
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.
👋 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 { |
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.
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 { |
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.
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 { |
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.
Same as above
assert_test.go
Outdated
@@ -0,0 +1,31 @@ | |||
package abide | |||
|
|||
import "testing" |
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.
import (
"testing"
)
assert_test.go
Outdated
|
||
import "testing" | ||
|
||
var contentTypeTestCases = []struct { |
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.
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 { | ||
|
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.
Remove newline please
LGTM! Thanks @meydjer |
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. |
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.