7001ca854c
Queuing Changes and Cfg Testing * staarting * staarting * startedpush * note * save * mocking * removederrs * fixtests * cleanuperrs * newenvsetup * preppingtests * queue * mmovetocfgpassunittests * sortoutconfig * passinginteg * deps * fixtests
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package collector_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
documentclean "queryorchestration/internal/document/clean"
|
|
documenttext "queryorchestration/internal/document/text"
|
|
"queryorchestration/internal/job/collector"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"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)
|
|
}
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := collector.New(cfg, &collector.Services{
|
|
Clean: documentclean.New(),
|
|
Text: documenttext.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), current.MinCleanVersion, current.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.NoError(t, err)
|
|
}
|