Files
query-orchestration/internal/test/objectstore_test.go
T
Michael McGuinness 555b6d420b Merged in feature/docresult (pull request #105)
Document Result Endpoint

* testing

* cleantesting

* progress

* query

* lint

* readme

* dockerclient

* api

* passtest

* tests

* test
2025-03-17 18:14:15 +00:00

87 lines
1.8 KiB
Go

package test
import (
"context"
"fmt"
"strings"
"testing"
"queryorchestration/internal/serviceconfig"
objectstore "queryorchestration/internal/serviceconfig/objectstore"
objectstoremock "queryorchestration/mocks/objectstore"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
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()
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, &CreateAWSConfig{
Cfg: cfg,
})
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
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)
PutObject(t, ctx, cfg, clientId, bucketName, filename, file)
}