Added tests for auth middleware.
This commit is contained in:
parent
58ba9f6dcc
commit
d395993338
5 changed files with 76 additions and 49 deletions
|
|
@ -6,10 +6,14 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"goweb/ent"
|
||||
|
||||
"github.com/go-playground/assert/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
|
|
@ -33,6 +37,18 @@ func ExecuteMiddleware(ctx echo.Context, mw echo.MiddlewareFunc) error {
|
|||
return handler(ctx)
|
||||
}
|
||||
|
||||
func AssertHTTPErrorCode(t *testing.T, err error, code int) {
|
||||
httpError, ok := err.(*echo.HTTPError)
|
||||
require.True(t, ok)
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue