-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers_test.go
95 lines (90 loc) · 1.83 KB
/
helpers_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
89
90
91
92
93
94
95
package apiary
import (
"database/sql"
"encoding/json"
"reflect"
"testing"
"time"
)
func Test_dateInRange(t *testing.T) {
minDate, _ := time.Parse("2006-01-02", "1783-09-03")
maxDate, _ := time.Parse("2006-01-02", "2000-12-31")
type args struct {
d string
min time.Time
max time.Time
}
tests := []struct {
name string
args args
want time.Time
wantErr bool
}{
{
name: "Test date in range",
args: args{
d: "1900-06-09",
min: minDate,
max: maxDate,
},
want: time.Date(1900, 6, 9, 0, 0, 0, 0, time.UTC),
wantErr: false,
},
{
name: "Test date after range",
args: args{
d: "2020-06-09",
min: minDate,
max: maxDate,
},
want: maxDate,
wantErr: false,
},
{
name: "Test date before range",
args: args{
d: "1620-06-09",
min: minDate,
max: maxDate,
},
want: minDate,
wantErr: false,
},
{
name: "Test invalid date",
args: args{
d: "1920-15-40",
min: minDate,
max: maxDate,
},
want: time.Time{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := dateInRange(tt.args.d, tt.args.min, tt.args.max)
if (err != nil) != tt.wantErr {
t.Errorf("dateInRange() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("dateInRange() = %v, want %v", got, tt.want)
}
})
}
}
func TestNullInt64(t *testing.T) {
emptyInt := NullInt64{sql.NullInt64{Int64: 0, Valid: false}}
out, _ := json.Marshal(emptyInt)
if string(out) != "null" {
t.Errorf("Want: null. Got: %s.", out)
}
}
func TestNullString(t *testing.T) {
emptyString := NullString{sql.NullString{String: "", Valid: false}}
out, _ := json.Marshal(emptyString)
if string(out) != "null" {
t.Errorf("Want: null. Got: %s.", out)
}
}