730f3ba11a
support folder paths * support folder paths * s3 storage docs
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package docinitrunner_test
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
|
|
docinitrunner "queryorchestration/api/docInitRunner"
|
|
"queryorchestration/internal/database/repository"
|
|
documentinit "queryorchestration/internal/document/init"
|
|
"queryorchestration/internal/server/runner"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
"queryorchestration/internal/serviceconfig/queue/documentsync"
|
|
"queryorchestration/internal/test"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type DocInitConfig struct {
|
|
runner.BaseConfig[docinitrunner.Body]
|
|
documentsync.DocSyncConfig
|
|
queue.QueueConfig
|
|
objectstore.ObjectStoreConfig
|
|
}
|
|
|
|
// stringPtr returns a pointer to a string
|
|
func stringPtr(s string) *string {
|
|
return &s
|
|
}
|
|
|
|
func TestDocInitRunner(t *testing.T) {
|
|
cfg := &DocInitConfig{}
|
|
test.CreateDB(t, cfg)
|
|
acfg := test.CreateAWSContainer(t, cfg)
|
|
|
|
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
|
cfg.DocumentSyncURL = test.CreateQueue(t, cfg, test.DocSyncRunnerName)
|
|
|
|
runner := docinitrunner.New(&docinitrunner.Services{
|
|
Document: documentinit.New(cfg),
|
|
Queries: cfg.GetDBQueries(),
|
|
})
|
|
|
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
|
Clientid: "clientid",
|
|
Name: "client_name",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
location := objectstore.BucketKey{
|
|
Location: objectstore.Import,
|
|
ClientID: "clientid",
|
|
CreatedAt: time.Now().UTC(),
|
|
}
|
|
|
|
// Create a document upload record to simulate the upload pipeline
|
|
uploadID := uuid.New()
|
|
err = cfg.GetDBQueries().AddDocumentUpload(t.Context(), &repository.AddDocumentUploadParams{
|
|
ID: uploadID,
|
|
Clientid: "clientid",
|
|
Bucket: "bucket",
|
|
Key: location.String(),
|
|
Part: 1,
|
|
Createdat: pgtype.Timestamp{
|
|
Valid: true,
|
|
Time: time.Now().UTC(),
|
|
},
|
|
Filename: stringPtr("test-document.pdf"),
|
|
BatchID: nil,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
doc := docinitrunner.Body{
|
|
Bucket: "bucket",
|
|
Key: location.String(),
|
|
Hash: "hash",
|
|
}
|
|
|
|
assert.True(t, runner.Process(t.Context(), doc))
|
|
|
|
test.AssertMessageBody(t, cfg, cfg.GetDocumentSyncURL(), regexp.MustCompile(`{"id":".+"}`))
|
|
}
|