2025-04-02 18:50:03 +00:00
|
|
|
package docinitrunner_test
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
import (
|
2025-05-23 00:20:01 +00:00
|
|
|
"regexp"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
2025-04-03 19:17:24 +00:00
|
|
|
"time"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
docinitrunner "queryorchestration/api/docInitRunner"
|
2025-02-03 17:30:50 +00:00
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
documentinit "queryorchestration/internal/document/init"
|
2025-04-02 18:50:03 +00:00
|
|
|
"queryorchestration/internal/server/runner"
|
2025-04-03 12:13:16 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
2025-05-23 00:20:01 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/queue"
|
2025-02-12 19:00:25 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/queue/documentsync"
|
2025-05-20 12:47:22 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-02-03 17:30:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DocInitConfig struct {
|
2025-04-02 18:50:03 +00:00
|
|
|
runner.BaseConfig[docinitrunner.Body]
|
2025-02-12 19:00:25 +00:00
|
|
|
documentsync.DocSyncConfig
|
2025-05-23 00:20:01 +00:00
|
|
|
queue.QueueConfig
|
|
|
|
|
objectstore.ObjectStoreConfig
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDocInitRunner(t *testing.T) {
|
|
|
|
|
cfg := &DocInitConfig{}
|
2025-05-23 00:20:01 +00:00
|
|
|
test.CreateDB(t, cfg)
|
|
|
|
|
acfg := test.CreateAWSContainer(t, cfg)
|
2025-05-20 12:47:22 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
|
|
|
|
cfg.DocumentSyncURL = test.CreateQueue(t, cfg, test.DocSyncRunnerName)
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-04-22 14:40:16 +00:00
|
|
|
runner := docinitrunner.New(&docinitrunner.Services{
|
2025-02-12 19:00:25 +00:00
|
|
|
Document: documentinit.New(cfg),
|
2025-02-03 17:30:50 +00:00
|
|
|
})
|
|
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
|
|
|
|
Clientid: "clientid",
|
|
|
|
|
Name: "client_name",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
2025-03-05 19:49:03 +00:00
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
location := objectstore.BucketKey{
|
|
|
|
|
Location: objectstore.Import,
|
|
|
|
|
ClientID: "clientid",
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
}
|
|
|
|
|
doc := docinitrunner.Body{
|
|
|
|
|
Bucket: "bucket",
|
|
|
|
|
Key: location.String(),
|
|
|
|
|
Hash: "hash",
|
|
|
|
|
}
|
2025-03-05 19:49:03 +00:00
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
assert.True(t, runner.Process(t.Context(), doc))
|
2025-05-23 00:20:01 +00:00
|
|
|
|
|
|
|
|
test.AssertMessageBody(t, cfg, cfg.GetDocumentSyncURL(), regexp.MustCompile(`{"id":".+"}`))
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|