-
Notifications
You must be signed in to change notification settings - Fork 28
/
type_test.go
122 lines (114 loc) · 2.26 KB
/
type_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package hubspot_test
import (
"testing"
"time"
"github.com/belong-inc/go-hubspot"
"github.com/google/go-cmp/cmp"
)
func TestHsStr_String(t *testing.T) {
tests := []struct {
name string
hs *hubspot.HsStr
want string
}{
{
name: "Success",
hs: hubspot.NewString("text"),
want: "text",
},
{
name: "Success case of nil receiver",
hs: nil,
want: "",
},
{
name: "Success case of empty string",
hs: hubspot.NewString(""),
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.hs.String(); got != tt.want {
t.Errorf("HsStr.String() mismatch: want %v, got = %v", tt.want, got)
}
})
}
}
func TestHsBool_Boolean(t *testing.T) {
tests := []struct {
input bool
expected bool
}{
{true, true},
{false, false},
}
for _, test := range tests {
result := hubspot.NewBoolean(test.input)
if *result != hubspot.HsBool(test.expected) {
t.Errorf("NewBoolean(%v) = %v; want %v", test.input, *result, test.expected)
}
}
}
var testDate = time.Date(2022, time.February, 28, 0, 0, 0, 0, time.UTC)
func TestHsTime_String(t *testing.T) {
tests := []struct {
name string
ht *hubspot.HsTime
want string
}{
{
name: "Success",
ht: hubspot.NewTime(testDate),
want: "2022-02-28 00:00:00 +0000 UTC",
},
{
name: "Success case of nil receiver",
ht: nil,
want: "nil",
},
{
name: "Success case of zero value",
ht: &hubspot.HsTime{},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.ht.String(); got != tt.want {
t.Errorf("HsTime.String() mismatch: want %v, got = %v", tt.want, got)
}
})
}
}
func TestHsTime_ToTime(t *testing.T) {
tests := []struct {
name string
ht *hubspot.HsTime
want *time.Time
}{
{
name: "Success",
ht: hubspot.NewTime(testDate),
want: &testDate,
},
{
name: "Success case of nil receiver",
ht: nil,
want: nil,
},
{
name: "Success case of zero value",
ht: &hubspot.HsTime{},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.ht.ToTime()
if diff := cmp.Diff(tt.want, got, cmpTimeOption); diff != "" {
t.Errorf("ToTime() mismatch (-want +got):%s", diff)
}
})
}
}