@@ -12,34 +12,35 @@ import (
12
12
"github.com/stretchr/testify/assert"
13
13
)
14
14
15
- func TestLogger (t * testing.T ) {
15
+ func TestLog (t * testing.T ) {
16
16
// Note: Just for the test coverage, not a real test.
17
17
e := echo .New ()
18
18
req := test .NewRequest (echo .GET , "/" , nil )
19
19
rec := test .NewResponseRecorder ()
20
20
c := echo .NewContext (req , rec , e )
21
-
22
- // Status 2xx
23
21
h := func (c echo.Context ) error {
24
22
return c .String (http .StatusOK , "test" )
25
23
}
26
- Logger ()(h )(c )
24
+ mw := Log ()(h )
25
+
26
+ // Status 2xx
27
+ mw (c )
27
28
28
29
// Status 3xx
29
30
rec = test .NewResponseRecorder ()
30
31
c = echo .NewContext (req , rec , e )
31
32
h = func (c echo.Context ) error {
32
33
return c .String (http .StatusTemporaryRedirect , "test" )
33
34
}
34
- Logger ()( h ) (c )
35
+ mw (c )
35
36
36
37
// Status 4xx
37
38
rec = test .NewResponseRecorder ()
38
39
c = echo .NewContext (req , rec , e )
39
40
h = func (c echo.Context ) error {
40
41
return c .String (http .StatusNotFound , "test" )
41
42
}
42
- Logger ()( h ) (c )
43
+ mw (c )
43
44
44
45
// Status 5xx with empty path
45
46
req = test .NewRequest (echo .GET , "" , nil )
@@ -48,10 +49,10 @@ func TestLogger(t *testing.T) {
48
49
h = func (c echo.Context ) error {
49
50
return errors .New ("error" )
50
51
}
51
- Logger ()( h ) (c )
52
+ mw (c )
52
53
}
53
54
54
- func TestLoggerIPAddress (t * testing.T ) {
55
+ func TestLogIPAddress (t * testing.T ) {
55
56
e := echo .New ()
56
57
req := test .NewRequest (echo .GET , "/" , nil )
57
58
rec := test .NewResponseRecorder ()
@@ -62,23 +63,22 @@ func TestLoggerIPAddress(t *testing.T) {
62
63
h := func (c echo.Context ) error {
63
64
return c .String (http .StatusOK , "test" )
64
65
}
65
-
66
- mw := Logger ()
66
+ mw := Log ()(h )
67
67
68
68
// With X-Real-IP
69
69
req .Header ().Add (echo .XRealIP , ip )
70
- mw (h )( c )
70
+ mw (c )
71
71
assert .Contains (t , buf .String (), ip )
72
72
73
73
// With X-Forwarded-For
74
74
buf .Reset ()
75
75
req .Header ().Del (echo .XRealIP )
76
76
req .Header ().Add (echo .XForwardedFor , ip )
77
- mw (h )( c )
77
+ mw (c )
78
78
assert .Contains (t , buf .String (), ip )
79
79
80
80
// with req.RemoteAddr
81
81
buf .Reset ()
82
- mw (h )( c )
82
+ mw (c )
83
83
assert .Contains (t , buf .String (), ip )
84
84
}
0 commit comments