71f9802e1a
Split Query Running + Debugging Full Flow * completedquerysyncrunner * spliitinglogic * synccomplete * informdependents * only push same collector * deps * livetesting * foundissue * some issues resolved * activeupdate * collectorupdatefixes * fix dbquesries * tests * tests * pollingdebug
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package documentclean
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue/documenttext"
|
|
queuemock "queryorchestration/mocks/queue"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
type DocCleanConfig struct {
|
|
serviceconfig.BaseConfig
|
|
documenttext.DocTextConfig
|
|
objectstore.ObjectStoreConfig
|
|
}
|
|
|
|
func TestCreate(t *testing.T) {
|
|
ctx := context.Background()
|
|
pool, err := pgxmock.NewPool()
|
|
if err != nil {
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
}
|
|
|
|
mockSQS := queuemock.NewMockSQSClient(t)
|
|
|
|
cfg := &DocCleanConfig{}
|
|
cfg.QueueClient = mockSQS
|
|
cfg.DocumentTextURL = "/i/am/here"
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := Service{
|
|
cfg: cfg,
|
|
svc: &Services{
|
|
Document: document.New(cfg),
|
|
},
|
|
}
|
|
|
|
id := uuid.New()
|
|
inloc := document.Location{
|
|
Bucket: "bucket_name",
|
|
Key: "/i/am/here",
|
|
}
|
|
|
|
pool.ExpectQuery("name: IsDocumentClean :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"isclean"}).
|
|
AddRow(false),
|
|
)
|
|
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
|
|
AddRow(database.MustToDBUUID(id), inloc.Bucket, inloc.Key),
|
|
)
|
|
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(database.MustToDBUUID(id), int32(1), inloc.Bucket, inloc.Key).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
|
|
mockSQS.EXPECT().
|
|
SendMessage(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
|
return *in.QueueUrl == cfg.DocumentTextURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", id)
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&sqs.SendMessageOutput{}, nil)
|
|
|
|
err = svc.Clean(ctx, id)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestInformClean(t *testing.T) {
|
|
ctx := context.Background()
|
|
mockSQS := queuemock.NewMockSQSClient(t)
|
|
|
|
cfg := &DocCleanConfig{}
|
|
cfg.QueueClient = mockSQS
|
|
cfg.DocumentTextURL = "/i/am/here"
|
|
svc := Service{
|
|
cfg: cfg,
|
|
}
|
|
id := uuid.New()
|
|
|
|
mockSQS.EXPECT().
|
|
SendMessage(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
|
return *in.QueueUrl == cfg.DocumentTextURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", id)
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&sqs.SendMessageOutput{}, nil)
|
|
|
|
err := svc.informClean(ctx, id)
|
|
assert.NoError(t, err)
|
|
}
|