Fixed container tests and import

This commit is contained in:
mikestefanello 2021-12-17 21:14:43 -05:00
parent 0c8c3cc41e
commit 195d572036
3 changed files with 6 additions and 7 deletions

View file

@ -29,5 +29,5 @@ run:
go run main.go go run main.go
.PHONY: test .PHONY: test
run: test:
go test ./... go test ./...

View file

@ -54,7 +54,6 @@ func TestMain(m *testing.M) {
} }
func TestNewContainer(t *testing.T) { func TestNewContainer(t *testing.T) {
c := NewContainer()
assert.NotNil(t, c.Web) assert.NotNil(t, c.Web)
assert.NotNil(t, c.Config) assert.NotNil(t, c.Config)
assert.NotNil(t, c.Cache) assert.NotNil(t, c.Cache)

View file

@ -3,7 +3,7 @@ package middleware
import ( import (
"net/http" "net/http"
"goweb/auth" "goweb/container"
"goweb/context" "goweb/context"
"goweb/ent" "goweb/ent"
"goweb/msg" "goweb/msg"
@ -11,14 +11,14 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func LoadAuthenticatedUser(authClient *auth.Client) echo.MiddlewareFunc { func LoadAuthenticatedUser(authClient *container.AuthClient) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc { return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
u, err := authClient.GetAuthenticatedUser(c) u, err := authClient.GetAuthenticatedUser(c)
switch err.(type) { switch err.(type) {
case *ent.NotFoundError: case *ent.NotFoundError:
c.Logger().Debug("auth user not found") c.Logger().Debug("auth user not found")
case auth.NotAuthenticatedError: case container.NotAuthenticatedError:
case nil: case nil:
c.Set(context.AuthenticatedUserKey, u) c.Set(context.AuthenticatedUserKey, u)
c.Logger().Info("auth user loaded in to context: %d", u.ID) c.Logger().Info("auth user loaded in to context: %d", u.ID)
@ -31,7 +31,7 @@ func LoadAuthenticatedUser(authClient *auth.Client) echo.MiddlewareFunc {
} }
} }
func LoadValidPasswordToken(authClient *auth.Client) echo.MiddlewareFunc { func LoadValidPasswordToken(authClient *container.AuthClient) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc { return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
var usr *ent.User var usr *ent.User
@ -46,7 +46,7 @@ func LoadValidPasswordToken(authClient *auth.Client) echo.MiddlewareFunc {
switch err.(type) { switch err.(type) {
case nil: case nil:
case auth.InvalidTokenError: case container.InvalidTokenError:
msg.Warning(c, "The link is either invalid or has expired. Please request a new one.") msg.Warning(c, "The link is either invalid or has expired. Please request a new one.")
return c.Redirect(http.StatusFound, c.Echo().Reverse("forgot_password")) return c.Redirect(http.StatusFound, c.Echo().Reverse("forgot_password"))
default: default: