Added tests for entity and log middleware.
This commit is contained in:
parent
ac93e0f366
commit
fc3fee1306
4 changed files with 57 additions and 7 deletions
27
middleware/log_test.go
Normal file
27
middleware/log_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"goweb/tests"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
echomw "github.com/labstack/echo/v4/middleware"
|
||||
)
|
||||
|
||||
func TestLogRequestID(t *testing.T) {
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
_ = tests.ExecuteMiddleware(ctx, echomw.RequestID())
|
||||
_ = tests.ExecuteMiddleware(ctx, LogRequestID())
|
||||
|
||||
var buf bytes.Buffer
|
||||
ctx.Logger().SetOutput(&buf)
|
||||
ctx.Logger().Info("test")
|
||||
rID := ctx.Response().Header().Get(echo.HeaderXRequestID)
|
||||
assert.Contains(t, buf.String(), fmt.Sprintf(`id":"%s"`, rID))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue