Files
query-orchestration/test/process_test.go
T

167 lines
4.4 KiB
Go
Raw Normal View History

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"
"strings"
"testing"
"github.com/aws/aws-sdk-go-v2/service/s3"
awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/oapi-codegen/runtime/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: &awstypes.NotificationConfiguration{
QueueConfigurations: []awstypes.QueueConfiguration{
{
QueueArn: &arn,
Events: []awstypes.Event{
awstypes.EventS3ObjectCreated,
},
},
},
},
})
assert.NoError(t, err)
doccleanurl := test.CreateQueue(t, ctx, cfg, test.DocCleanRunner)
doctexturl := test.CreateQueue(t, ctx, cfg, test.DocTextRunner)
querysyncurl := test.CreateQueue(t, ctx, cfg, test.QuerySyncRunner)
queryurl := test.CreateQueue(t, ctx, cfg, test.QueryRunner)
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,
},
},
{
Name: test.DocTextRunner,
Env: map[string]string{
"QUERY_SYNC_URL": querysyncurl,
},
},
{
Name: test.QuerySyncRunner,
Env: map[string]string{
"QUERY_URL": queryurl,
},
},
{
Name: test.QueryRunner,
Env: map[string]string{
"QUERY_URL": queryurl,
},
},
},
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)
contextQueryRes, err := qService.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.CONTEXTFULL,
})
assert.NoError(t, err)
jsonQueryRes, err := qService.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.JSONEXTRACTOR,
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
})
assert.NoError(t, err)
newActiveVersion := int32(2)
_, err = qService.UpdateJobCollectorByJobIdWithResponse(ctx, jobRes.JSON201.Id, queryservice.JobCollectorUpdate{
ActiveVersion: &newActiveVersion,
Fields: &[]queryservice.JobCollectorField{
{
Name: "JSON_QUERY",
QueryId: jsonQueryRes.JSON201.Id,
},
},
})
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)
}