github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go (about) 1 package jsonlog // import "github.com/docker/docker/daemon/logger/jsonfilelog/jsonlog" 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/docker/docker/internal/testutil" 8 "github.com/gotestyourself/gotestyourself/assert" 9 is "github.com/gotestyourself/gotestyourself/assert/cmp" 10 ) 11 12 func TestFastTimeMarshalJSONWithInvalidYear(t *testing.T) { 13 aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local) 14 _, err := fastTimeMarshalJSON(aTime) 15 testutil.ErrorContains(t, err, "year outside of range") 16 17 anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local) 18 _, err = fastTimeMarshalJSON(anotherTime) 19 testutil.ErrorContains(t, err, "year outside of range") 20 } 21 22 func TestFastTimeMarshalJSON(t *testing.T) { 23 aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC) 24 json, err := fastTimeMarshalJSON(aTime) 25 assert.NilError(t, err) 26 assert.Check(t, is.Equal("\"2015-05-29T11:01:02.000000003Z\"", json)) 27 28 location, err := time.LoadLocation("Europe/Paris") 29 assert.NilError(t, err) 30 31 aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location) 32 json, err = fastTimeMarshalJSON(aTime) 33 assert.NilError(t, err) 34 assert.Check(t, is.Equal("\"2015-05-29T11:01:02.000000003+02:00\"", json)) 35 }