-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_test.go
594 lines (529 loc) · 19.4 KB
/
handler_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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
package httphandler_test
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/Eun/go-hit"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/talon-one/go-httphandler"
)
func TestHandleFunc(t *testing.T) {
options := httphandler.Options{
LogFunc: func(_ *http.Request, handlerError, internalError, publicError error, statusCode int, requestUUID string) {
require.EqualError(t, handlerError, "handler error")
require.Nil(t, internalError)
require.Equal(t, "bad request", publicError.Error())
require.Equal(t, http.StatusBadRequest, statusCode)
require.Equal(t, "0123456789", requestUUID)
},
Encoders: map[string]httphandler.EncodeFunc{
"text/html": func(w http.ResponseWriter, r *http.Request, _ *httphandler.WireError) error {
require.Equal(t, "0123456789", httphandler.GetRequestUUID(r))
_, err := io.WriteString(w, "html")
return err
},
"application/json": func(w http.ResponseWriter, r *http.Request, _ *httphandler.WireError) error {
require.Equal(t, "0123456789", httphandler.GetRequestUUID(r))
_, err := io.WriteString(w, "json")
return err
},
},
FallbackEncoderFunc: func() (httphandler.EncodeFunc, string) {
return func(w http.ResponseWriter, r *http.Request, _ *httphandler.WireError) error {
require.Equal(t, "0123456789", httphandler.GetRequestUUID(r))
_, err := io.WriteString(w, "fallback")
return err
}, "application/octet-stream"
},
RequestUUIDFunc: func() string {
return "0123456789"
},
}
h := httphandler.New(&options)
mux := http.NewServeMux()
mux.HandleFunc("/no-content-type-set", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
if r.Method != http.MethodPost {
return &httphandler.HandlerError{
StatusCode: http.StatusBadRequest,
PublicError: errors.New("bad request"),
}
}
w.WriteHeader(http.StatusNoContent)
return nil
}))
mux.HandleFunc("/text/html", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
if r.Method != http.MethodPost {
return &httphandler.HandlerError{
StatusCode: http.StatusBadRequest,
PublicError: errors.New("bad request"),
ContentType: "text/html",
}
}
w.WriteHeader(http.StatusNoContent)
return nil
}))
mux.HandleFunc("/application/json", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
if r.Method != http.MethodPost {
return &httphandler.HandlerError{
StatusCode: http.StatusBadRequest,
PublicError: errors.New("bad request"),
ContentType: "application/json",
}
}
w.WriteHeader(http.StatusNoContent)
return nil
}))
s := httptest.NewServer(mux)
defer s.Close()
expectFallback := hit.CombineSteps(
hit.Expect().Status().Equal(http.StatusBadRequest),
hit.Expect().Headers("Content-Type").Equal("application/octet-stream"),
hit.Expect().Body().String().Equal("fallback"),
)
expectHMTL := hit.CombineSteps(
hit.Expect().Status().Equal(http.StatusBadRequest),
hit.Expect().Headers("Content-Type").Equal("text/html"),
hit.Expect().Body().String().Equal("html"),
)
expectJSON := hit.CombineSteps(
hit.Expect().Status().Equal(http.StatusBadRequest),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().String().Equal("json"),
)
t.Run("no accept header set", func(t *testing.T) {
hit.Test(t,
hit.Description("no-content-type-set endpoint should respond with application/octet-stream"),
hit.Get(hit.JoinURL(s.URL, "no-content-type-set")),
expectFallback,
)
hit.Test(t,
hit.Description("text/html endpoint should respond with text/html"),
hit.Get(hit.JoinURL(s.URL, "text/html")),
expectHMTL,
)
hit.Test(t,
hit.Description("application/json endpoint should respond with application/json"),
hit.Get(hit.JoinURL(s.URL, "application/json")),
expectJSON,
)
})
t.Run("accept header set", func(t *testing.T) {
hit.Test(t,
hit.Description("no-content-type-set endpoint should respond with text/html"),
hit.Get(hit.JoinURL(s.URL, "no-content-type-set")),
hit.Send().Headers("Accept").Add("text/html"),
expectHMTL,
)
hit.Test(t,
hit.Description("text/html endpoint should respond with text/html"),
hit.Get(hit.JoinURL(s.URL, "text/html")),
hit.Send().Headers("Accept").Add("text/html"),
expectHMTL,
)
hit.Test(t,
hit.Description("application/json endpoint should respond with application/json"),
hit.Get(hit.JoinURL(s.URL, "application/json")),
hit.Send().Headers("Accept").Add("text/html"),
expectJSON,
)
})
t.Run("no error", func(t *testing.T) {
hit.Test(t,
hit.Post(hit.JoinURL(s.URL, "application/json")),
hit.Expect().Status().Equal(http.StatusNoContent),
)
})
}
func TestInvalidAcceptHeader(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
StatusCode: http.StatusInternalServerError,
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Send().Headers("Accept").Add(""),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
)
}
func TestDefaultErrorValues(t *testing.T) {
h := httphandler.New(nil)
require.NoError(t, h.SetRequestUUIDFunc(func() string {
return "0123456789"
}))
require.NoError(t, h.SetLogFunc(func(_ *http.Request, handlerError, internalError, publicError error, statusCode int, requestUUID string) {
require.EqualError(t, handlerError, "handler error")
require.Nil(t, internalError)
require.Equal(t, "unknown error", publicError.Error())
require.Equal(t, http.StatusInternalServerError, statusCode)
require.Equal(t, "0123456789", requestUUID)
}))
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
}
func TestFaultyEncoder(t *testing.T) {
var errorLog []error
options := httphandler.Options{
LogFunc: func(_ *http.Request, handlerError, internalError, publicError error, statusCode int, requestUUID string) {
errorLog = append(errorLog, handlerError)
},
Encoders: map[string]httphandler.EncodeFunc{},
FallbackEncoderFunc: func() (httphandler.EncodeFunc, string) {
return func(w http.ResponseWriter, r *http.Request, _ *httphandler.WireError) error {
return errors.New("encoder error")
}, "application/octet-stream"
},
RequestUUIDFunc: func() string {
return "0123456789"
},
}
h := httphandler.New(&options)
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/octet-stream"),
)
require.Len(t, errorLog, 2)
require.EqualError(t, errorLog[0], `handler error`)
require.EqualError(t, errorLog[1], `unable to encode "application/octet-stream": encoder error`)
}
func TestDoubleWrite(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
w.WriteHeader(http.StatusBadRequest)
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "bad request")
return &httphandler.HandlerError{
StatusCode: http.StatusInternalServerError,
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusBadRequest),
hit.Expect().Body().String().Equal("bad request"),
)
}
func TestDefaultOptions(t *testing.T) {
options := httphandler.Options{
LogFunc: nil,
Encoders: nil,
FallbackEncoderFunc: nil,
RequestUUIDFunc: nil,
}
h := httphandler.New(&options)
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
}
func TestSetEncoderOption(t *testing.T) {
t.Run("using http handler", func(t *testing.T) {
h := httphandler.New(nil)
require.NoError(t, h.SetEncoder("application/json", func(w http.ResponseWriter, r *http.Request, e *httphandler.WireError) error {
_, err := io.WriteString(w, "json")
return err
}))
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
ContentType: "application/json",
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().String().Equal("json"),
)
})
t.Run("using options", func(t *testing.T) {
var options httphandler.Options
require.NoError(t, options.SetEncoder("application/json", func(w http.ResponseWriter, r *http.Request, e *httphandler.WireError) error {
_, err := io.WriteString(w, "json")
return err
}))
h := httphandler.New(&options)
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
ContentType: "application/json",
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().String().Equal("json"),
)
})
}
func TestSetEncodersOption(t *testing.T) {
h := httphandler.New(nil)
require.NoError(t, h.SetEncoders(map[string]httphandler.EncodeFunc{
"application/json": func(w http.ResponseWriter, r *http.Request, e *httphandler.WireError) error {
_, err := io.WriteString(w, "json")
return err
},
}))
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
ContentType: "application/json",
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().String().Equal("json"),
)
}
func TestSetLogFuncAndSetRequestUUIDFuncOption(t *testing.T) {
h := httphandler.New(nil)
require.NoError(t, h.SetLogFunc(func(_ *http.Request, handlerError, internalError, publicError error, statusCode int, requestUUID string) {
require.EqualError(t, handlerError, "handler error")
require.Nil(t, internalError)
require.Equal(t, "unknown error", publicError.Error())
require.Equal(t, http.StatusInternalServerError, statusCode)
require.Equal(t, "0123456789", requestUUID)
}))
require.NoError(t, h.SetRequestUUIDFunc(func() string {
return "0123456789"
}))
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
ContentType: "application/json",
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
}
func TestSetFallbackEncoderOption(t *testing.T) {
h := httphandler.New(nil)
require.NoError(t, h.SetFallbackEncoder("application/json", func(w http.ResponseWriter, r *http.Request, e *httphandler.WireError) error {
_, err := io.WriteString(w, "json")
return err
}))
mux := http.NewServeMux()
mux.HandleFunc("/", h.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().String().Equal("json"),
)
}
func TestSetInvalidOptions(t *testing.T) {
h := httphandler.New(nil)
require.EqualError(t, h.SetLogFunc(nil), "logFunc cannot be nil")
require.EqualError(t, h.SetEncoders(nil), "encoders cannot be nil")
require.EqualError(t, h.SetEncoder("", func(_ http.ResponseWriter, _ *http.Request, _ *httphandler.WireError) error {
return nil
}), "content-type cannot be empty")
require.EqualError(t, h.SetEncoder("text/html", nil), "encoder cannot be nil")
require.EqualError(t, h.SetFallbackEncoder("", func(_ http.ResponseWriter, _ *http.Request, _ *httphandler.WireError) error {
return nil
}), "content-type cannot be empty")
require.EqualError(t, h.SetFallbackEncoder("text/html", nil), "encoder cannot be nil")
require.EqualError(t, h.SetRequestUUIDFunc(nil), "requestUUIDFunc cannot be nil")
}
func TestDefaultEncoders(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{}
}))
s := httptest.NewServer(mux)
defer s.Close()
defaultEncoders := httphandler.DefaultOptions().Encoders
for contentType := range defaultEncoders {
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Send().Headers("Accept").Add(contentType),
hit.Expect().Headers("Content-Type").Equal(contentType),
)
}
}
func TestPanicHandler(t *testing.T) {
t.Run("string", func(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
panic("oops")
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
})
t.Run("error", func(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
panic(errors.New("oops"))
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
})
t.Run("set custom panic handler", func(t *testing.T) {
handler := httphandler.New(nil)
handler.SetCustomPanicHandler(func(ctx context.Context, handlerError *httphandler.HandlerError) {
require.Equal(t, "panic: oops", handlerError.InternalError.Error())
})
mux := http.NewServeMux()
mux.HandleFunc("/", handler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
panic("oops")
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
})
}
type extendedError struct {
Title string
Details string
}
func (e extendedError) Error() string {
return fmt.Sprintf("error: title=`%s' details=`%s'", e.Title, e.Details)
}
func TestExtendedError(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", httphandler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
PublicError: extendedError{
Title: "Some Error",
Details: "Not implemented",
},
}
}))
s := httptest.NewServer(mux)
defer s.Close()
t.Run("application/json", func(t *testing.T) {
hit.Test(t,
hit.Get(s.URL),
hit.Send().Headers("Accept").Add("application/json"),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error.Title").Equal("Some Error"),
hit.Expect().Body().JSON().JQ(".Error.Details").Equal("Not implemented"),
)
})
}
func TestRemoveEncoder(t *testing.T) {
opts := httphandler.DefaultOptions()
handler := httphandler.New(opts)
// remove text/html encoders
delete(opts.Encoders, "text/html")
mux := http.NewServeMux()
mux.HandleFunc("/", handler.HandleFunc(func(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
return &httphandler.HandlerError{
PublicError: errors.New("unknown error"),
}
}))
s := httptest.NewServer(mux)
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
// request text/html, however since we removed the encoders earlier we should fallback to application/json
hit.Send().Headers("Accept").Add("text/html"),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
}
type myHandler struct{}
func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) *httphandler.HandlerError {
panic("implement me")
}
func TestHandler(t *testing.T) {
s := httptest.NewServer(httphandler.Handle(myHandler{}))
defer s.Close()
hit.Test(t,
hit.Get(s.URL),
hit.Expect().Status().Equal(http.StatusInternalServerError),
hit.Expect().Headers("Content-Type").Equal("application/json"),
hit.Expect().Body().JSON().JQ(".StatusCode").Equal(http.StatusInternalServerError),
hit.Expect().Body().JSON().JQ(".RequestUUID").Len().GreaterThan(0),
hit.Expect().Body().JSON().JQ(".Error").Equal("unknown error"),
)
}