-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontext_test.go
294 lines (219 loc) · 7.01 KB
/
context_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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package gdutils
import (
"net/http"
"reflect"
"testing"
"github.com/pawelWritesCode/gdutils/pkg/cache"
"github.com/pawelWritesCode/gdutils/pkg/debugger"
"github.com/pawelWritesCode/gdutils/pkg/pathfinder"
"github.com/pawelWritesCode/gdutils/pkg/schema"
"github.com/pawelWritesCode/gdutils/pkg/serializer"
"github.com/pawelWritesCode/gdutils/pkg/template"
)
type newDebugger struct{}
type newCache struct{}
type newClient struct{}
type newTemplateEngine struct{}
type newStringValidator struct{}
type newPathFinder struct{}
type newSerializer struct{}
func (n newSerializer) Deserialize(data []byte, v any) error {
panic("implement me")
}
func (n newSerializer) Serialize(v any) ([]byte, error) {
panic("implement me")
}
func (n newPathFinder) Find(expr string, bytes []byte) (any, error) {
panic("implement me")
}
func (n newStringValidator) Validate(document, schemaPath string) error {
panic("implement me")
}
func (n newTemplateEngine) Replace(templateValue string, storage map[string]any) (string, error) {
panic("implement me")
}
func (n newClient) Do(req *http.Request) (*http.Response, error) {
panic("implement me")
}
func (n newCache) Save(key string, value any) {
panic("implement me")
}
func (n newCache) GetSaved(key string) (any, error) {
panic("implement me")
}
func (n newCache) Reset() {
panic("implement me")
}
func (n newCache) All() map[string]any {
panic("implement me")
}
func (n newDebugger) Print(info string) {
panic("implement me")
}
func (n newDebugger) IsOn() bool {
panic("implement me")
}
func (n newDebugger) TurnOn() {
panic("implement me")
}
func (n newDebugger) TurnOff() {
panic("implement me")
}
func (n newDebugger) Reset(isOn bool) {
panic("implement me")
}
func TestState_ResetState(t *testing.T) {
s := NewDefaultAPIContext(true, "")
s.Cache.Save("test", 1)
s.ResetState(false)
if s.Debugger.IsOn() != false {
t.Errorf("IsDebug property did not change")
}
if !reflect.DeepEqual(s.Cache.All(), map[string]any{}) {
t.Errorf("cache did not reset")
}
}
func TestState_SetDebugger(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefaultDebugger := s.Debugger.(*debugger.DebuggerService)
if !isDefaultDebugger {
t.Errorf("default debugger should be *debugger.DebuggerService")
}
s.SetDebugger(newDebugger{})
_, isNewDebugger := s.Debugger.(newDebugger)
if !isNewDebugger {
t.Errorf("SetDebugger does not work properly")
}
}
func TestState_SetCache(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefaultCache := s.Cache.(*cache.ConcurrentCache)
if !isDefaultCache {
t.Errorf("default cache should be *cache.ConcurrentCache")
}
s.SetCache(newCache{})
_, isNewCache := s.Cache.(newCache)
if !isNewCache {
t.Errorf("SetCache does not work properly")
}
}
func TestState_SetRequestDoer(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefaultHttpCli := s.RequestDoer.(*http.Client)
if !isDefaultHttpCli {
t.Errorf("default request doer is not *http.Client")
}
s.SetRequestDoer(newClient{})
_, isNewClient := s.RequestDoer.(newClient)
if !isNewClient {
t.Errorf("SetRequestDoer does not work properly")
}
}
func TestState_SetTemplateEngine(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.TemplateEngine.(template.TemplateManager)
if !isDefault {
t.Errorf("default TemplateEngine is not template.TemplateManager")
}
s.SetTemplateEngine(newTemplateEngine{})
_, isNewTemplateEngine := s.TemplateEngine.(newTemplateEngine)
if !isNewTemplateEngine {
t.Errorf("SetTemplateEngine does not work proplerly")
}
}
func TestState_SetSchemaStringValidator(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.SchemaValidators.StringValidator.(schema.JSONSchemaRawXGValidator)
if !isDefault {
t.Errorf("default StringValidator is not schema.JSONSchemaRawXGValidator")
}
s.SetSchemaStringValidator(newStringValidator{})
_, isNewStringValidator := s.SchemaValidators.StringValidator.(newStringValidator)
if !isNewStringValidator {
t.Errorf("SetSchemaStringValidator does not work properly")
}
}
func TestState_SetSchemaReferenceValidator(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.SchemaValidators.ReferenceValidator.(schema.JSONSchemaReferenceXGValidator)
if !isDefault {
t.Errorf("default ReferenceValidator is not schema.JSONSchemaReferenceXGValidator")
}
s.SetSchemaReferenceValidator(newStringValidator{})
_, isNewReferenceValidator := s.SchemaValidators.ReferenceValidator.(newStringValidator)
if !isNewReferenceValidator {
t.Errorf("SetSchemaReferenceValidator does not work properly")
}
}
func TestState_SetJSONPathFinder(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.PathFinders.JSON.(*pathfinder.DynamicJSONPathFinder)
if !isDefault {
t.Errorf("default JSON PathFinder is not pathfinder.DynamicJSONPathFinder")
}
s.SetJSONPathFinder(newPathFinder{})
_, isNewPathFinder := s.PathFinders.JSON.(newPathFinder)
if !isNewPathFinder {
t.Errorf("SetJSONPathFinder does not work properly")
}
}
func TestState_SetYAMLPathFinder(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.PathFinders.YAML.(pathfinder.GoccyGoYamlFinder)
if !isDefault {
t.Errorf("default YAML PathFinder is not pathfinder.GoccyGoYamlFinder")
}
s.SetYAMLPathFinder(newPathFinder{})
_, isNewPathFinder := s.PathFinders.YAML.(newPathFinder)
if !isNewPathFinder {
t.Errorf("SetYAMLPathFinder does not work properly")
}
}
func TestState_SetXMLPathFinder(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.PathFinders.XML.(pathfinder.AntchfxXMLFinder)
if !isDefault {
t.Errorf("default XML PathFinder is not pathfinder.AntchfxXMLFinder")
}
s.SetXMLPathFinder(newPathFinder{})
_, isNewPathFinder := s.PathFinders.XML.(newPathFinder)
if !isNewPathFinder {
t.Errorf("SetXMLPathFinder does not work properly")
}
}
func TestState_SetJSONSerializer(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.Serializers.JSON.(serializer.JSON)
if !isDefault {
t.Errorf("default JSON Formatter is not formatter.JSONFormatter")
}
s.SetJSONSerializer(newSerializer{})
_, isNewFormatter := s.Serializers.JSON.(newSerializer)
if !isNewFormatter {
t.Errorf("SetJSONSerializer does not work properly")
}
}
func TestState_SetYAMLSerializer(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.Serializers.YAML.(serializer.YAML)
if !isDefault {
t.Errorf("default JSON Formatter is not formatter.YAMLFormatter")
}
s.SetYAMLSerializer(newSerializer{})
_, isNewFormatter := s.Serializers.YAML.(newSerializer)
if !isNewFormatter {
t.Errorf("SetYAMLSerializer does not work properly")
}
}
func TestState_SetXMLSerializer(t *testing.T) {
s := NewDefaultAPIContext(false, "")
_, isDefault := s.Serializers.XML.(serializer.XML)
if !isDefault {
t.Errorf("default XML Formatter is not formatter.XMLFormatter")
}
s.SetXMLSerializer(newSerializer{})
_, isNewFormatter := s.Serializers.XML.(newSerializer)
if !isNewFormatter {
t.Errorf("SetXMLSerializer does not work properly")
}
}