Skip to content

Commit

Permalink
internal: fix new staticcheck warnings
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
jeanbza committed Jan 8, 2019
1 parent f971889 commit 8d96cf9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 86 deletions.
10 changes: 4 additions & 6 deletions gensupport/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,10 @@ func TestUploadRequestGetBody(t *testing.T) {
}()

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",
Expand Down
25 changes: 0 additions & 25 deletions gensupport/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"net"
"net/http"
"testing"
"time"
)

func TestRetry(t *testing.T) {
Expand Down Expand Up @@ -124,30 +123,6 @@ func TestRetryClosesBody(t *testing.T) {
}
}

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
Expand Down
26 changes: 0 additions & 26 deletions googleapi/googleapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,32 +189,6 @@ func (wrap MarshalStyle) JSONReader(v interface{}) (io.Reader, error) {
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.
Expand Down
7 changes: 0 additions & 7 deletions internal/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ func TestTokenSource(t *testing.T) {
// 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",
Expand Down
51 changes: 34 additions & 17 deletions internal/kokoro/vet.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,19 +44,22 @@ goimports -l . 2>&1 | tee /dev/stderr | (! read)
# 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)

staticcheck -ignore '
*:SA1019
' ./...
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 -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)
2 changes: 1 addition & 1 deletion internal/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewPoolResolver(size int, o *DialSettings) *PoolResolver {
// 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++ {
Expand Down
1 change: 0 additions & 1 deletion transport/bytestream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ type Writer struct {
writeClient pb.ByteStream_WriteClient
resourceName string
offset int64
backoffDelay time.Duration
err error
}

Expand Down
1 change: 0 additions & 1 deletion transport/bytestream/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func TestClientWrite(t *testing.T) {
testCases := []struct {
name string
resourceName string
maxBufSize int
data string
results []int
wantWriteErr bool
Expand Down
4 changes: 2 additions & 2 deletions transport/bytestream/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ExampleNewClient(serverPort int, resourceName string) {
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) {
Expand All @@ -61,7 +61,7 @@ func ExampleNewReader(serverPort int, resourceName string) {
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) {
Expand Down

0 comments on commit 8d96cf9

Please sign in to comment.