ms-auth/internal/sessions/repository/valkey_repository_test.go
Vyacheslav1557 15a128e0a6 test:
2024-10-13 22:21:15 +05:00

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)
})
}