daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go
27220ecc
 package jsonlog
9aa8a590
 
 import (
 	"testing"
 	"time"
7de92de6
 
 	"github.com/docker/docker/internal/testutil"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
9aa8a590
 )
 
7de92de6
 func TestFastTimeMarshalJSONWithInvalidYear(t *testing.T) {
9aa8a590
 	aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local)
7de92de6
 	_, err := fastTimeMarshalJSON(aTime)
 	testutil.ErrorContains(t, err, "year outside of range")
9aa8a590
 
7de92de6
 	anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local)
 	_, err = fastTimeMarshalJSON(anotherTime)
 	testutil.ErrorContains(t, err, "year outside of range")
9aa8a590
 }
 
27220ecc
 func TestFastTimeMarshalJSON(t *testing.T) {
9aa8a590
 	aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC)
7de92de6
 	json, err := fastTimeMarshalJSON(aTime)
 	require.NoError(t, err)
 	assert.Equal(t, "\"2015-05-29T11:01:02.000000003Z\"", json)
9aa8a590
 
 	location, err := time.LoadLocation("Europe/Paris")
7de92de6
 	require.NoError(t, err)
 
9aa8a590
 	aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location)
7de92de6
 	json, err = fastTimeMarshalJSON(aTime)
 	require.NoError(t, err)
 	assert.Equal(t, "\"2015-05-29T11:01:02.000000003+02:00\"", json)
9aa8a590
 }