Files
query-orchestration/internal/test/objectstore.go
T
Michael McGuinness 6648cdf1cb Merged in feature/clientexternalid (pull request #99)
Client External ID

* normalizeexternalid

* cleanopenapi

* cleanopenapi

* changingpublic

* noprecommit

* testing

* precommit

* processtest

* nodb

* tests

* tests
2025-03-11 16:31:06 +00:00

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)
}
func SetBucketNotifs(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, name string) {
arn := fmt.Sprintf("arn:aws:sqs:%s:000000000000:%s", cfg.GetAWSRegion(), DocInitRunner)
_, 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) string {
location := fmt.Sprintf("%s/%s", clientId, filename)
_, err := cfg.GetStoreClient().PutObject(ctx, &s3.PutObjectInput{
Bucket: &bucket,
Key: &location,
Body: file,
})
require.NoError(t, err)
return location
}