2025-01-08 18:14:15 +00:00
|
|
|
package repository_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestQueriesNew(t *testing.T) {
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queries := repository.New(pool)
|
|
|
|
|
assert.NotNil(t, queries)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestQueriesWithTx(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queries := repository.New(pool)
|
|
|
|
|
assert.NotNil(t, queries)
|
|
|
|
|
|
|
|
|
|
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
|
|
|
|
|
|
|
|
tx, err := pool.Begin(ctx)
|
2025-02-03 17:30:50 +00:00
|
|
|
assert.NoError(t, err)
|
2025-01-08 18:14:15 +00:00
|
|
|
|
|
|
|
|
txQueries := queries.WithTx(tx)
|
|
|
|
|
assert.NotNil(t, txQueries)
|
|
|
|
|
}
|