refactoring tests util methods + adding context tests

This commit is contained in:
Julien Neuhart
2019-07-24 14:56:12 +02:00
parent 2be9ae7868
commit 554474776c
23 changed files with 295 additions and 234 deletions

29
test/context.go Normal file
View File

@@ -0,0 +1,29 @@
package test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
)
// DummyEchoContext creates a
// echo.Context without anything.
func DummyEchoContext() echo.Context {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
return e.NewContext(req, rec)
}
// EchoContextMultipart creates a
// echo.Context with form files.
func EchoContextMultipart(t *testing.T) echo.Context {
e := echo.New()
body, contentType := MergeMultipartForm(t, nil)
req := httptest.NewRequest(http.MethodPost, "/", body)
req.Header.Set(echo.HeaderContentType, contentType)
rec := httptest.NewRecorder()
return e.NewContext(req, rec)
}