@@ -39,8 +39,10 @@ func AssertHTTPResponse(t *testing.T, id string, w *http.Response) {
3939
4040 data := string (body )
4141
42+ contentType := w .Header .Get ("Content-Type" )
43+
4244 // If the response body is JSON, indent.
43- if w . Header . Get ( "Content-Type" ) == "application/json" {
45+ if contentTypeIsJSON ( contentType ) {
4446 lines := strings .Split (data , "\n " )
4547 jsonStr := lines [len (lines )- 1 ]
4648
@@ -68,6 +70,22 @@ func AssertHTTPResponse(t *testing.T, id string, w *http.Response) {
6870 createOrUpdateSnapshot (t , id , data )
6971}
7072
73+ func contentTypeIsJSON (contentType string ) bool {
74+ contentTypeParts := strings .Split (contentType , ";" )
75+ firstPart := contentTypeParts [0 ]
76+
77+ isPlainJSON := firstPart == "application/json"
78+ if isPlainJSON {
79+ return isPlainJSON
80+ }
81+
82+ isVendor := strings .HasPrefix (firstPart , "application/vnd." )
83+
84+ isJSON := strings .HasSuffix (firstPart , "+json" )
85+
86+ return isVendor && isJSON
87+ }
88+
7189// AssertReader asserts the value of an io.Reader.
7290func AssertReader (t * testing.T , id string , r io.Reader ) {
7391 data , err := ioutil .ReadAll (r )
@@ -84,7 +102,7 @@ func createOrUpdateSnapshot(t *testing.T, id, data string) {
84102 var err error
85103 if snapshot == nil {
86104 if ! args .shouldUpdate {
87- t .Error (newSnapshotMessage (data ))
105+ t .Error (newSnapshotMessage (id , data ))
88106 return
89107 }
90108
@@ -109,7 +127,7 @@ func createOrUpdateSnapshot(t *testing.T, id, data string) {
109127 return
110128 }
111129
112- t .Error (didNotMatchMessage (diff ))
130+ t .Error (didNotMatchMessage (id , diff ))
113131 return
114132 }
115133}
@@ -132,16 +150,18 @@ func compareResults(t *testing.T, existing, new string) string {
132150 return dmp .DiffPrettyText (allDiffs )
133151}
134152
135- func didNotMatchMessage (diff string ) string {
136- msg := "\n \n Existing snapshot does not match results...\n \n "
153+ func didNotMatchMessage (id , diff string ) string {
154+ msg := "\n \n ## Existing snapshot does not match results...\n "
155+ msg += "## \" " + id + "\" \n \n "
137156 msg += diff
138157 msg += "\n \n "
139158 msg += "If this change was intentional, run tests again, $ go test -v -- -u\n "
140159 return msg
141160}
142161
143- func newSnapshotMessage (body string ) string {
144- msg := "\n \n New snapshot found...\n \n "
162+ func newSnapshotMessage (id , body string ) string {
163+ msg := "\n \n ## New snapshot found...\n "
164+ msg += "## \" " + id + "\" \n \n "
145165 msg += body
146166 msg += "\n \n "
147167 msg += "To save, run tests again, $ go test -v -- -u\n "
0 commit comments