Added tests package with helpers. Started on middleware tests.
This commit is contained in:
parent
0e2625bf51
commit
58ba9f6dcc
9 changed files with 197 additions and 66 deletions
|
|
@ -1,15 +1,12 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"goweb/config"
|
||||
"goweb/ent"
|
||||
"goweb/tests"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
|
@ -18,7 +15,6 @@ var (
|
|||
c *Container
|
||||
ctx echo.Context
|
||||
usr *ent.User
|
||||
rec *httptest.ResponseRecorder
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
|
@ -34,20 +30,12 @@ func TestMain(m *testing.M) {
|
|||
}()
|
||||
|
||||
// Create a web context
|
||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
||||
rec = httptest.NewRecorder()
|
||||
ctx = c.Web.NewContext(req, rec)
|
||||
ctx, _ = tests.NewContext(c.Web, "/")
|
||||
tests.InitSession(ctx)
|
||||
|
||||
// Create a test user
|
||||
var err error
|
||||
usr, err = c.ORM.User.
|
||||
Create().
|
||||
SetEmail("test@test.dev").
|
||||
SetPassword("abc").
|
||||
SetName("Test User").
|
||||
Save(context.Background())
|
||||
|
||||
if err != nil {
|
||||
if usr, err = tests.CreateUser(c.ORM); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue