5c253b3592
Feature/docinit * createunittests * cleanup * skip * cleanup
115 lines
2.9 KiB
Go
115 lines
2.9 KiB
Go
package integration_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
documentinit "queryorchestration/internal/document/init"
|
|
"queryorchestration/internal/server/runner"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
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/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)
|
|
|
|
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 := "/i/am/here"
|
|
body := strings.NewReader("hello world")
|
|
_, err = cfg.StoreClient.PutObject(ctx, &s3.PutObjectInput{
|
|
Bucket: &bucketName,
|
|
Key: &location,
|
|
Body: body,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
err = cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: net.Runners[test.DocInitRunner].URI,
|
|
Body: documentinit.Create{
|
|
JobID: jobRes.JSON201.Id,
|
|
Location: location,
|
|
},
|
|
})
|
|
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)
|
|
}
|