555b6d420b
Document Result Endpoint * testing * cleantesting * progress * query * lint * readme * dockerclient * api * passtest * tests * test
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
objectstore "queryorchestration/internal/serviceconfig/objectstore"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"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/require"
|
|
)
|
|
|
|
func CreateBucket(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, name string) {
|
|
_, err := cfg.GetStoreClient().CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: aws.String(name),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = cfg.PingStoreByName(ctx, name)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
const BucketName = "documentbucket"
|
|
|
|
func SetBucketNotifs(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, name string) {
|
|
arn := GetQueueArn(cfg, DocInitRunnerName)
|
|
_, err := cfg.GetStoreClient().PutBucketNotificationConfiguration(ctx, &s3.PutBucketNotificationConfigurationInput{
|
|
Bucket: &name,
|
|
NotificationConfiguration: &awstypes.NotificationConfiguration{
|
|
QueueConfigurations: []awstypes.QueueConfiguration{
|
|
{
|
|
QueueArn: &arn,
|
|
Events: []awstypes.Event{
|
|
awstypes.EventS3ObjectCreated,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
func SetStoreClient(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, endpoint string) {
|
|
cfg.SetS3Endpoint(endpoint)
|
|
cfg.SetS3UsePathStyle(true)
|
|
err := cfg.SetStoreClient(ctx)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func PutObject(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, clientId types.UUID, bucket string, filename string, file io.Reader) {
|
|
location := fmt.Sprintf("%s/%s", clientId, filename)
|
|
_, err := cfg.GetStoreClient().PutObject(ctx, &s3.PutObjectInput{
|
|
Bucket: &bucket,
|
|
Key: &location,
|
|
Body: file,
|
|
})
|
|
require.NoError(t, err)
|
|
}
|