storage: fix some issues identified by staticcheck
- bucket: complaint about explicit comparison to bool literals.
Restructured the switch to an if/else chain.
- bucket_test/storage: replaced use of deprecated constructor
by the recommended replacement.
- integration_test: seems like a genuine bug where a "return" is
ommitted and no error is returned when it should be.
With these changes staticcheck passes cleanly within the storage module.
Change-Id: I090e8345ccbff66e632855802602251d26e217e5
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/51030
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Cotter <cjcotter@google.com>
diff --git a/storage/bucket.go b/storage/bucket.go
index dae11ff..389402f 100644
--- a/storage/bucket.go
+++ b/storage/bucket.go
@@ -986,12 +986,11 @@
},
}
- switch {
- case rr.Condition.IsLive == nil:
+ if rr.Condition.IsLive == nil {
r.Condition.Liveness = LiveAndArchived
- case *rr.Condition.IsLive == true:
+ } else if *rr.Condition.IsLive {
r.Condition.Liveness = Live
- case *rr.Condition.IsLive == false:
+ } else {
r.Condition.Liveness = Archived
}
diff --git a/storage/bucket_test.go b/storage/bucket_test.go
index f65bd20..b4ebca1 100644
--- a/storage/bucket_test.go
+++ b/storage/bucket_test.go
@@ -15,6 +15,7 @@
package storage
import (
+ "context"
"net/http"
"reflect"
"testing"
@@ -413,7 +414,7 @@
}
func TestCallBuilders(t *testing.T) {
- rc, err := raw.New(&http.Client{})
+ rc, err := raw.NewService(context.Background())
if err != nil {
t.Fatal(err)
}
diff --git a/storage/integration_test.go b/storage/integration_test.go
index 270d5f2..e5a7d39 100644
--- a/storage/integration_test.go
+++ b/storage/integration_test.go
@@ -3307,7 +3307,7 @@
if objAttrs.EventBasedHold || objAttrs.TemporaryHold {
obj := bkt.Object(objAttrs.Name)
if _, err := obj.Update(ctx, ObjectAttrsToUpdate{EventBasedHold: false, TemporaryHold: false}); err != nil {
- fmt.Errorf("removing hold from %q: %v", bucketName+"/"+objAttrs.Name, err)
+ return fmt.Errorf("removing hold from %q: %v", bucketName+"/"+objAttrs.Name, err)
}
}
if err := bkt.Object(objAttrs.Name).Delete(ctx); err != nil {
diff --git a/storage/storage.go b/storage/storage.go
index 5688815..1d7903d 100644
--- a/storage/storage.go
+++ b/storage/storage.go
@@ -113,7 +113,7 @@
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
- rawService, err := raw.New(hc)
+ rawService, err := raw.NewService(ctx, option.WithHTTPClient(hc))
if err != nil {
return nil, fmt.Errorf("storage client: %v", err)
}