1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-20 02:59:54 +02:00
echo/middleware/request_id_test.go
2017-02-10 16:21:32 +09:00

33 lines
773 B
Go

package middleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/labstack/echo"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
)
func TestRequestID(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
rid := RequestIDWithConfig(RequestIDConfig{})
h := rid(func(c echo.Context) error {
return c.String(http.StatusOK, "test")
})
h(c)
if assert.NotEmpty(t, rec.Header().Get("X-Request-ID")) {
u, err := uuid.FromString(rec.Header().Get("X-Request-ID"))
spew.Dump(u)
assert.NoError(t, err)
assert.Equal(t, uint(4), u.Version())
assert.Equal(t, uint(uuid.VariantRFC4122), u.Variant())
}
}