You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've discovered that timestamps are escaped differently in Go 1.20. This may not be a huge issue, but if you do snapshot testing and test against the validation errors from gin, it will cause them to fail when comparing payloads between Go 1.19 and Go 1.20 because timestamps used to have extra escaping that now have disappeared in Go 1.20. Was this intentional or am I doing something weird here?
When I run in one terminal go run . and then in another go test ./... with go version 1.19.4 the first time, I get the following error message, as I should as snapshot tests fail the first time you run them because there is no saved file to compare the payload to. But note the escaping around the timestamps:
❯ go test ./...
--- FAIL: TestThing (0.00s)
main_test.go:50: snapshot created for test TestThing, with contents:
{"detail":"parsing time \"\\\"01.01.2022 22:00\\\"\" as \"\\\"2006-01-02T15:0
4:05Z07:00\\\"\": cannot parse \"1.2022 22:00\\\"\" as \"2006\""}
I then switched my go version to 1.20 and ran go test ./... again:
❯ go test ./...
--- FAIL: TestThing (0.00s)
main_test.go:50: snapshot not equal:
--- Previous
+++ Current
@@ -1,2 +1,2 @@
-{"detail":"parsing time \"\\\"01.01.2022 22:00\\\"\" as \"\\\"2006-01-02T15:
04:05Z07:00\\\"\": cannot parse \"1.2022 22:00\\\"\" as \"2006\""}
+{"detail":"parsing time \"01.01.2022 22:00\" as \"2006-01-02T15:04:05Z07:00\
": cannot parse \"01.01.2022 22:00\" as \"2006\""}
Note how in the + section the escaping is now better and doesn't include \\\.
Expectations
I would have expected the error messages to stay the same, even though the escaping in 1.19 was worse.
Actual result
Something changed between go versions that caused the escaping of the timestamps to change in Gin's validation errors.
I've also confirmed that this has nothing to do with cupaloy, the snapshot testing library I'm using. I sent requests to my local server from main.go using httpie and have the same escaping discrepancy between go versions:
In go1.20, enforce strict parsing for RFC3339 for Time.Unmarshal. By default, gin uses func (t *Time) UnmarshalJSON(data []byte) method, See golang/go#54580
Description
I've discovered that timestamps are escaped differently in Go 1.20. This may not be a huge issue, but if you do snapshot testing and test against the validation errors from gin, it will cause them to fail when comparing payloads between Go 1.19 and Go 1.20 because timestamps used to have extra escaping that now have disappeared in Go 1.20. Was this intentional or am I doing something weird here?
How to reproduce
go.mod
main.go
main_test.go
When I run in one terminal
go run .
and then in anothergo test ./...
with go version 1.19.4 the first time, I get the following error message, as I should as snapshot tests fail the first time you run them because there is no saved file to compare the payload to. But note the escaping around the timestamps:I then switched my go version to 1.20 and ran
go test ./...
again:Note how in the
+
section the escaping is now better and doesn't include\\\
.Expectations
I would have expected the error messages to stay the same, even though the escaping in 1.19 was worse.
Actual result
Something changed between go versions that caused the escaping of the timestamps to change in Gin's validation errors.
I've also confirmed that this has nothing to do with
cupaloy
, the snapshot testing library I'm using. I sent requests to my local server frommain.go
usinghttpie
and have the same escaping discrepancy between go versions:request.json
go 1.19.4
go 1.20
Environment
The text was updated successfully, but these errors were encountered: