storage/gcs: tests for non-existent buckets

This commit is contained in:
Jarek Kowalski
2018-10-29 19:43:57 -07:00
parent ee01895961
commit 12286ced57
2 changed files with 22 additions and 4 deletions

View File

@@ -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

View File

@@ -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")
}
}