-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
executable file
·88 lines (84 loc) · 1.56 KB
/
time_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package odt_test
import (
"reflect"
"testing"
"time"
date "github.com/efimovalex/odt"
)
func TestTime_UnmarshalJSON(t *testing.T) {
type args struct {
b []byte
}
tests := []struct {
name string
d *date.Time
args args
wantErr bool
}{
{
"Success null value",
&date.Time{},
args{[]byte(`null`)},
false,
},
{
"Success date value",
&date.Time{},
args{[]byte(`"18:10:02"`)},
false,
},
{
"Success stripped of quotation marks ",
&date.Time{},
args{[]byte(`22:10:12`)},
false,
},
{
"Error non valid time value",
&date.Time{},
args{[]byte(`"18:10"`)},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.d.UnmarshalJSON(tt.args.b); (err != nil) != tt.wantErr {
t.Errorf("Time.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestTime_MarshalJSON(t *testing.T) {
tm, _ := time.Parse(time.RFC3339, "0001-01-01T23:59:59+03:00")
tests := []struct {
name string
d *date.Time
want []byte
wantErr bool
}{
{
"Success null value",
&date.Time{},
[]byte(`null`),
false,
},
{
"Success good value",
&date.Time{&tm},
[]byte(`"23:59:59"`),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.d.MarshalJSON()
if (err != nil) != tt.wantErr {
t.Errorf("Time.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Time.MarshalJSON() = %s, want %s", got, tt.want)
}
})
}
}