blob: fixed GCS post-submit test

This commit is contained in:
Jarek Kowalski
2020-02-17 08:57:23 -08:00
parent 47ba37f9d0
commit 29db31d008
2 changed files with 11 additions and 4 deletions

1
go.mod
View File

@@ -17,6 +17,7 @@ require (
github.com/godbus/dbus v4.1.0+incompatible // indirect
github.com/golang/protobuf v1.3.2
github.com/google/fswalker v0.2.0
github.com/google/martian v2.1.0+incompatible
github.com/klauspost/compress v1.9.7
github.com/klauspost/crc32 v1.2.0 // indirect
github.com/klauspost/pgzip v1.2.1

View File

@@ -8,6 +8,7 @@
"fmt"
"io"
"io/ioutil"
"time"
"github.com/efarrer/iothrottler"
"github.com/pkg/errors"
@@ -274,10 +275,15 @@ func New(ctx context.Context, opt *Options) (blob.Storage, error) {
uploadThrottler: uploadThrottler,
}
// verify GCS connection is functional by fetching one blob,
// which must return success or ErrBlobNotFound. Any other error indicates problem with connection.
if _, err = gcs.GetBlob(ctx, "kopia.repository", 0, 100); err != nil && err != blob.ErrBlobNotFound {
return nil, err
// verify GCS connection is functional by listing blobs in a bucket, which will fail if the bucket
// does not exist. We list with a prefix that will not exist, to avoid iterating through any objects.
nonExistentPrefix := fmt.Sprintf("kopia-gcs-storage-initializing-%v", time.Now().UnixNano())
err = gcs.ListBlobs(ctx, blob.ID(nonExistentPrefix), func(md blob.Metadata) error {
return nil
})
if err != nil {
return nil, errors.Wrap(err, "unable to list from the bucket")
}
return gcs, nil