package test import ( "context" "fmt" "io" "log/slog" "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) slog.Info("create bucket", "bucket", name) 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) slog.Info("set bucket notifs", "bucket", name, "queueARN", arn) } 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) slog.Info("put object", "bucket", bucket, "key", location) }