d91ef1832b
Function Test Coverage * test * scripts
80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package objectstore_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"queryorchestration/internal/serviceconfig"
|
|
objectstore "queryorchestration/internal/serviceconfig/objectstore"
|
|
objectstoremock "queryorchestration/mocks/objectstore"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
func TestGetStoreClient(t *testing.T) {
|
|
c := objectstore.ObjectStoreConfig{}
|
|
assert.Nil(t, c.GetStoreClient())
|
|
c.StoreClient = &s3.Client{}
|
|
assert.Equal(t, &s3.Client{}, c.GetStoreClient())
|
|
}
|
|
|
|
func TestStoreClient(t *testing.T) {
|
|
os.Clearenv()
|
|
ctx := context.Background()
|
|
c := objectstore.ObjectStoreConfig{}
|
|
err := c.SetStoreClient(ctx)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, c.StoreClient)
|
|
}
|
|
|
|
func TestPingStoreByName(t *testing.T) {
|
|
ctx := context.Background()
|
|
mocks3 := objectstoremock.NewMockS3Client(t)
|
|
c := objectstore.ObjectStoreConfig{
|
|
StoreClient: mocks3,
|
|
}
|
|
name := "bucket-name"
|
|
|
|
mocks3.EXPECT().
|
|
HeadBucket(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *s3.HeadBucketInput) bool {
|
|
return *in.Bucket == name
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&s3.HeadBucketOutput{}, nil)
|
|
|
|
err := c.PingStoreByName(ctx, name)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestGetS3Client(t *testing.T) {
|
|
c := objectstore.ObjectStoreConfig{}
|
|
assert.Empty(t, c.GetS3Endpoint())
|
|
c.AWSEndpointUrlS3 = "s3_endpoint"
|
|
assert.Equal(t, "s3_endpoint", c.GetS3Endpoint())
|
|
}
|
|
|
|
type StoreConfig struct {
|
|
serviceconfig.BaseConfig
|
|
objectstore.ObjectStoreConfig
|
|
}
|
|
|
|
func TestSetStoreClientAndPingByName(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
|
defer cancel()
|
|
cfg := &StoreConfig{}
|
|
name := "bucket"
|
|
|
|
err := cfg.SetStoreClientAndPingByName(ctx, name)
|
|
|
|
if !errors.Is(err, context.DeadlineExceeded) {
|
|
t.Errorf("Expected timeout error, got: %v", err)
|
|
}
|
|
}
|