b16ff55afa
Document CRUD * doccreate * dochashlocandget * depsandtodo
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package collector_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
documentclean "queryorchestration/internal/document/clean"
|
|
"queryorchestration/internal/job/collector"
|
|
"queryorchestration/internal/query"
|
|
textextraction "queryorchestration/internal/text_extraction"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
"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 := collector.New(db, &collector.Services{
|
|
Query: query.New(db),
|
|
DocumentClean: documentclean.New(),
|
|
TextExtraction: textextraction.New(),
|
|
})
|
|
|
|
current := collector.Collector{
|
|
ID: uuid.New(),
|
|
JobID: uuid.New(),
|
|
ActiveVersion: 1,
|
|
LatestVersion: 4,
|
|
}
|
|
av := int32(2)
|
|
update := collector.UpdateParams{
|
|
JobID: current.JobID,
|
|
ActiveVersion: &av,
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(update.JobID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
AddRow(database.MustToDBUUID(current.ID), database.MustToDBUUID(current.JobID), ¤t.MinCleanVersion, ¤t.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
|
)
|
|
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
pool.ExpectExec("name: UpdateCollector :exec").WithArgs(int32(5), int32(2), database.MustToDBUUID(current.ID)).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
pool.ExpectCommit()
|
|
|
|
err = svc.UpdateByJobId(ctx, &update)
|
|
assert.Nil(t, err)
|
|
}
|