package storeeventrunner import ( "regexp" "testing" "time" "queryorchestration/internal/database/repository" documentstore "queryorchestration/internal/document/store" "queryorchestration/internal/server/runner" "queryorchestration/internal/serviceconfig/objectstore" "queryorchestration/internal/serviceconfig/queue" "queryorchestration/internal/serviceconfig/queue/documentinit" "queryorchestration/internal/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) type DocInitConfig struct { runner.BaseConfig[S3EventNotification] documentinit.DocInitConfig queue.QueueConfig objectstore.ObjectStoreConfig } func TestStoreEventRunner(t *testing.T) { cfg := &DocInitConfig{} test.CreateDB(t, cfg) acfg := test.CreateAWSContainer(t, cfg) test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint) cfg.DocInitURL = test.CreateQueue(t, cfg, test.DocInitRunnerName) runner := New(&Services{ documentstore.New(cfg), }) clientId := "hi" bucketName := "bucketName" location := objectstore.BucketKey{ Location: objectstore.Import, ClientID: clientId, CreatedAt: time.Now().UTC(), EntityID: uuid.New(), } doc := S3EventNotification{ Records: []S3EventRecord{ { EventName: EventS3ObjectCreatedPut, S3: S3EventRecordDetails{ Bucket: S3Bucket{ Name: bucketName, }, Object: S3Object{ Key: location.String(), ETag: "example_hash", }, }, }, }, } err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{ Clientid: clientId, Name: "name", }) require.NoError(t, err) assert.True(t, runner.Process(t.Context(), doc)) test.AssertMessageBody(t, cfg, cfg.GetDocInitURL(), regexp.MustCompile(`^\{"bucket":"bucketName","key":"hi\/import\/.+\/0\/.+","hash":"example_hash"\}$`)) }