internal: fix new staticcheck warnings

- The staticchecker we use seems to have gotten upgrades that allows it to find
a bunch more things to clean up - mostly unused vars/methods/etc. This CL
does the needful fixing-up.
- Also switches from using -ignore to using ye olde pipe-stderr-to-stdout-and-
grep-exclude since -ignore is being deprecated. Subsequently we have to remove
pipefail, since we now expect staticcheck's exit code to be 1.

Change-Id: Ife74520c39db4208ca1347ef97643365a370c7af
Reviewed-on: https://code-review.googlesource.com/c/37070
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Eno Compton <enocom@google.com>
diff --git a/gensupport/media_test.go b/gensupport/media_test.go
index 0403eac..7c232d5 100644
--- a/gensupport/media_test.go
+++ b/gensupport/media_test.go
@@ -280,12 +280,10 @@
 	}()
 
 	for _, test := range []struct {
-		desc            string
-		r               io.Reader
-		chunkSize       int
-		wantGetBody     bool
-		wantContentType string
-		wantUploadType  string
+		desc        string
+		r           io.Reader
+		chunkSize   int
+		wantGetBody bool
 	}{
 		{
 			desc:        "chunk size of zero: no getBody",
diff --git a/gensupport/retry_test.go b/gensupport/retry_test.go
index 7bbe6bb..d061345 100644
--- a/gensupport/retry_test.go
+++ b/gensupport/retry_test.go
@@ -21,7 +21,6 @@
 	"net"
 	"net/http"
 	"testing"
-	"time"
 )
 
 func TestRetry(t *testing.T) {
@@ -124,30 +123,6 @@
 	}
 }
 
-func RetryReturnsOnContextCancel(t *testing.T) {
-	f := func() (*http.Response, error) {
-		return nil, io.ErrUnexpectedEOF
-	}
-	backoff := UniformPauseStrategy(time.Hour)
-	ctx, cancel := context.WithCancel(context.Background())
-
-	errc := make(chan error, 1)
-	go func() {
-		_, err := Retry(ctx, f, backoff)
-		errc <- err
-	}()
-
-	cancel()
-	select {
-	case err := <-errc:
-		if err != ctx.Err() {
-			t.Errorf("Retry returned err: %v, want %v", err, ctx.Err())
-		}
-	case <-time.After(5 * time.Second):
-		t.Errorf("Timed out waiting for Retry to return")
-	}
-}
-
 func TestShouldRetry(t *testing.T) {
 	testCases := []struct {
 		status int
diff --git a/googleapi/googleapi.go b/googleapi/googleapi.go
index 8cdb03b..ab53767 100644
--- a/googleapi/googleapi.go
+++ b/googleapi/googleapi.go
@@ -189,32 +189,6 @@
 	return buf, nil
 }
 
-// endingWithErrorReader from r until it returns an error.  If the
-// final error from r is io.EOF and e is non-nil, e is used instead.
-type endingWithErrorReader struct {
-	r io.Reader
-	e error
-}
-
-func (er endingWithErrorReader) Read(p []byte) (n int, err error) {
-	n, err = er.r.Read(p)
-	if err == io.EOF && er.e != nil {
-		err = er.e
-	}
-	return
-}
-
-// countingWriter counts the number of bytes it receives to write, but
-// discards them.
-type countingWriter struct {
-	n *int64
-}
-
-func (w countingWriter) Write(p []byte) (int, error) {
-	*w.n += int64(len(p))
-	return len(p), nil
-}
-
 // ProgressUpdater is a function that is called upon every progress update of a resumable upload.
 // This is the only part of a resumable upload (from googleapi) that is usable by the developer.
 // The remaining usable pieces of resumable uploads is exposed in each auto-generated API.
diff --git a/internal/creds_test.go b/internal/creds_test.go
index 5d36efd..abde12f 100644
--- a/internal/creds_test.go
+++ b/internal/creds_test.go
@@ -73,13 +73,6 @@
 	// TODO(jba): find a way to test the call to google.DefaultTokenSource.
 }
 
