package integration_test import ( "context" "fmt" "os" "path" "queryorchestration/internal/server/runner" "queryorchestration/internal/serviceconfig/objectstore" documentcleanc "queryorchestration/internal/serviceconfig/queue/documentclean" "queryorchestration/internal/test" queryservice "queryorchestration/pkg/queryService" "regexp" "strings" "testing" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/stretchr/testify/assert" ) type DocInitConfig struct { runner.BaseConfig documentcleanc.DocCleanConfig objectstore.ObjectStoreConfig } func TestDocInitRunner(t *testing.T) { t.SkipNow() ctx := context.Background() cfg := &DocInitConfig{} test.SetCfgProvider(t, cfg) cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../..")) network, ncleanup := test.CreateNetwork(t, ctx) defer ncleanup() acfg, clean := test.CreateAWSContainer(t, ctx, &test.CreateAWSConfig{ Cfg: cfg, Network: network, }) defer clean() err := cfg.SetQueueClient(ctx) assert.NoError(t, err) test.CreateStoreClient(t, ctx, cfg, acfg.ExternalEndpoint) doccleanurl := test.CreateQueue(t, ctx, cfg, "docclean") bucketName := "docinitbucket" test.CreateBucket(t, ctx, cfg, bucketName) arn := fmt.Sprintf("arn:aws:sqs:%s:000000000000:%s", cfg.AWSRegion, test.DocInitRunner) _, err = cfg.StoreClient.PutBucketNotificationConfiguration(ctx, &s3.PutBucketNotificationConfigurationInput{ Bucket: &bucketName, NotificationConfiguration: &types.NotificationConfiguration{ QueueConfigurations: []types.QueueConfiguration{ { QueueArn: &arn, Events: []types.Event{ types.EventS3ObjectCreated, }, }, }, }, }) assert.NoError(t, err) net, cleanup := test.CreateRunnersAndServicesNetwork(t, ctx, &test.EcosystemNetworkConfig{ Cfg: cfg, Network: network, Runners: []*test.RunnerNetworkConfig{ { Name: test.DocInitRunner, Env: map[string]string{ "DOCUMENT_CLEAN_URL": doccleanurl, }, }, }, Services: []*test.ServiceNetworkConfig{ { Name: test.QueryService, }, }, }) defer cleanup() qService, err := queryservice.NewClientWithResponses(net.Services[test.QueryService].URI) assert.NoError(t, err) clientRes, err := qService.CreateClientWithResponse(ctx, queryservice.ClientCreate{ Name: "example_name", }) assert.NoError(t, err) jobRes, err := qService.CreateJobWithResponse(ctx, queryservice.JobCreate{ ClientId: clientRes.JSON201.Id, }) assert.NoError(t, err) canSync := true _, err = qService.UpdateClientWithResponse(ctx, clientRes.JSON201.Id, queryservice.ClientUpdate{ CanSync: &canSync, }) assert.NoError(t, err) _, err = qService.UpdateJobWithResponse(ctx, jobRes.JSON201.Id, queryservice.JobUpdate{ CanSync: &canSync, }) assert.NoError(t, err) location := fmt.Sprintf("%s/%s/%s", clientRes.JSON201.Id, jobRes.JSON201.Id, "object_name") body := strings.NewReader("hello world") _, err = cfg.StoreClient.PutObject(ctx, &s3.PutObjectInput{ Bucket: &bucketName, Key: &location, Body: body, }) assert.NoError(t, err) resRegex := regexp.MustCompile(`{"id": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"`) test.AssertMessageBody(t, ctx, cfg, doccleanurl, resRegex) }