github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/b2/api/types_test.go (about) 1 package api_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/rclone/rclone/backend/b2/api" 8 "github.com/rclone/rclone/fstest" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 var ( 14 emptyT api.Timestamp 15 t0 = api.Timestamp(fstest.Time("1970-01-01T01:01:01.123456789Z")) 16 t1 = api.Timestamp(fstest.Time("2001-02-03T04:05:06.123000000Z")) 17 ) 18 19 func TestTimestampMarshalJSON(t *testing.T) { 20 resB, err := t0.MarshalJSON() 21 res := string(resB) 22 require.NoError(t, err) 23 assert.Equal(t, "3661123", res) 24 25 resB, err = t1.MarshalJSON() 26 res = string(resB) 27 require.NoError(t, err) 28 assert.Equal(t, "981173106123", res) 29 } 30 31 func TestTimestampUnmarshalJSON(t *testing.T) { 32 var tActual api.Timestamp 33 err := tActual.UnmarshalJSON([]byte("981173106123")) 34 require.NoError(t, err) 35 assert.Equal(t, (time.Time)(t1), (time.Time)(tActual)) 36 } 37 38 func TestTimestampIsZero(t *testing.T) { 39 assert.True(t, emptyT.IsZero()) 40 assert.False(t, t0.IsZero()) 41 assert.False(t, t1.IsZero()) 42 } 43 44 func TestTimestampEqual(t *testing.T) { 45 assert.False(t, emptyT.Equal(emptyT)) 46 assert.False(t, t0.Equal(emptyT)) 47 assert.False(t, emptyT.Equal(t0)) 48 assert.False(t, t0.Equal(t1)) 49 assert.False(t, t1.Equal(t0)) 50 assert.True(t, t0.Equal(t0)) 51 assert.True(t, t1.Equal(t1)) 52 }