60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package document_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestList(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\"}"
|
|
q := query.Query{
|
|
ID: uuid.New(),
|
|
Type: queryprocessor.TypeJsonExtractor,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(1),
|
|
RequiredQueryIDs: []uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: config,
|
|
}
|
|
|
|
dbReqIDs := make([]pgtype.UUID, len(q.RequiredQueryIDs))
|
|
for index, id := range q.RequiredQueryIDs {
|
|
dbReqIDs[index] = database.MustToDBUUID(id)
|
|
}
|
|
|
|
filters := query.ListFilters{}
|
|
|
|
pool.ExpectQuery("name: ListQueries :many").WithArgs().WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(q.ID), repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
resList, err := svc.List(ctx, filters)
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualExportedValues(t, []query.Query{q}, *resList)
|
|
}
|