59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package query_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"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(),
|
|
Type: queryprocessor.TypeJsonExtractor,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(1),
|
|
RequiredQueryIDs: []uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: config,
|
|
}
|
|
update := &queryprocessor.Update{
|
|
ID: existing.ID,
|
|
RequiredQueryIDs: []uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: config,
|
|
}
|
|
|
|
dbReqIDs := database.MustToDBUUIDArray(existing.RequiredQueryIDs)
|
|
|
|
pool.ExpectQuery("name: GetQuery :one").WithArgs(database.MustToDBUUID(update.ID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(existing.ID), repository.QuerytypeJsonExtractor, existing.ActiveVersion, existing.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
err = svc.Update(ctx, update)
|
|
assert.Nil(t, err)
|
|
}
|