81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
42 lines
941 B
Go
42 lines
941 B
Go
package database_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"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 := "ID"
|
|
clientName := "example_client"
|
|
|
|
pool.ExpectBegin()
|
|
pool.ExpectExec("name: CreateClient :exec").WithArgs(clientID, clientName).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
pool.ExpectCommit()
|
|
|
|
err = cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
|
err := q.CreateClient(ctx, &repository.CreateClientParams{
|
|
Name: clientName,
|
|
ID: clientID,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
})
|
|
require.NoError(t, err)
|
|
}
|