1587da9d11
Fix Fullsuite * save * foundthefix.. * codeandrequire
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package database_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExecuteTransaction(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
clientID := database.MustToDBUUID(uuid.New())
|
|
clientName := "example_client"
|
|
externalId := "example_id"
|
|
|
|
pool.ExpectBegin()
|
|
pool.ExpectQuery("name: CreateClient :one").WithArgs(externalId, 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, &repository.CreateClientParams{
|
|
Name: clientName,
|
|
Externalid: externalId,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, clientID, id)
|
|
|
|
return nil
|
|
})
|
|
require.NoError(t, err)
|
|
}
|