49 lines
967 B
Go
49 lines
967 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"git.sch9.ru/new_gate/ms-auth/config"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/valkey-io/valkey-go/mock"
|
|
"go.uber.org/mock/gomock"
|
|
"go.uber.org/zap"
|
|
"testing"
|
|
)
|
|
|
|
func TestValkeyRepository_CreateSession(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
client := mock.NewClient(ctrl)
|
|
|
|
sessionRepo := NewValkeyRepository(client, config.Config{JWTSecret: "secret"}, zap.NewNop())
|
|
|
|
t.Run("valid session creation", func(t *testing.T) {
|
|
var userId int32 = 1
|
|
|
|
matcher := mock.MatchFn(func(cmd []string) bool {
|
|
if cmd[0] != "SET" {
|
|
return false
|
|
}
|
|
if cmd[1] != "1" {
|
|
return false
|
|
}
|
|
if cmd[3] != "NX" {
|
|
return false
|
|
}
|
|
if cmd[4] != "EXAT" {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
|
|
ctx := context.Background()
|
|
client.EXPECT().Do(ctx, matcher)
|
|
|
|
err := sessionRepo.CreateSession(context.Background(), userId)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|