Files
query-orchestration/internal/test/objectstore_test.go
T
Michael McGuinness 1d49313a9f Merged in feature/standardisefilepath (pull request #111)
Feature/standardisefilepath

* baseprocessing

* generalstructure
2025-04-03 12:13:16 +00:00

88 lines
1.9 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) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &StoreConfig{}
SetCfgProvider(t, cfg)
acfg, cleanup := CreateAWSContainer(t, ctx, cfg, &CreateAWSConfig{})
defer cleanup()
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
CreateBucket(t, ctx, cfg, "myname")
}
func TestCreateStoreClient(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &StoreConfig{}
SetCfgProvider(t, cfg)
acfg, cleanup := CreateAWSContainer(t, ctx, cfg, &CreateAWSConfig{})
defer cleanup()
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
assert.NotNil(t, cfg.GetStoreClient())
}
func TestPutObject(t *testing.T) {
ctx := context.Background()
cfg := &StoreConfig{}
SetCfgProvider(t, cfg)
mockS3 := objectstoremock.NewMockS3Client(t)
cfg.StoreClient = mockS3
bucketName := "bucket"
file := strings.NewReader("hello")
key := objectstore.BucketKey{
ClientID: "byebye",
Filename: "hello",
}
mockS3.EXPECT().
PutObject(
mock.Anything,
mock.MatchedBy(func(in *s3.PutObjectInput) bool {
return *in.Bucket == bucketName && *in.Key == key.String()
}),
mock.Anything,
).
Return(&s3.PutObjectOutput{}, nil)
PutObject(t, ctx, cfg, PutObjectParams{
Bucket: bucketName,
File: file,
Key: key,
})
}