diff --git a/middleware/auth_test.go b/middleware/auth_test.go index 62fcb93..d74dd42 100644 --- a/middleware/auth_test.go +++ b/middleware/auth_test.go @@ -50,7 +50,7 @@ func TestRequireAuthentication(t *testing.T) { // Logged in err = tests.ExecuteMiddleware(ctx, RequireAuthentication()) - tests.AssertHTTPErrorCodeNot(t, err, http.StatusUnauthorized) + assert.Nil(t, err) } func TestRequireNoAuthentication(t *testing.T) { @@ -59,7 +59,7 @@ func TestRequireNoAuthentication(t *testing.T) { // Not logged in err := tests.ExecuteMiddleware(ctx, RequireNoAuthentication()) - tests.AssertHTTPErrorCodeNot(t, err, http.StatusForbidden) + assert.Nil(t, err) // Login err = c.Auth.Login(ctx, usr.ID) @@ -104,7 +104,7 @@ func TestLoadValidPasswordToken(t *testing.T) { ctx.SetParamValues(fmt.Sprintf("%d", usr.ID), token) _ = tests.ExecuteMiddleware(ctx, LoadUser(c.ORM)) err = tests.ExecuteMiddleware(ctx, LoadValidPasswordToken(c.Auth)) - tests.AssertHTTPErrorCode(t, err, http.StatusNotFound) + assert.Nil(t, err) ctxPt, ok := ctx.Get(context.PasswordTokenKey).(*ent.PasswordToken) require.True(t, ok) assert.Equal(t, pt.ID, ctxPt.ID) diff --git a/middleware/cache_test.go b/middleware/cache_test.go index 007696d..8fb447d 100644 --- a/middleware/cache_test.go +++ b/middleware/cache_test.go @@ -43,7 +43,7 @@ func TestServeCachedPage(t *testing.T) { require.NoError(t, err) _ = tests.ExecuteMiddleware(ctx, LoadAuthenticatedUser(c.Auth)) err = tests.ExecuteMiddleware(ctx, ServeCachedPage(c.Cache)) - tests.AssertHTTPErrorCode(t, err, http.StatusNotFound) + assert.Nil(t, err) } func TestCacheControl(t *testing.T) { diff --git a/tests/tests.go b/tests/tests.go index 1c717d6..34668cd 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -33,7 +33,9 @@ func InitSession(ctx echo.Context) { } func ExecuteMiddleware(ctx echo.Context, mw echo.MiddlewareFunc) error { - handler := mw(echo.NotFoundHandler) + handler := mw(func(c echo.Context) error { + return nil + }) return handler(ctx) } @@ -43,12 +45,6 @@ func AssertHTTPErrorCode(t *testing.T, err error, code int) { assert.Equal(t, code, httpError.Code) } -func AssertHTTPErrorCodeNot(t *testing.T, err error, code int) { - httpError, ok := err.(*echo.HTTPError) - require.True(t, ok) - assert.NotEqual(t, code, httpError.Code) -} - func CreateUser(orm *ent.Client) (*ent.User, error) { seed := fmt.Sprintf("%d-%d", time.Now().UnixMilli(), rand.IntnRange(10, 1000000)) return orm.User.