Merge pull request #8639 from gyuho/ineffassign

test: add 'ineffassign'
release-3.3
Gyu-Ho Lee 2017-10-03 10:30:55 -07:00 committed by GitHub
commit e44ce19c1f
21 changed files with 50 additions and 23 deletions

View File

@ -56,6 +56,7 @@ before_install:
- go get -v -u honnef.co/go/tools/cmd/gosimple
- go get -v -u honnef.co/go/tools/cmd/unused
- go get -v -u honnef.co/go/tools/cmd/staticcheck
- go get -v -u github.com/gordonklaus/ineffassign
- ./scripts/install-marker.sh amd64
- export GOROOT=$(go env GOROOT)

View File

@ -8,10 +8,11 @@ package client
import (
"errors"
"fmt"
codec1978 "github.com/ugorji/go/codec"
"reflect"
"runtime"
time "time"
codec1978 "github.com/ugorji/go/codec"
)
const (
@ -77,7 +78,6 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
}
}
r.EncodeMapStart(yynn2)
yynn2 = 0
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1819)
@ -352,7 +352,6 @@ func (x *Node) CodecEncodeSelf(e *codec1978.Encoder) {
}
}
r.EncodeMapStart(yynn2)
yynn2 = 0
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1819)

View File

@ -49,7 +49,7 @@ func TestMain(m *testing.M) {
os.Args = append(os.Args, "-test.run=Test")
}
v := 0
var v int
if useCluster {
tr, trerr := transport.NewTransport(transport.TLSInfo{}, time.Second)
if trerr != nil {

View File

@ -453,7 +453,7 @@ func (c *Client) checkVersion() (err error) {
vs := strings.Split(resp.Version, ".")
maj, min := 0, 0
if len(vs) >= 2 {
maj, rerr = strconv.Atoi(vs[0])
maj, _ = strconv.Atoi(vs[0])
min, rerr = strconv.Atoi(vs[1])
}
if maj < 3 || (maj == 3 && min < 2) {

View File

@ -311,7 +311,7 @@ func testWatchCancelRunning(t *testing.T, wctx *watchctx) {
select {
case <-time.After(time.Second):
t.Fatalf("took too long to cancel")
case v, ok := <-wctx.ch:
case _, ok := <-wctx.ch:
if !ok {
// closed before getting put; OK
break
@ -320,8 +320,8 @@ func testWatchCancelRunning(t *testing.T, wctx *watchctx) {
select {
case <-time.After(time.Second):
t.Fatalf("took too long to close")
case v, ok = <-wctx.ch:
if ok {
case v, ok2 := <-wctx.ch:
if ok2 {
t.Fatalf("expected watcher channel to close, got %v", v)
}
}

View File

@ -48,7 +48,7 @@ func TestMain(m *testing.M) {
os.Args = append(os.Args, "-test.run=Test")
}
v := 0
var v int
if useCluster {
cfg := integration.ClusterConfig{Size: 3}
clus := integration.NewClusterV3(nil, &cfg)

View File

@ -66,10 +66,13 @@ func TestGRPCResolver(t *testing.T) {
delOp := naming.Update{Op: naming.Delete, Addr: "127.0.0.1"}
err = r.Update(context.TODO(), "foo", delOp)
if err != nil {
t.Fatalf("failed to udpate %v", err)
}
us, err = w.Next()
if err != nil {
t.Fatal("failed to get udpate", err)
t.Fatalf("failed to get udpate %v", err)
}
wu = &naming.Update{

View File

@ -43,6 +43,9 @@ func TestDetectKvOrderViolation(t *testing.T) {
},
}
cli, err := clientv3.New(cfg)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
if _, err = clus.Client(0).Put(ctx, "foo", "bar"); err != nil {
@ -101,6 +104,9 @@ func TestDetectTxnOrderViolation(t *testing.T) {
},
}
cli, err := clientv3.New(cfg)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
if _, err = clus.Client(0).Put(ctx, "foo", "bar"); err != nil {
@ -143,6 +149,9 @@ func TestDetectTxnOrderViolation(t *testing.T) {
cli.SetEndpoints(clus.Members[2].GRPCAddr())
_, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
if err != nil {
t.Fatal(err)
}
orderingTxn = orderingKv.Txn(ctx)
_, err = orderingTxn.If(
clientv3.Compare(clientv3.Value("b"), ">", "a"),

View File

@ -35,6 +35,9 @@ func TestEndpointSwitchResolvesViolation(t *testing.T) {
}
cfg := clientv3.Config{Endpoints: []string{clus.Members[0].GRPCAddr()}}
cli, err := clientv3.New(cfg)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
@ -91,6 +94,9 @@ func TestUnresolvableOrderViolation(t *testing.T) {
},
}
cli, err := clientv3.New(cfg)
if err != nil {
t.Fatal(err)
}
eps := cli.Endpoints()
ctx := context.TODO()

View File

@ -56,7 +56,6 @@ func TestRevision(t *testing.T) {
// skip the same revision
rg.SetRev(99) // will be 100
expectedRevision = int64(90)
rg.Wait(1)
// nothing happens

View File

@ -124,7 +124,7 @@ func ctlV3RoleRevokePermission(cx ctlCtx, rolename string, key, rangeEnd string,
cmdArgs := append(cx.PrefixArgs(), "role", "revoke-permission")
cmdArgs = append(cmdArgs, rolename)
cmdArgs = append(cmdArgs, key)
expStr := ""
var expStr string
if len(rangeEnd) != 0 {
cmdArgs = append(cmdArgs, rangeEnd)
expStr = fmt.Sprintf("Permission of range [%s, %s) is revoked from role %s", key, rangeEnd, rolename)

View File

@ -69,7 +69,7 @@ func spawnEtcd(args []string) (*expect.ExpectProcess, error) {
return nil, err
}
env := []string{}
var env []string
if args[1] == "grpc-proxy" {
// avoid test flag conflicts in coverage enabled etcd by putting flags in ETCDCOV_ARGS
env = append(os.Environ(), "ETCDCOV_ARGS="+strings.Join(args, "\xe7\xcd"))

View File

@ -110,7 +110,7 @@ func etcdFlagUsages(flagSet *pflag.FlagSet) string {
if len(flag.Deprecated) > 0 {
return
}
format := ""
var format string
if len(flag.Shorthand) > 0 {
format = " -%s, --%s"
} else {

View File

@ -317,7 +317,7 @@ func (h *statsHandler) serveLeader(w http.ResponseWriter, r *http.Request) {
// a server Request, performing validation of supplied fields as appropriate.
// If any validation fails, an empty Request and non-nil error is returned.
func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) {
noValueOnSuccess := false
var noValueOnSuccess bool
emptyReq := etcdserverpb.Request{}
err := r.ParseForm()

View File

@ -382,7 +382,6 @@ func (s *v2v3Store) Delete(nodePath string, dir, recursive bool) (*store.Event,
if !dir && !recursive {
return s.deleteNode(nodePath)
}
dir = true
if !recursive {
return s.deleteEmptyDir(nodePath)
}
@ -516,7 +515,7 @@ func compareFail(nodePath, prevValue string, prevIndex uint64, resp *clientv3.Tx
kv := kvs[0]
indexMatch := (prevIndex == 0 || kv.ModRevision == int64(prevIndex))
valueMatch := (prevValue == "" || string(kv.Value) == prevValue)
cause := ""
var cause string
switch {
case indexMatch && !valueMatch:
cause = fmt.Sprintf("[%v != %v]", prevValue, string(kv.Value))

View File

@ -112,7 +112,7 @@ func (tp *TCPProxy) pick() *remote {
case r.srv.Priority < bestPr:
bestPr = r.srv.Priority
w = 0
weighted, unweighted = nil, nil
weighted = nil
unweighted = []*remote{r}
fallthrough
case r.srv.Priority == bestPr:

View File

@ -243,7 +243,8 @@ func (in *inflights) freeTo(to uint64) {
return
}
i, idx := 0, in.start
idx := in.start
var i int
for i = 0; i < in.count; i++ {
if to < in.buffer[idx] { // found the first large inflight
break

View File

@ -194,7 +194,6 @@ func benchStoreSet(b *testing.B, valueSize int, process func(interface{}) ([]byt
}
}
kvs = nil
b.StopTimer()
memStats := new(runtime.MemStats)
runtime.GC()

View File

@ -216,7 +216,7 @@ func TestStoreWatchExpireEmptyRefresh(t *testing.T) {
fc := newFakeClock()
s.clock = fc
var eidx uint64 = 1
var eidx uint64
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
// Should be no-op
fc.Advance(200 * time.Millisecond)
@ -241,7 +241,7 @@ func TestStoreWatchNoRefresh(t *testing.T) {
fc := newFakeClock()
s.clock = fc
var eidx uint64 = 1
var eidx uint64
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
// Should be no-op
fc.Advance(200 * time.Millisecond)

11
test
View File

@ -384,6 +384,17 @@ function fmt_pass {
echo "Skipping staticcheck..."
fi
if which ineffassign >/dev/null; then
echo "Checking ineffassign..."
ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${ineffassignResult}" ]; then
echo -e "ineffassign checking failed:\n${ineffassignResult}"
exit 255
fi
else
echo "Skipping ineffassign..."
fi
echo "Checking for license header..."
licRes=""
files=$(find . -type f -iname '*.go' ! -path './cmd/*' ! -path './gopath.proto/*')

View File

@ -110,7 +110,7 @@ func etcdFlagUsages(flagSet *pflag.FlagSet) string {
if len(flag.Deprecated) > 0 {
return
}
format := ""
var format string
if len(flag.Shorthand) > 0 {
format = " -%s, --%s"
} else {