ms-auth/internal/sessions/repository/valkey_repository_test.go

49 lines
967 B
Go
Raw Permalink Normal View History

2024-10-09 17:07:38 +00:00
package repository
import (
"context"
"git.sch9.ru/new_gate/ms-auth/config"
"github.com/stretchr/testify/require"
2024-10-13 17:21:15 +00:00
"github.com/valkey-io/valkey-go/mock"
"go.uber.org/mock/gomock"
2024-10-09 17:07:38 +00:00
"go.uber.org/zap"
"testing"
)
func TestValkeyRepository_CreateSession(t *testing.T) {
t.Parallel()
2024-10-13 17:21:15 +00:00
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := mock.NewClient(ctrl)
sessionRepo := NewValkeyRepository(client, config.Config{JWTSecret: "secret"}, zap.NewNop())
2024-10-09 17:07:38 +00:00
t.Run("valid session creation", func(t *testing.T) {
2024-10-13 17:21:15 +00:00
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)
2024-10-09 17:07:38 +00:00
require.NoError(t, err)
})
}