2025-02-12 19:00:25 +00:00
|
|
|
package endtoend_test
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-02-06 15:00:26 +00:00
|
|
|
"fmt"
|
2025-02-03 17:30:50 +00:00
|
|
|
"os"
|
|
|
|
|
"path"
|
2025-02-07 12:12:51 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-02-05 12:52:41 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
|
|
|
documentcleanc "queryorchestration/internal/serviceconfig/queue/documentclean"
|
2025-02-03 17:30:50 +00:00
|
|
|
"queryorchestration/internal/test"
|
|
|
|
|
queryservice "queryorchestration/pkg/queryService"
|
2025-02-05 17:44:01 +00:00
|
|
|
"strings"
|
2025-02-03 17:30:50 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-02-05 17:44:01 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
2025-02-11 15:22:59 +00:00
|
|
|
awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
|
|
|
|
"github.com/oapi-codegen/runtime/types"
|
2025-02-03 17:30:50 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
type ProcessConfig struct {
|
|
|
|
|
serviceconfig.BaseConfig
|
2025-02-05 12:52:41 +00:00
|
|
|
documentcleanc.DocCleanConfig
|
|
|
|
|
objectstore.ObjectStoreConfig
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
func TestProcess(t *testing.T) {
|
2025-02-05 12:52:41 +00:00
|
|
|
t.SkipNow()
|
2025-02-03 17:30:50 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
cfg := &ProcessConfig{}
|
2025-02-05 12:52:41 +00:00
|
|
|
test.SetCfgProvider(t, cfg)
|
2025-02-07 12:12:51 +00:00
|
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), ".."))
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
network, ncleanup := test.CreateNetwork(t, ctx)
|
|
|
|
|
defer ncleanup()
|
|
|
|
|
|
2025-02-05 12:52:41 +00:00
|
|
|
acfg, clean := test.CreateAWSContainer(t, ctx, &test.CreateAWSConfig{
|
2025-02-03 17:30:50 +00:00
|
|
|
Cfg: cfg,
|
|
|
|
|
Network: network,
|
|
|
|
|
})
|
2025-02-05 12:52:41 +00:00
|
|
|
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)
|
2025-02-06 15:00:26 +00:00
|
|
|
arn := fmt.Sprintf("arn:aws:sqs:%s:000000000000:%s", cfg.AWSRegion, test.DocInitRunner)
|
|
|
|
|
_, err = cfg.StoreClient.PutBucketNotificationConfiguration(ctx, &s3.PutBucketNotificationConfigurationInput{
|
|
|
|
|
Bucket: &bucketName,
|
2025-02-11 15:22:59 +00:00
|
|
|
NotificationConfiguration: &awstypes.NotificationConfiguration{
|
|
|
|
|
QueueConfigurations: []awstypes.QueueConfiguration{
|
2025-02-06 15:00:26 +00:00
|
|
|
{
|
|
|
|
|
QueueArn: &arn,
|
2025-02-11 15:22:59 +00:00
|
|
|
Events: []awstypes.Event{
|
|
|
|
|
awstypes.EventS3ObjectCreated,
|
2025-02-06 15:00:26 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
assert.NoError(t, err)
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-02-12 19:00:25 +00:00
|
|
|
docsyncurl := test.CreateQueue(t, ctx, cfg, test.DocSyncRunner)
|
2025-02-07 12:12:51 +00:00
|
|
|
doccleanurl := test.CreateQueue(t, ctx, cfg, test.DocCleanRunner)
|
2025-02-07 14:15:06 +00:00
|
|
|
doctexturl := test.CreateQueue(t, ctx, cfg, test.DocTextRunner)
|
|
|
|
|
querysyncurl := test.CreateQueue(t, ctx, cfg, test.QuerySyncRunner)
|
2025-02-11 15:22:59 +00:00
|
|
|
queryurl := test.CreateQueue(t, ctx, cfg, test.QueryRunner)
|
2025-02-12 19:00:25 +00:00
|
|
|
jobsyncurl := test.CreateQueue(t, ctx, cfg, test.JobSyncRunner)
|
2025-02-07 12:12:51 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
net, cleanup := test.CreateRunnersAndServicesNetwork(t, ctx, &test.EcosystemNetworkConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
Network: network,
|
|
|
|
|
Runners: []*test.RunnerNetworkConfig{
|
|
|
|
|
{
|
|
|
|
|
Name: test.DocInitRunner,
|
2025-02-12 19:00:25 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
|
"DOCUMENT_SYNC_URL": docsyncurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: test.DocSyncRunner,
|
2025-02-03 17:30:50 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
|
"DOCUMENT_CLEAN_URL": doccleanurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-07 12:12:51 +00:00
|
|
|
{
|
|
|
|
|
Name: test.DocCleanRunner,
|
|
|
|
|
Env: map[string]string{
|
|
|
|
|
"DOCUMENT_TEXT_URL": doctexturl,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-07 14:15:06 +00:00
|
|
|
{
|
|
|
|
|
Name: test.DocTextRunner,
|
|
|
|
|
Env: map[string]string{
|
|
|
|
|
"QUERY_SYNC_URL": querysyncurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-11 15:22:59 +00:00
|
|
|
{
|
|
|
|
|
Name: test.QuerySyncRunner,
|
|
|
|
|
Env: map[string]string{
|
|
|
|
|
"QUERY_URL": queryurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: test.QueryRunner,
|
|
|
|
|
Env: map[string]string{
|
|
|
|
|
"QUERY_URL": queryurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-12 19:00:25 +00:00
|
|
|
{
|
|
|
|
|
Name: test.JobSyncRunner,
|
|
|
|
|
Env: map[string]string{
|
|
|
|
|
"DOCUMENT_SYNC_URL": docsyncurl,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-03 17:30:50 +00:00
|
|
|
},
|
|
|
|
|
Services: []*test.ServiceNetworkConfig{
|
|
|
|
|
{
|
|
|
|
|
Name: test.QueryService,
|
2025-02-12 19:00:25 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
|
"JOB_SYNC_URL": jobsyncurl,
|
|
|
|
|
},
|
2025-02-03 17:30:50 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
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)
|
|
|
|
|
|
2025-02-06 15:00:26 +00:00
|
|
|
location := fmt.Sprintf("%s/%s/%s", clientRes.JSON201.Id, jobRes.JSON201.Id, "object_name")
|
2025-02-05 17:44:01 +00:00
|
|
|
body := strings.NewReader("hello world")
|
|
|
|
|
_, err = cfg.StoreClient.PutObject(ctx, &s3.PutObjectInput{
|
|
|
|
|
Bucket: &bucketName,
|
|
|
|
|
Key: &location,
|
|
|
|
|
Body: body,
|
|
|
|
|
})
|
|
|
|
|
assert.NoError(t, err)
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|