-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
logger_test.go
40 lines (30 loc) · 877 Bytes
/
logger_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
package echozap
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
)
func TestZapLogger(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/something", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := func(c echo.Context) error {
return c.String(http.StatusOK, "")
}
obs, logs := observer.New(zap.DebugLevel)
logger := zap.New(obs)
err := ZapLogger(logger)(h)(c)
assert.Nil(t, err)
logFields := logs.AllUntimed()[0].ContextMap()
assert.Equal(t, 1, logs.Len())
assert.Equal(t, int64(200), logFields["status"])
assert.NotNil(t, logFields["latency"])
assert.Equal(t, "GET /something", logFields["request"])
assert.NotNil(t, logFields["host"])
assert.NotNil(t, logFields["size"])
}