From 29db31d008fed60c8eeedc7158d83446ac8375f7 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Mon, 17 Feb 2020 08:57:23 -0800 Subject: [PATCH] blob: fixed GCS post-submit test --- go.mod | 1 + repo/blob/gcs/gcs_storage.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2e90428d2..fc19ad86d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/repo/blob/gcs/gcs_storage.go b/repo/blob/gcs/gcs_storage.go index ce017c7e4..dab304f6b 100644 --- a/repo/blob/gcs/gcs_storage.go +++ b/repo/blob/gcs/gcs_storage.go @@ -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