-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
103 lines (100 loc) · 2.51 KB
/
options_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
96
97
98
99
100
101
102
103
package registrantalert
import (
"reflect"
"strconv"
"testing"
"time"
)
// TestOptions tests the Options functions.
func TestOptions(t *testing.T) {
tests := []struct {
name string
values *registrantAlertRequest
option Option
want string
}{
{
name: "responseFormat",
values: ®istrantAlertRequest{},
option: OptionResponseFormat("json"),
want: "json",
},
{
name: "sinceDate",
values: ®istrantAlertRequest{},
option: OptionSinceDate(time.Date(2021, 01, 01, 0, 0, 0, 0, time.UTC)),
want: "2021-01-01",
},
{
name: "punycode",
values: ®istrantAlertRequest{},
option: OptionPunycode(false),
want: "false",
},
{
name: "createdDateFrom",
values: ®istrantAlertRequest{},
option: OptionCreatedDateFrom(time.Date(2022, 01, 01, 0, 0, 0, 0, time.UTC)),
want: "2022-01-01",
},
{
name: "createdDateTo",
values: ®istrantAlertRequest{},
option: OptionCreatedDateTo(time.Date(2021, 02, 01, 0, 0, 0, 0, time.UTC)),
want: "2021-02-01",
},
{
name: "updatedDateFrom",
values: ®istrantAlertRequest{},
option: OptionUpdatedDateFrom(time.Date(2021, 01, 03, 0, 0, 0, 0, time.UTC)),
want: "2021-01-03",
},
{
name: "updatedDateTo",
values: ®istrantAlertRequest{},
option: OptionUpdatedDateTo(time.Date(2021, 01, 01, 1, 0, 0, 0, time.UTC)),
want: "2021-01-01",
},
{
name: "expiredDateFrom",
values: ®istrantAlertRequest{},
option: OptionExpiredDateFrom(time.Date(2021, 01, 01, 0, 2, 0, 0, time.UTC)),
want: "2021-01-01",
},
{
name: "expiredDateTo",
values: ®istrantAlertRequest{},
option: OptionExpiredDateTo(time.Date(2021, 01, 01, 0, 0, 3, 0, time.UTC)),
want: "2021-01-01",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got string
tt.option(tt.values)
switch tt.name {
case "responseFormat":
got = tt.values.ResponseFormat
case "sinceDate":
got = tt.values.SinceDate
case "createdDateFrom":
got = tt.values.CreatedDateFrom
case "createdDateTo":
got = tt.values.CreatedDateTo
case "updatedDateFrom":
got = tt.values.UpdatedDateFrom
case "updatedDateTo":
got = tt.values.UpdatedDateTo
case "expiredDateFrom":
got = tt.values.ExpiredDateFrom
case "expiredDateTo":
got = tt.values.ExpiredDateTo
case "punycode":
got = strconv.FormatBool(tt.values.Punycode)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Option() = %v, want %v", got, tt.want)
}
})
}
}