b16ff55afa
Document CRUD * doccreate * dochashlocandget * depsandtodo
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package documentsync
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/job/collector"
|
|
"queryorchestration/internal/query/result"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetResults(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,
|
|
}
|
|
|
|
doc := Document{
|
|
ID: uuid.New(),
|
|
JobID: uuid.New(),
|
|
}
|
|
|
|
coll := collector.Collector{
|
|
ID: uuid.New(),
|
|
JobID: doc.JobID,
|
|
MinCleanVersion: int32(1),
|
|
MinTextVersion: int32(2),
|
|
}
|
|
results := []*result.Result{
|
|
{
|
|
ID: uuid.New(),
|
|
QueryID: uuid.New(),
|
|
QueryVersion: 2,
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListResultsByDocumentID :many").WithArgs(database.MustToDBUUID(doc.ID), coll.MinCleanVersion, coll.MinTextVersion).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "queryId", "queryVersion"}).
|
|
AddRow(database.MustToDBUUID(results[0].ID), database.MustToDBUUID(results[0].QueryID), results[0].QueryVersion),
|
|
)
|
|
|
|
docSvc := Service{
|
|
db: db,
|
|
}
|
|
res, err := docSvc.getResults(ctx, doc.ID, &coll)
|
|
assert.Nil(t, err)
|
|
assert.ElementsMatch(t, results, res)
|
|
}
|