Files
query-orchestration/test/process_test.go
T
Michael McGuinness 90353d8161 Merged in feature/docclean (pull request #55)
Doc Clean Structure

* outline

* isdocclean

* placeholder for clean log

* versionplustesting

* versionplustesting

* testspassed
2025-02-07 12:12:51 +00:00

129 lines
3.4 KiB
Go

package integration_test
import (
"context"
"fmt"
"os"
"path"
"queryorchestration/internal/serviceconfig"
"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 ProcessConfig struct {
serviceconfig.BaseConfig
documentcleanc.DocCleanConfig
objectstore.ObjectStoreConfig
}
func TestProcess(t *testing.T) {
t.SkipNow()
ctx := context.Background()
cfg := &ProcessConfig{}
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)
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)
doccleanurl := test.CreateQueue(t, ctx, cfg, test.DocCleanRunner)
doctexturl := test.CreateQueue(t, ctx, cfg, "doctextrunner")
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,
},
},
{
Name: test.DocCleanRunner,
Env: map[string]string{
"DOCUMENT_TEXT_URL": doctexturl,
},
},
},
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, doctexturl, resRegex)
}