yanic/jsontime/jsontime_test.go

30 lines
550 B
Go
Raw Normal View History

2016-03-20 17:10:39 +01:00
package jsontime
import (
"encoding/json"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMarshalTime(t *testing.T) {
assert := assert.New(t)
nativeTime, err := time.Parse(time.RFC3339, "2012-11-01T22:08:41+00:00")
assert.Nil(err)
json, err := Time(nativeTime).MarshalJSON()
assert.Nil(err)
assert.Equal(`"2012-11-01T22:08:41"`, string(json))
}
func TestUnmarshalTime(t *testing.T) {
assert := assert.New(t)
jsonTime := Time{}
err := json.Unmarshal([]byte(`"2012-11-01T22:08:41"`), &jsonTime)
assert.Nil(err)
}