2025-02-05 12:52:41 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-11 16:31:06 +00:00
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-02-05 12:52:41 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
|
objectstore "queryorchestration/internal/serviceconfig/objectstore"
|
2025-03-11 16:31:06 +00:00
|
|
|
objectstoremock "queryorchestration/mocks/objectstore"
|
2025-02-05 12:52:41 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
|
|
|
"github.com/google/uuid"
|
2025-02-05 12:52:41 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-11 16:31:06 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
2025-02-05 12:52:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type StoreConfig struct {
|
|
|
|
|
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, &CreateAWSConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
|
2025-02-05 12:52:41 +00:00
|
|
|
|
|
|
|
|
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, &CreateAWSConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
|
2025-02-05 12:52:41 +00:00
|
|
|
assert.NotNil(t, cfg.GetStoreClient())
|
|
|
|
|
}
|
2025-03-11 16:31:06 +00:00
|
|
|
|
|
|
|
|
func TestPutObject(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
cfg := &StoreConfig{}
|
|
|
|
|
SetCfgProvider(t, cfg)
|
|
|
|
|
mockS3 := objectstoremock.NewMockS3Client(t)
|
|
|
|
|
cfg.StoreClient = mockS3
|
|
|
|
|
|
|
|
|
|
clientId := uuid.New()
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
|
file := strings.NewReader("hello")
|
|
|
|
|
filename := "hello"
|
|
|
|
|
expectedLocation := fmt.Sprintf("%s/%s", clientId, filename)
|
|
|
|
|
|
|
|
|
|
mockS3.EXPECT().
|
|
|
|
|
PutObject(
|
|
|
|
|
mock.Anything,
|
|
|
|
|
mock.MatchedBy(func(in *s3.PutObjectInput) bool {
|
|
|
|
|
return *in.Bucket == bucketName && *in.Key == expectedLocation
|
|
|
|
|
}),
|
|
|
|
|
mock.Anything,
|
|
|
|
|
).
|
|
|
|
|
Return(&s3.PutObjectOutput{}, nil)
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
PutObject(t, ctx, cfg, clientId, bucketName, filename, file)
|
2025-03-11 16:31:06 +00:00
|
|
|
}
|