Skip to content

Commit

Permalink
chore(storage): update to go 1.15 chores (#5706)
Browse files Browse the repository at this point in the history
* change xerrors to errors package for .As() and .Is()

* remove go114 file

* remove loc()
  • Loading branch information
BrennaEpp authored Apr 6, 2022
1 parent 5769c29 commit 3b27572
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 188 deletions.
5 changes: 2 additions & 3 deletions storage/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"cloud.google.com/go/internal/optional"
"cloud.google.com/go/internal/trace"
"github.com/googleapis/go-type-adapters/adapters"
"golang.org/x/xerrors"
"google.golang.org/api/googleapi"
"google.golang.org/api/iamcredentials/v1"
"google.golang.org/api/iterator"
Expand Down Expand Up @@ -187,7 +186,7 @@ func (b *BucketHandle) Attrs(ctx context.Context) (attrs *BucketAttrs, err error
return err
}, b.retry, true)
var e *googleapi.Error
if ok := xerrors.As(err, &e); ok && e.Code == http.StatusNotFound {
if ok := errors.As(err, &e); ok && e.Code == http.StatusNotFound {
return nil, ErrBucketNotExist
}
if err != nil {
Expand Down Expand Up @@ -1919,7 +1918,7 @@ func (it *ObjectIterator) fetch(pageSize int, pageToken string) (string, error)
}, it.bucket.retry, true)
if err != nil {
var e *googleapi.Error
if ok := xerrors.As(err, &e); ok && e.Code == http.StatusNotFound {
if ok := errors.As(err, &e); ok && e.Code == http.StatusNotFound {
err = ErrBucketNotExist
}
return "", err
Expand Down
23 changes: 12 additions & 11 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"errors"
"flag"
"fmt"
"hash/crc32"
Expand Down Expand Up @@ -52,7 +53,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/oauth2/google"
"golang.org/x/xerrors"
"google.golang.org/api/googleapi"
"google.golang.org/api/iterator"
itesting "google.golang.org/api/iterator/testing"
Expand Down Expand Up @@ -1214,12 +1214,12 @@ func TestIntegration_CancelWriteGRPC(t *testing.T) {

// The next Write should return context.Canceled.
_, err = w.Write(content)
if !xerrors.Is(err, context.Canceled) {
if !errors.Is(err, context.Canceled) {
t.Fatalf("On Write: got %v, wanted context.Canceled", err)
}
// The Close should too.
err = w.Close()
if !xerrors.Is(err, context.Canceled) {
if !errors.Is(err, context.Canceled) {
t.Fatalf("On Close: got %v, wanted context.Canceled", err)
}

Expand Down Expand Up @@ -1616,7 +1616,7 @@ func TestIntegration_Objects(t *testing.T) {
realLen := len(contents[objName])
_, err := bkt.Object(objName).NewRangeReader(ctx, int64(realLen*2), 10)
var e *googleapi.Error
if ok := xerrors.As(err, &e); !ok {
if ok := errors.As(err, &e); !ok {
t.Error("NewRangeReader did not return a googleapi.Error")
} else {
if e.Code != 416 {
Expand Down Expand Up @@ -2894,7 +2894,7 @@ func TestIntegration_RequesterPays(t *testing.T) {
return 0
}
var e *googleapi.Error
if ok := xerrors.As(err, &e); ok {
if ok := errors.As(err, &e); ok {
return e.Code
}
return -1
Expand Down Expand Up @@ -3153,7 +3153,7 @@ func TestIntegration_PublicBucket(t *testing.T) {

errCode := func(err error) int {
var err2 *googleapi.Error
if ok := xerrors.As(err, &err2); !ok {
if ok := errors.As(err, &err2); !ok {
return -1
}
return err2.Code
Expand Down Expand Up @@ -3335,12 +3335,12 @@ func TestIntegration_CancelWrite(t *testing.T) {
cancel()
// The next Write should return context.Canceled.
_, err = w.Write(buf)
if !xerrors.Is(err, context.Canceled) {
if !errors.Is(err, context.Canceled) {
t.Fatalf("got %v, wanted context.Canceled", err)
}
// The Close should too.
err = w.Close()
if !xerrors.Is(err, context.Canceled) {
if !errors.Is(err, context.Canceled) {
t.Fatalf("got %v, wanted context.Canceled", err)
}
}
Expand Down Expand Up @@ -3521,16 +3521,17 @@ func TestIntegration_UpdateRetentionExpirationTime(t *testing.T) {
h.mustWrite(obj.NewWriter(ctx), randomContents())

defer func() {
t.Helper()
h.mustUpdateBucket(bkt, BucketAttrsToUpdate{RetentionPolicy: &RetentionPolicy{RetentionPeriod: 0}}, h.mustBucketAttrs(bkt).MetaGeneration)

// RetentionPeriod of less than a day is explicitly called out
// as best effort and not guaranteed, so let's log problems deleting
// objects instead of failing.
if err := obj.Delete(context.Background()); err != nil {
t.Logf("%s: object delete: %v", loc(), err)
t.Logf("object delete: %v", err)
}
if err := bkt.Delete(context.Background()); err != nil {
t.Logf("%s: bucket delete: %v", loc(), err)
t.Logf("bucket delete: %v", err)
}
}()

Expand Down Expand Up @@ -3992,7 +3993,7 @@ func TestIntegration_ReaderCancel(t *testing.T) {
buf := make([]byte, 1000)
_, readErr = r.Read(buf)
if readErr != nil {
if xerrors.Is(readErr, context.Canceled) {
if errors.Is(readErr, context.Canceled) {
return
}
break
Expand Down
4 changes: 2 additions & 2 deletions storage/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package storage

import (
"context"
"errors"
"io"
"net"
"net/url"
"strings"

"cloud.google.com/go/internal"
gax "github.com/googleapis/gax-go/v2"
"golang.org/x/xerrors"
"google.golang.org/api/googleapi"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -61,7 +61,7 @@ func shouldRetry(err error) bool {
if err == nil {
return false
}
if xerrors.Is(err, io.ErrUnexpectedEOF) {
if errors.Is(err, io.ErrUnexpectedEOF) {
return true
}

Expand Down
163 changes: 0 additions & 163 deletions storage/reader_go114_test.go

This file was deleted.

Loading

0 comments on commit 3b27572

Please sign in to comment.