forked from savsgio/atreugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
82 lines (61 loc) · 1.83 KB
/
utils_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
package atreugo
import (
"errors"
"testing"
"github.com/valyala/fasthttp"
)
func Test_viewToHandler(t *testing.T) {
called := false
err := errors.New("error")
view := func(ctx *RequestCtx) error {
called = true
return err
}
ctx := new(fasthttp.RequestCtx)
handler := viewToHandler(view, defaultErrorView)
handler(ctx)
if !called {
t.Error("View is not called")
}
if ctx.Response.StatusCode() != fasthttp.StatusInternalServerError {
t.Errorf("Status code == %d, want %d", ctx.Response.StatusCode(), fasthttp.StatusInternalServerError)
}
if string(ctx.Response.Body()) != err.Error() {
t.Errorf("Response body == %s, want %s", ctx.Response.Body(), err.Error())
}
}
func Test_isEqual(t *testing.T) {
v1 := func() {} // nolint:ifshort
v2 := func() {} // nolint:ifshort
if !isEqual(v1, v1) {
t.Errorf("Values are equals")
}
if isEqual(v1, v2) {
t.Errorf("Values are not equals")
}
}
func Test_middlewaresInclude(t *testing.T) {
fnIncluded := func(ctx *RequestCtx) error { return nil }
fnNotIncluded := func(ctx *RequestCtx) error { return nil }
ms := []Middleware{fnIncluded}
if !middlewaresInclude(ms, fnIncluded) {
t.Errorf("The middleware '%p' is included in '%p'", fnIncluded, ms)
}
if middlewaresInclude(ms, fnNotIncluded) {
t.Errorf("The middleware '%p' is not included in '%p'", fnNotIncluded, ms)
}
}
func Test_appendMiddlewares(t *testing.T) {
fn := func(ctx *RequestCtx) error { return nil }
fnSkip := func(ctx *RequestCtx) error { return nil }
dst := []Middleware{}
src := []Middleware{fn, fnSkip}
skip := []Middleware{fnSkip}
dst = appendMiddlewares(dst, src, skip...)
if middlewaresInclude(dst, fnSkip) {
t.Errorf("The middleware '%p' must not be appended in '%p'", fnSkip, dst)
}
if !middlewaresInclude(dst, fn) {
t.Errorf("The middleware '%p' must be appended in '%p'", fn, dst)
}
}