Merged in feature/jobsync (pull request #63)
Document Sync and Job Sync * docsyncfunc * startedQueryWork * morefixes * jobsyncsvcstart * save * jobsynctext * save * save * docsync * shorttest * jobsync * jobsyncupdateoncollectorupdate * passlivetest * collectortest * lint
This commit is contained in:
@@ -5,30 +5,28 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
docinitrunner "queryorchestration/api/docInitRunner"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
documentinit "queryorchestration/internal/document/init"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||
objectstoremock "queryorchestration/mocks/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue/documentsync"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type DocInitConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
documentclean.DocCleanConfig
|
||||
objectstore.ObjectStoreConfig
|
||||
documentsync.DocSyncConfig
|
||||
}
|
||||
|
||||
func TestDocInitRunner(t *testing.T) {
|
||||
@@ -42,16 +40,11 @@ func TestDocInitRunner(t *testing.T) {
|
||||
cfg := &DocInitConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
mockStore := objectstoremock.NewMockS3Client(t)
|
||||
cfg.StoreClient = mockStore
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg.QueueClient = mockSQS
|
||||
|
||||
runner := docinitrunner.New(validator.New(), &docinitrunner.Services{
|
||||
Document: documentinit.New(cfg, &documentinit.Services{
|
||||
Job: job.New(cfg, &job.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
Client: client.New(cfg),
|
||||
}),
|
||||
}),
|
||||
Document: documentinit.New(cfg),
|
||||
})
|
||||
assert.NotNil(t, runner)
|
||||
|
||||
@@ -60,10 +53,11 @@ func TestDocInitRunner(t *testing.T) {
|
||||
ClientID: uuid.New(),
|
||||
}
|
||||
bucketName := "bucketName"
|
||||
location := fmt.Sprintf("aaa/%s/aaa", j.ID.String())
|
||||
location := fmt.Sprintf("%s/%s/aaa", j.ClientID.String(), j.ID.String())
|
||||
docinfo := document.Document{
|
||||
ID: uuid.New(),
|
||||
Hash: "example_hash",
|
||||
ID: uuid.New(),
|
||||
JobID: j.ID,
|
||||
Hash: "example_hash",
|
||||
}
|
||||
doc := docinitrunner.S3EventNotification{
|
||||
Records: []docinitrunner.S3EventRecord{
|
||||
@@ -88,14 +82,6 @@ func TestDocInitRunner(t *testing.T) {
|
||||
Body: &body,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetJob :one").WithArgs(database.MustToDBUUID(j.ID)).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(j.ID), database.MustToDBUUID(j.ClientID), j.CanSync),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
|
||||
)
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(docinfo.Hash, database.MustToDBUUID(j.ID)).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
@@ -108,6 +94,21 @@ func TestDocInitRunner(t *testing.T) {
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(docinfo.ID), bucketName, location).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "jobId", "hash"}).
|
||||
AddRow(database.MustToDBUUID(docinfo.ID), database.MustToDBUUID(docinfo.JobID), "example"),
|
||||
)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == cfg.DocumentSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", docinfo.ID.String())
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
err = runner.Process(ctx, msg)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user