65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"git.sch9.ru/new_gate/ms-auth/config"
|
|
"git.sch9.ru/new_gate/ms-auth/internal/sessions"
|
|
vk "git.sch9.ru/new_gate/ms-auth/pkg/external/valkey"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/testcontainers/testcontainers-go/modules/valkey"
|
|
"go.uber.org/zap"
|
|
"log"
|
|
"testing"
|
|
)
|
|
|
|
func SetupValkey() (sessions.ValkeyRepository, func()) {
|
|
ctx := context.Background()
|
|
|
|
valkeyContainer, err := valkey.Run(ctx,
|
|
"docker.io/valkey/valkey:7.2.5",
|
|
//valkey.WithSnapshotting(10, 1),
|
|
//valkey.WithLogLevel(valkey.LogLevelVerbose),
|
|
//valkey.WithConfigFile(filepath.Join("testdata", "valkey7.conf")),
|
|
)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
dsn, err := valkeyContainer.ConnectionString(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
client, err := vk.NewValkeyClient(dsn)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
cfg := config.Config{
|
|
JWTSecret: "secret",
|
|
}
|
|
|
|
sessionRepo := NewValkeyRepository(client, cfg, zap.NewNop())
|
|
|
|
closeVC := func() {
|
|
if err := valkeyContainer.Stop(ctx, nil); err != nil {
|
|
log.Printf("failed to terminate container: %s", err)
|
|
}
|
|
}
|
|
|
|
return sessionRepo, closeVC
|
|
}
|
|
|
|
func TestValkeyRepository_CreateSession(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sessionRepo, closeVC := SetupValkey()
|
|
defer closeVC()
|
|
|
|
t.Run("valid session creation", func(t *testing.T) {
|
|
err := sessionRepo.CreateSession(context.Background(), 1)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|