Files
query-orchestration/internal/query/update_test.go
T

55 lines
1.5 KiB
Go
Raw Normal View History

2025-01-07 16:30:45 +00:00
package query_test
2025-01-06 14:40:43 +00:00
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/query"
queryprocessor "queryorchestration/internal/query/processor"
2025-01-06 14:40:43 +00:00
"testing"
"github.com/google/uuid"
2025-01-20 13:31:48 +00:00
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
2025-01-06 14:40:43 +00:00
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestUpdate(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)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
svc := query.New(db)
config := "{\"path\":\"example_path\"}"
existing := query.Query{
ID: uuid.New(),
ActiveVersion: int32(1),
LatestVersion: int32(1),
}
update := &queryprocessor.Update{
ID: existing.ID,
}
pool.ExpectQuery("name: GetQuery :one").WithArgs(database.MustToDBUUID(update.ID)).WillReturnRows(
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
2025-01-20 13:31:48 +00:00
AddRow(database.MustToDBUUID(existing.ID), repository.QuerytypeJsonExtractor, existing.ActiveVersion, existing.LatestVersion, []byte(config), []pgtype.UUID{}),
2025-01-06 14:40:43 +00:00
)
2025-01-20 13:31:48 +00:00
pool.ExpectBeginTx(pgx.TxOptions{})
pool.ExpectExec("name: UpdateQuery :exec").WithArgs(int32(1), int32(2), database.MustToDBUUID(update.ID)).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
2025-01-06 14:40:43 +00:00
err = svc.Update(ctx, update)
assert.Nil(t, err)
}