зеркало из https://github.com/mozilla/doorman.git
Test mozlog middleware
This commit is contained in:
Родитель
e5d76c6d8b
Коммит
0cddea9beb
|
@ -1,13 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoggerMiddleware(t *testing.T) {
|
||||
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
c.Request, _ = http.NewRequest("GET", "/get", nil)
|
||||
handler := MozLogger()
|
||||
|
||||
var buf bytes.Buffer
|
||||
logrus.SetOutput(&buf)
|
||||
defer logrus.SetOutput(os.Stdout)
|
||||
|
||||
handler(c)
|
||||
|
||||
assert.Contains(t, buf.String(), "errno=0")
|
||||
}
|
||||
|
||||
func TestRequestLogFields(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
fields := RequestLogFields(r, 200, time.Duration(100))
|
||||
|
|
Загрузка…
Ссылка в новой задаче