81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
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/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, StoreEventRunnerName)
|
|
_, 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)
|
|
}
|
|
|
|
type PutObjectParams struct {
|
|
ClientId string
|
|
Bucket string
|
|
Filepath string
|
|
File io.Reader
|
|
}
|
|
|
|
func PutObject(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, params PutObjectParams) {
|
|
location := fmt.Sprintf("%s/%s", params.ClientId, params.Filepath)
|
|
_, err := cfg.GetStoreClient().PutObject(ctx, &s3.PutObjectInput{
|
|
Bucket: ¶ms.Bucket,
|
|
Key: &location,
|
|
Body: params.File,
|
|
})
|
|
require.NoError(t, err)
|
|
slog.Info("put object", "bucket", params.Bucket, "key", location)
|
|
}
|
|
|
|
func PutImportObject(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, params PutObjectParams) {
|
|
params.Filepath = fmt.Sprintf("import/%s", params.Filepath)
|
|
PutObject(t, ctx, cfg, params)
|
|
}
|
|
|
|
func PutTextractObject(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, params PutObjectParams) {
|
|
params.Filepath = fmt.Sprintf("text/textract/%s", params.Filepath)
|
|
PutObject(t, ctx, cfg, params)
|
|
}
|