24 lines
603 B
Go
24 lines
603 B
Go
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/context"
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/models/sqlc"
|
|
)
|
|
|
|
func TestLoadUser(t *testing.T) {
|
|
ctx, _ := tests.NewContext(c.Web, "/")
|
|
ctx.SetParamNames("user")
|
|
ctx.SetParamValues(fmt.Sprintf("%d", usr.ID))
|
|
_ = tests.ExecuteMiddleware(ctx, LoadUser(c.DB))
|
|
ctxUsr, ok := ctx.Get(context.UserKey).(*sqlc.User)
|
|
require.True(t, ok)
|
|
assert.Equal(t, usr.ID, ctxUsr.ID)
|
|
}
|