-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_test.go
51 lines (47 loc) · 976 Bytes
/
date_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package openbd
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDate_UnmarshalJSON(t *testing.T) {
type args struct {
value []byte
}
tests := []struct {
name string
args args
want Date
}{
{
name: "Hyphen-separated date date only",
args: args{
value: []byte(`"2001-01-02"`),
},
want: Date{time.Date(2001, 1, 2, 0, 0, 0, 0, time.UTC)},
},
{
name: "Hyphen-separated date date time",
args: args{
value: []byte(`"2001-01-02 12:13:14"`),
},
want: Date{time.Date(2001, 1, 2, 12, 13, 14, 0, time.UTC)},
},
{
name: "Hyphen-separated date zero date time",
args: args{
value: []byte(`"0000-00-00 00:00:00"`),
},
want: Date{time.Time{}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := Date{time.Time{}}
err := d.UnmarshalJSON(tt.args.value)
require.NoError(t, err)
assert.Equal(t, tt.want, d)
})
}
}