Files
query-orchestration/internal/test/objectstore_test.go
T

66 lines
1.3 KiB
Go
Raw Normal View History

package test
import (
"context"
"strings"
2025-03-05 12:05:46 +00:00
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/aws"
objectstore "queryorchestration/internal/serviceconfig/objectstore"
objectstoremock "queryorchestration/mocks/objectstore"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/stretchr/testify/mock"
)
type StoreConfig struct {
aws.AWSConfig
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestCreateBucket(t *testing.T) {
2025-04-25 17:02:50 +00:00
t.Parallel()
if testing.Short() {
t.SkipNow()
}
ctx := context.Background()
cfg := &StoreConfig{}
acfg := CreateAWSContainer(t, cfg)
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
2025-04-25 17:02:50 +00:00
CreateBucket(t, ctx, cfg)
}
func TestPutObject(t *testing.T) {
ctx := context.Background()
cfg := &StoreConfig{}
2025-04-25 17:02:50 +00:00
mockS3 := objectstoremock.NewMockS3Client(t)
cfg.StoreClient = mockS3
file := strings.NewReader("hello")
key := objectstore.BucketKey{
ClientID: "byebye",
}
mockS3.EXPECT().
PutObject(
mock.Anything,
mock.MatchedBy(func(in *s3.PutObjectInput) bool {
return *in.Bucket == GetAlias(t, "bucket") && *in.Key == key.String()
}),
mock.Anything,
).
Return(&s3.PutObjectOutput{}, nil)
PutObject(t, ctx, cfg, PutObjectParams{
2025-04-25 17:02:50 +00:00
File: file,
Key: key,
})
}