forked from mirrors/homebox
Initial commit
This commit is contained in:
commit
29f583e936
135 changed files with 18463 additions and 0 deletions
39
backend/internal/services/contexts_test.go
Normal file
39
backend/internal/services/contexts_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/git-web-template/backend/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_SetAuthContext(t *testing.T) {
|
||||
user := &types.UserOut{
|
||||
ID: uuid.New(),
|
||||
}
|
||||
|
||||
token := uuid.New().String()
|
||||
|
||||
ctx := SetUserCtx(context.Background(), user, token)
|
||||
|
||||
ctxUser := UseUserCtx(ctx)
|
||||
|
||||
assert.NotNil(t, ctxUser)
|
||||
assert.Equal(t, user.ID, ctxUser.ID)
|
||||
|
||||
ctxUserToken := UseTokenCtx(ctx)
|
||||
assert.NotEmpty(t, ctxUserToken)
|
||||
}
|
||||
|
||||
func Test_SetAuthContext_Nulls(t *testing.T) {
|
||||
ctx := SetUserCtx(context.Background(), nil, "")
|
||||
|
||||
ctxUser := UseUserCtx(ctx)
|
||||
|
||||
assert.Nil(t, ctxUser)
|
||||
|
||||
ctxUserToken := UseTokenCtx(ctx)
|
||||
assert.Empty(t, ctxUserToken)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue