pkg/remotestorage: handle new error strings (googleapi)

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-01-09 20:27:10 -08:00
parent 0a8669f13c
commit bc2cf2882b
4 changed files with 20 additions and 20 deletions

View File

View File

@ -0,0 +1 @@
a

View File

@ -1,4 +1,4 @@
// Copyright 2016 CoreOS, Inc.
// Copyright 2018 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package remotestorage_test
package main
import (
"io/ioutil"
@ -21,30 +21,29 @@ import (
"github.com/coreos/dbtester/pkg/remotestorage"
)
func ExampleGoogleCloudStorage_UploadFile() {
func main() {
kbs, err := ioutil.ReadFile("key.json")
if err != nil {
log.Fatal(err)
}
u, err := remotestorage.NewGoogleCloudStorage(kbs, "my-project")
u, err := remotestorage.NewGoogleCloudStorage(kbs, "etcd-development")
if err != nil {
log.Fatal(err)
}
if err := u.UploadFile("test-bucket", "agent.log", "dir/agent.log", remotestorage.WithContentType("text/plain")); err != nil {
if err := u.UploadFile("dbtester-results", "agent.log", "dir/agent.log", remotestorage.WithContentType("text/plain")); err != nil {
log.Fatal(err)
}
}
func ExampleGoogleCloudStorage_UploadDir() {
kbs, err := ioutil.ReadFile("key.json")
if err != nil {
log.Fatal(err)
}
u, err := remotestorage.NewGoogleCloudStorage(kbs, "my-project")
if err != nil {
log.Fatal(err)
}
if err := u.UploadDir("test-bucket", "articles", "articles"); err != nil {
log.Fatal(err)
}
// upload directories
// kbs, err := ioutil.ReadFile("key.json")
// if err != nil {
// log.Fatal(err)
// }
// u, err := remotestorage.NewGoogleCloudStorage(kbs, "my-project")
// if err != nil {
// log.Fatal(err)
// }
// if err := u.UploadDir("test-bucket", "articles", "articles"); err != nil {
// log.Fatal(err)
// }
}

View File

@ -78,7 +78,7 @@ func (g *GoogleCloudStorage) UploadFile(bucket, src, dst string, opts ...OpOptio
bkt := client.Bucket(bucket)
if err := bkt.Create(ctx, g.Project, nil); err != nil {
if !strings.Contains(err.Error(), "You already own this bucket. Please select another name") {
if err.Error() != "googleapi: Error 409: Sorry, that name is not available. Please try a different one., conflict" {
return err
}
}
@ -122,7 +122,7 @@ func (g *GoogleCloudStorage) UploadDir(bucket, src, dst string, opts ...OpOption
bkt := client.Bucket(bucket)
if err := bkt.Create(ctx, g.Project, nil); err != nil {
if !strings.Contains(err.Error(), "You already own this bucket. Please select another name") {
if err.Error() != "googleapi: Error 409: Sorry, that name is not available. Please try a different one., conflict" {
return err
}
}