package documentstore import ( "testing" "time" "queryorchestration/internal/serviceconfig" "queryorchestration/internal/serviceconfig/objectstore" "queryorchestration/internal/serviceconfig/queue/documentinit" queuemock "queryorchestration/mocks/queue" "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) type ProcessConfig struct { serviceconfig.BaseConfig documentinit.DocInitConfig } func TestProcess(t *testing.T) { ctx := t.Context() cfg := &ProcessConfig{} mockSQS := queuemock.NewMockSQSClient(t) cfg.QueueClient = mockSQS cfg.DocInitURL = "docinit" svc := New(cfg) t.Run("invalid event", func(t *testing.T) { err := svc.Process(ctx, Params{ Event: EventS3("invalid"), }) assert.NoError(t, err) }) t.Run("invalid key", func(t *testing.T) { err := svc.Process(ctx, Params{ Event: EventS3ObjectCreatedPut, Key: "7db16095-9155-47d4-8004-b3b3ead93c83/invalid", }) assert.NoError(t, err) }) t.Run("document init", func(t *testing.T) { mockSQS.EXPECT(). SendMessage( mock.Anything, mock.MatchedBy(func(in *sqs.SendMessageInput) bool { return *in.QueueUrl == cfg.DocInitURL }), mock.Anything, ). Return(&sqs.SendMessageOutput{}, nil) location := objectstore.BucketKey{ ClientID: "7db16095-9155-47d4-8004-b3b3ead93c83", Location: objectstore.Import, CreatedAt: time.Now().UTC(), } err := svc.Process(ctx, Params{ Event: EventS3ObjectCreatedPut, Key: location.String(), }) assert.NoError(t, err) }) } func TestIsSupportedEvent(t *testing.T) { svc := Service{} t.Run("put", func(t *testing.T) { assert.True(t, svc.isSupportedEvent(EventS3ObjectCreatedPut)) }) t.Run("invalid", func(t *testing.T) { assert.False(t, svc.isSupportedEvent("invalid")) }) }