-const validRefeshTokenJSON = `{
-  "client_id": "764-aaaaa.apps.googleusercontent.com",
-  "client_secret": "d-988888888",
-  "refresh_token": "1/88888aaaaaaaaa",
-  "type": "authorized_user"
-}`
-
 const validServiceAccountJSON = `{
   "type": "service_account",
   "project_id": "dumba-504",
diff --git a/internal/kokoro/vet.sh b/internal/kokoro/vet.sh
index aabdebe..e81d04e 100755
--- a/internal/kokoro/vet.sh
+++ b/internal/kokoro/vet.sh
@@ -1,7 +1,21 @@
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 #!/bin/bash
 
 # Fail on any error
-set -eo pipefail
+set -eo
 
 # Display commands being run
 set -x
@@ -30,19 +44,22 @@
 # Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
 # so we rely on inverse grepping to do this for us.
 golint ./... 2>&1 | ( \
-    grep -v "gen.go" | \
-    grep -v "disco.go" | \
-    grep -v "exported const DefaultDelayThreshold should have comment" | \
-    grep -v "exported const DefaultBundleCountThreshold should have comment" | \
-    grep -v "exported const DefaultBundleByteThreshold should have comment" | \
-    grep -v "exported const DefaultBufferedByteLimit should have comment" | \
-    grep -v "error var Done should have name of the form ErrFoo" | \
-    grep -v "exported method APIKey.RoundTrip should have comment or be unexported" | \
-    grep -v "exported method MarshalStyle.JSONReader should have comment or be unexported" | \
-    grep -v "UnmarshalJSON should have comment or be unexported" | \
-    grep -v "MarshalJSON should have comment or be unexported" | \
-    grep -vE "\.pb\.go:" || true) | tee /dev/stderr | (! read)
+  grep -v "gen.go" | \
+  grep -v "disco.go" | \
+  grep -v "exported const DefaultDelayThreshold should have comment" | \
+  grep -v "exported const DefaultBundleCountThreshold should have comment" | \
+  grep -v "exported const DefaultBundleByteThreshold should have comment" | \
+  grep -v "exported const DefaultBufferedByteLimit should have comment" | \
+  grep -v "error var Done should have name of the form ErrFoo" | \
+  grep -v "exported method APIKey.RoundTrip should have comment or be unexported" | \
+  grep -v "exported method MarshalStyle.JSONReader should have comment or be unexported" | \
+  grep -v "UnmarshalJSON should have comment or be unexported" | \
+  grep -v "MarshalJSON should have comment or be unexported" | \
+  grep -vE "\.pb\.go:" || true) | tee /dev/stderr | (! read)
 
-staticcheck -ignore '
-*:SA1019
-' ./...
\ No newline at end of file
+staticcheck -go 1.9 ./... 2>&1 | ( \
+  grep -v "SA1019" | \
+  grep -v "S1007" | \
+  grep -v "error var Done should have name of the form ErrFoo" | \
+  grep -v "examples" | \
+  grep -v "gen.go" || true) | tee /dev/stderr | (! read)
diff --git a/internal/pool.go b/internal/pool.go
index ba40624..a4426dc 100644
--- a/internal/pool.go
+++ b/internal/pool.go
@@ -38,7 +38,7 @@
 // provided to NewPoolResolver.
 func (r *PoolResolver) Resolve(target string) (naming.Watcher, error) {
 	if r.dialOpt.Endpoint == "" {
-		return nil, errors.New("No endpoint configured")
+		return nil, errors.New("no endpoint configured")
 	}
 	addrs := make([]*naming.Update, 0, r.poolSize)
 	for i := 0; i < r.poolSize; i++ {
diff --git a/transport/bytestream/client.go b/transport/bytestream/client.go
index 63ba048..8c2ab87 100644
--- a/transport/bytestream/client.go
+++ b/transport/bytestream/client.go
@@ -153,7 +153,6 @@
 	writeClient  pb.ByteStream_WriteClient
 	resourceName string
 	offset       int64
-	backoffDelay time.Duration
 	err          error
 }
 
diff --git a/transport/bytestream/client_test.go b/transport/bytestream/client_test.go
index dcc2a80..f6a47d2 100644
--- a/transport/bytestream/client_test.go
+++ b/transport/bytestream/client_test.go
@@ -170,7 +170,6 @@
 	testCases := []struct {
 		name         string
 		resourceName string
-		maxBufSize   int
 		data         string
 		results      []int
 		wantWriteErr bool
diff --git a/transport/bytestream/examples_test.go b/transport/bytestream/examples_test.go
index 9ee7617..cab79ed 100644
--- a/transport/bytestream/examples_test.go
+++ b/transport/bytestream/examples_test.go
@@ -41,7 +41,7 @@
 	if err != nil && err != io.EOF {
 		log.Printf("Read %d bytes, got err=%v", n, err)
 	}
-	log.Printf("read %q", string(buf.Bytes()))
+	log.Printf("read %q", buf.String())
 }
 
 func ExampleNewReader(serverPort int, resourceName string) {
@@ -61,7 +61,7 @@
 	if err != nil && err != io.EOF {
 		log.Printf("Read %d bytes, got err=%v", n, err)
 	}
-	log.Printf("read %q", string(buf.Bytes()))
+	log.Printf("read %q", buf.String())
 }
 
 func ExampleNewWriter(serverPort int, resourceName string) {