Files
query-orchestration/internal/database/repository/db_test.go
T

42 lines
808 B
Go
Raw Normal View History

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)
assert.Nil(t, err)
txQueries := queries.WithTx(tx)
assert.NotNil(t, txQueries)
}