Files
query-orchestration/internal/serviceconfig/database/transaction_test.go
T
Michael McGuinness 7001ca854c Merged in feature/docinitialisation (pull request #41)
Queuing Changes and Cfg Testing

* staarting

* staarting

* startedpush

* note

* save

* mocking

* removederrs

* fixtests

* cleanuperrs

* newenvsetup

* preppingtests

* queue

* mmovetocfgpassunittests

* sortoutconfig

* passinginteg

* deps

* fixtests
2025-02-03 17:30:50 +00:00

46 lines
1.1 KiB
Go

package database_test
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"testing"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestExecuteTransaction(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
clientID := database.MustToDBUUID(uuid.New())
clientName := "example_client"
pool.ExpectBegin()
pool.ExpectQuery("name: CreateClient :one").WithArgs(clientName).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(clientID),
)
pool.ExpectCommit()
err = cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
id, err := q.CreateClient(ctx, "example_client")
assert.NoError(t, err)
assert.Equal(t, clientID, id)
return nil
})
assert.NoError(t, err)
}