From 12286ced5793165b6ab265cc53ebf00580442382 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Mon, 29 Oct 2018 19:43:57 -0700 Subject: [PATCH] storage/gcs: tests for non-existent buckets --- storage/gcs/gcs_storage.go | 4 ---- storage/gcs/gcs_storage_test.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/storage/gcs/gcs_storage.go b/storage/gcs/gcs_storage.go index fe0f233f7..05a731135 100644 --- a/storage/gcs/gcs_storage.go +++ b/storage/gcs/gcs_storage.go @@ -190,10 +190,6 @@ func (gcs *gcsStorage) Close(ctx context.Context) error { return nil } -func (gcs *gcsStorage) String() string { - return fmt.Sprintf("gcs://%v/%v", gcs.BucketName, gcs.Prefix) -} - func toBandwidth(bytesPerSecond int) iothrottler.Bandwidth { if bytesPerSecond <= 0 { return iothrottler.Unlimited diff --git a/storage/gcs/gcs_storage_test.go b/storage/gcs/gcs_storage_test.go index 03e8ae724..edc55fb3b 100644 --- a/storage/gcs/gcs_storage_test.go +++ b/storage/gcs/gcs_storage_test.go @@ -43,3 +43,25 @@ func TestGCSStorage(t *testing.T) { t.Fatalf("unable to clear GCS bucket: %v", err) } } + +func TestGCSStorageInvalid(t *testing.T) { + bucket := os.Getenv("KOPIA_GCS_TEST_BUCKET") + if bucket == "" { + t.Skip("KOPIA_GCS_TEST_BUCKET not provided") + } + + ctx := context.Background() + st, err := gcs.New(ctx, &gcs.Options{ + BucketName: bucket + "-no-such-bucket", + ServiceAccountCredentials: os.Getenv("KOPIA_GCS_CREDENTIALS_FILE"), + }) + + if err != nil { + t.Fatalf("unable to connect to GCS: %v", err) + } + + defer st.Close(ctx) + if err := st.PutBlock(ctx, "xxx", []byte{1, 2, 3}); err == nil { + t.Errorf("unexpecte success when adding to non-existent bucket") + } +}