This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
client_test.go
251 lines (206 loc) · 6.16 KB
/
client_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package bux
import (
"context"
"testing"
"github.com/BuxOrg/bux/tester"
"github.com/bitcoin-sv/go-paymail"
"github.com/mrz1836/go-cachestore"
"github.com/mrz1836/go-datastore"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// todo: finish unit tests!
// TestClient_Debug will test the method Debug()
func TestClient_Debug(t *testing.T) {
t.Parallel()
t.Run("load basic with debug", func(t *testing.T) {
tc, err := NewClient(
tester.GetNewRelicCtx(t, defaultNewRelicApp, defaultNewRelicTx),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
require.NotNil(t, tc)
defer CloseClient(context.Background(), t, tc)
assert.Equal(t, false, tc.IsDebug())
tc.Debug(true)
assert.Equal(t, true, tc.IsDebug())
assert.Equal(t, true, tc.Cachestore().IsDebug())
assert.Equal(t, true, tc.Datastore().IsDebug())
assert.Equal(t, true, tc.Notifications().IsDebug())
})
}
// TestClient_IsDebug will test the method IsDebug()
func TestClient_IsDebug(t *testing.T) {
t.Parallel()
t.Run("basic debug checks", func(t *testing.T) {
tc, err := NewClient(
tester.GetNewRelicCtx(t, defaultNewRelicApp, defaultNewRelicTx),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
require.NotNil(t, tc)
defer CloseClient(context.Background(), t, tc)
assert.Equal(t, false, tc.IsDebug())
tc.Debug(true)
assert.Equal(t, true, tc.IsDebug())
})
}
// TestClient_Version will test the method Version()
func TestClient_Version(t *testing.T) {
t.Parallel()
t.Run("check version", func(t *testing.T) {
tc, err := NewClient(
tester.GetNewRelicCtx(t, defaultNewRelicApp, defaultNewRelicTx),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
require.NotNil(t, tc)
defer CloseClient(context.Background(), t, tc)
assert.Equal(t, version, tc.Version())
})
}
// TestClient_Cachestore will test the method Cachestore()
func TestClient_Cachestore(t *testing.T) {
t.Parallel()
t.Run("no options, panic", func(t *testing.T) {
assert.Panics(t, func() {
c := new(Client)
assert.Nil(t, c.Cachestore())
})
})
t.Run("valid cachestore", func(t *testing.T) {
tc, err := NewClient(
context.Background(),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
defer CloseClient(context.Background(), t, tc)
assert.NotNil(t, tc.Cachestore())
assert.IsType(t, &cachestore.Client{}, tc.Cachestore())
})
}
// TestClient_Datastore will test the method Datastore()
func TestClient_Datastore(t *testing.T) {
t.Parallel()
t.Run("no options, panic", func(t *testing.T) {
assert.Panics(t, func() {
c := new(Client)
assert.Nil(t, c.Datastore())
})
})
t.Run("valid datastore", func(t *testing.T) {
tc, err := NewClient(
context.Background(),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
defer CloseClient(context.Background(), t, tc)
assert.NotNil(t, tc.Datastore())
assert.IsType(t, &datastore.Client{}, tc.Datastore())
})
}
// TestClient_PaymailClient will test the method PaymailClient()
func TestClient_PaymailClient(t *testing.T) {
t.Parallel()
t.Run("no options, panic", func(t *testing.T) {
assert.Panics(t, func() {
c := new(Client)
assert.Nil(t, c.PaymailClient())
})
})
t.Run("valid paymail client", func(t *testing.T) {
tc, err := NewClient(
context.Background(),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
defer CloseClient(context.Background(), t, tc)
assert.NotNil(t, tc.PaymailClient())
assert.IsType(t, &paymail.Client{}, tc.PaymailClient())
})
}
// TestClient_GetPaymailConfig will test the method GetPaymailConfig()
func TestClient_GetPaymailConfig(t *testing.T) {
t.Parallel()
t.Run("no options, panic", func(t *testing.T) {
assert.Panics(t, func() {
c := new(Client)
assert.Nil(t, c.GetPaymailConfig())
})
})
t.Run("valid paymail server config", func(t *testing.T) {
opts := DefaultClientOpts(false, true)
opts = append(opts, WithPaymailSupport(
[]string{testDomain},
defaultSenderPaymail,
false, false,
))
tc, err := NewClient(context.Background(), opts...)
require.NoError(t, err)
defer CloseClient(context.Background(), t, tc)
assert.NotNil(t, tc.GetPaymailConfig())
assert.IsType(t, &PaymailServerOptions{}, tc.GetPaymailConfig())
})
}
// TestPaymailOptions_Client will test the method Client()
func TestPaymailOptions_Client(t *testing.T) {
t.Parallel()
t.Run("no client", func(t *testing.T) {
p := new(paymailOptions)
assert.Nil(t, p.Client())
})
t.Run("valid paymail client", func(t *testing.T) {
tc, err := NewClient(
context.Background(),
DefaultClientOpts(false, true)...,
)
require.NoError(t, err)
assert.NotNil(t, tc.PaymailClient())
defer CloseClient(context.Background(), t, tc)
assert.IsType(t, &paymail.Client{}, tc.PaymailClient())
assert.NotNil(t, tc.PaymailClient())
assert.IsType(t, &paymail.Client{}, tc.PaymailClient())
})
}
// TestPaymailOptions_FromSender will test the method FromSender()
func TestPaymailOptions_FromSender(t *testing.T) {
t.Parallel()
t.Run("no sender, use default", func(t *testing.T) {
p := &paymailOptions{
serverConfig: &PaymailServerOptions{},
}
assert.Equal(t, defaultSenderPaymail, p.FromSender())
})
t.Run("custom sender set", func(t *testing.T) {
p := &paymailOptions{
serverConfig: &PaymailServerOptions{
DefaultFromPaymail: "[email protected]",
},
}
assert.Equal(t, "[email protected]", p.FromSender())
})
}
// TestPaymailOptions_ServerConfig will test the method ServerConfig()
func TestPaymailOptions_ServerConfig(t *testing.T) {
// t.Parallel()
t.Run("no server config", func(t *testing.T) {
p := new(paymailOptions)
assert.Nil(t, p.ServerConfig())
})
t.Run("valid server config", func(t *testing.T) {
logger := zerolog.Nop()
opts := DefaultClientOpts(false, true)
opts = append(opts, WithPaymailSupport(
[]string{testDomain},
defaultSenderPaymail,
false, false,
),
WithLogger(&logger))
tc, err := NewClient(context.Background(), opts...)
require.NoError(t, err)
defer CloseClient(context.Background(), t, tc)
assert.NotNil(t, tc.GetPaymailConfig())
assert.IsType(t, &PaymailServerOptions{}, tc.GetPaymailConfig())
})
}