Files
query-orchestration/internal/test/objectstore_test.go
T
Michael McGuinness 721ca8a6e6 Merged in feature/dockerfileintest (pull request #130)
Dockerfile in Test

* dockerfile

* network

* const
2025-05-03 11:29:10 +00:00

85 lines
1.7 KiB
Go

package test
import (
"context"
"strings"
"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/assert"
"github.com/stretchr/testify/mock"
)
type StoreConfig struct {
aws.AWSConfig
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestCreateBucket(t *testing.T) {
t.Parallel()
if testing.Short() {
t.SkipNow()
}
ctx := context.Background()
cfg := &StoreConfig{}
net := GetNetwork(t, ctx)
acfg := CreateAWSContainer(t, ctx, cfg, net)
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
CreateBucket(t, ctx, cfg)
}
func TestCreateStoreClient(t *testing.T) {
t.Parallel()
if testing.Short() {
t.SkipNow()
}
ctx := context.Background()
cfg := &StoreConfig{}
net := GetNetwork(t, ctx)
acfg := CreateAWSContainer(t, ctx, cfg, net)
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
assert.NotNil(t, cfg.GetStoreClient())
}
func TestPutObject(t *testing.T) {
ctx := context.Background()
cfg := &StoreConfig{}
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 == NormaliseAlias(t.Name()) && *in.Key == key.String()
}),
mock.Anything,
).
Return(&s3.PutObjectOutput{}, nil)
PutObject(t, ctx, cfg, PutObjectParams{
File: file,
Key: key,
})
}