gcsstore: Avoid panic when composing with no passed objects (#360)
This commit is contained in:
parent
0ef0e6f9e0
commit
ebf767b2e9
|
@ -129,6 +129,10 @@ const COMPOSE_RETRIES = 3
|
|||
|
||||
// Compose takes a bucket name, a list of initial source names, and a destination string to compose multiple GCS objects together
|
||||
func (service *GCSService) compose(ctx context.Context, bucket string, srcs []string, dst string) error {
|
||||
if len(srcs) < 1 {
|
||||
return fmt.Errorf("empty srcs passed to compose for bucket: %s dest: %s", bucket, dst)
|
||||
}
|
||||
|
||||
dstParams := GCSObjectParams{
|
||||
Bucket: bucket,
|
||||
ID: dst,
|
||||
|
|
|
@ -195,6 +195,30 @@ func TestComposeObjects(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestComposeNoObjects(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client, err := storage.NewClient(ctx, option.WithAPIKey("foo"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
service := GCSService{
|
||||
Client: client,
|
||||
}
|
||||
|
||||
err = service.ComposeObjects(ctx, GCSComposeParams{
|
||||
Bucket: "test-bucket",
|
||||
Sources: []string{},
|
||||
Destination: "test_all",
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Error: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetObjectAttrs(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
|
|
|
@ -270,6 +270,10 @@ func (upload gcsUpload) FinishUpload(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if len(names) == 0 {
|
||||
return fmt.Errorf("no GCS objects found with FilterObjects %+v", filterParams)
|
||||
}
|
||||
|
||||
composeParams := GCSComposeParams{
|
||||
Bucket: store.Bucket,
|
||||
Destination: store.keyWithPrefix(id),
|
||||
|
|
Loading…
Reference in New Issue