From 6ec4b9c26ad853d7c50bd04ef4d3ab044dc10248 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 11:16:03 -0800 Subject: [PATCH 1/8] test: exclude '_home' for gosimple, unused --- test | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test b/test index 8045e1a1b..4572dd20c 100755 --- a/test +++ b/test @@ -19,10 +19,6 @@ if [ -z "$PASSES" ]; then PASSES="fmt dep compile build unit" fi -# TODO: 'client' pkg fails with gosimple from generated files -# TODO: 'rafttest' is failing with unused -GOSIMPLE_UNUSED_PATHS=$(go list ./... | sed -e 's/github.com\/coreos\/etcd\///g' | grep -vE 'cmd|vendor|rafttest|github.com/coreos/etcd$|client$') - # Invoke ./cover for HTML output COVER=${COVER:-"-cover"} @@ -33,6 +29,10 @@ TEST_PKGS=`find . -name \*_test.go | while read a; do dirname $a; done | sort | FORMATTABLE=`find . -name \*.go | while read a; do echo $(dirname $a)/"*.go"; done | sort | uniq | egrep -v "$IGNORE_PKGS" | sed "s|\./||g"` TESTABLE_AND_FORMATTABLE=`echo "$TEST_PKGS" | egrep -v "$INTEGRATION_PKGS"` +# TODO: 'client' pkg fails with gosimple from generated files +# TODO: 'rafttest' is failing with unused +GOSIMPLE_UNUSED_PATHS=`find . -name \*.go | while read a; do dirname $a; done | sort | uniq | egrep -v "$IGNORE_PKGS" | grep -v 'client'` + if [ -z "$GOARCH" ]; then GOARCH=$(go env GOARCH); fi @@ -178,7 +178,7 @@ function fmt_pass { if which gosimple >/dev/null; then echo "Checking gosimple..." for path in $GOSIMPLE_UNUSED_PATHS; do - simplResult=`gosimple $REPO_PATH/${path} || true` + simplResult=`gosimple ${path} 2>&1 || true` if [ -n "${simplResult}" ]; then echo -e "gosimple checking ${path} failed:\n${simplResult}" exit 255 @@ -187,11 +187,11 @@ function fmt_pass { else echo "Skipping gosimple..." fi - + if which unused >/dev/null; then echo "Checking unused..." for path in $GOSIMPLE_UNUSED_PATHS; do - unusedResult=`unused $REPO_PATH/${path} || true` + unusedResult=`unused ${path} 2>&1 || true` if [ -n "${unusedResult}" ]; then echo -e "unused checking ${path} failed:\n${unusedResult}" exit 255 From 55307d48ac6ac1870139c12ca266f61ddf449574 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 12:05:19 -0800 Subject: [PATCH 2/8] auth: fix gosimple errors --- auth/store.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/auth/store.go b/auth/store.go index 9e170188c..20a1c6834 100644 --- a/auth/store.go +++ b/auth/store.go @@ -459,11 +459,7 @@ func (as *authStore) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, if user == nil { return nil, ErrUserNotFound } - - for _, role := range user.Roles { - resp.Roles = append(resp.Roles, role) - } - + resp.Roles = append(resp.Roles, user.Roles...) return &resp, nil } @@ -529,11 +525,7 @@ func (as *authStore) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, if role == nil { return nil, ErrRoleNotFound } - - for _, perm := range role.KeyPermission { - resp.Perm = append(resp.Perm, perm) - } - + resp.Perm = append(resp.Perm, role.KeyPermission...) return &resp, nil } From f3cb93015ca07fc804ff8369d1bf7fcdfa3d5fb0 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 13:06:38 -0800 Subject: [PATCH 3/8] integration: simplify boolean comparison in resp.Created --- integration/v3_watch_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/v3_watch_test.go b/integration/v3_watch_test.go index b7762f3fb..ad99fac71 100644 --- a/integration/v3_watch_test.go +++ b/integration/v3_watch_test.go @@ -717,7 +717,7 @@ func testV3WatchMultipleEventsTxn(t *testing.T, startRev int64) { if err := wStream.Send(wreq); err != nil { t.Fatalf("wStream.Send error: %v", err) } - if resp, err := wStream.Recv(); err != nil || resp.Created == false { + if resp, err := wStream.Recv(); err != nil || !resp.Created { t.Fatalf("create response failed: resp=%v, err=%v", resp, err) } From 0c5d1d5641a528666b3b47a9033d809869fdeb87 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 13:10:54 -0800 Subject: [PATCH 4/8] raft: simplify boolean comparison, remove unused --- raft/raft_test.go | 10 ---------- raft/rawnode_test.go | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/raft/raft_test.go b/raft/raft_test.go index 7e2e48434..371bc24ce 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -1321,10 +1321,6 @@ func TestRecvMsgVote(t *testing.T) { testRecvMsgVote(t, pb.MsgVote) } -func testRecvMsgPreVote(t *testing.T) { - testRecvMsgVote(t, pb.MsgPreVote) -} - func testRecvMsgVote(t *testing.T, msgType pb.MessageType) { tests := []struct { state StateType @@ -2925,12 +2921,6 @@ func TestTransferNonMember(t *testing.T) { } } -// ents creates a raft state machine with a sequence of log entries at -// the given terms. -func ents(terms ...uint64) *raft { - return entsWithConfig(nil, terms...) -} - func entsWithConfig(configFunc func(*Config), terms ...uint64) *raft { storage := NewMemoryStorage() for i, term := range terms { diff --git a/raft/rawnode_test.go b/raft/rawnode_test.go index 6e98663ba..7b3683058 100644 --- a/raft/rawnode_test.go +++ b/raft/rawnode_test.go @@ -128,7 +128,7 @@ func TestRawNodeReadIndex(t *testing.T) { rawNode.raft.readStates = wrs // ensure the ReadStates can be read out hasReady := rawNode.HasReady() - if hasReady != true { + if !hasReady { t.Errorf("HasReady() returns %t, want %t", hasReady, true) } rd := rawNode.Ready() From b8e09bf849c18ef2c41b5a5c83738b467c73ad29 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 13:15:04 -0800 Subject: [PATCH 5/8] tools: simplify boolean comparison, remove unused --- tools/etcd-dump-db/main.go | 3 --- tools/functional-tester/etcd-agent/main.go | 2 +- tools/functional-tester/etcd-tester/key_stresser.go | 1 - tools/functional-tester/etcd-tester/v2_stresser.go | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/etcd-dump-db/main.go b/tools/etcd-dump-db/main.go index f6c9a309c..b5262c90b 100644 --- a/tools/etcd-dump-db/main.go +++ b/tools/etcd-dump-db/main.go @@ -49,9 +49,6 @@ var ( var ( iterateBucketName string iterateBucketLimit uint64 - - revertCopyPath string - revertRevision int64 ) func init() { diff --git a/tools/functional-tester/etcd-agent/main.go b/tools/functional-tester/etcd-agent/main.go index 1dfc9c5ff..004b959b3 100644 --- a/tools/functional-tester/etcd-agent/main.go +++ b/tools/functional-tester/etcd-agent/main.go @@ -44,7 +44,7 @@ func main() { fmt.Println("got --use-root=true but not root user") os.Exit(1) } - if *useRoot == false { + if !*useRoot { fmt.Println("root permissions disabled, agent will not modify network") } diff --git a/tools/functional-tester/etcd-tester/key_stresser.go b/tools/functional-tester/etcd-tester/key_stresser.go index bd818b890..e049a62c9 100644 --- a/tools/functional-tester/etcd-tester/key_stresser.go +++ b/tools/functional-tester/etcd-tester/key_stresser.go @@ -42,7 +42,6 @@ type keyStresser struct { rateLimiter *rate.Limiter - mu sync.Mutex wg sync.WaitGroup cancel func() diff --git a/tools/functional-tester/etcd-tester/v2_stresser.go b/tools/functional-tester/etcd-tester/v2_stresser.go index 5ee1729ed..39fbd722c 100644 --- a/tools/functional-tester/etcd-tester/v2_stresser.go +++ b/tools/functional-tester/etcd-tester/v2_stresser.go @@ -41,7 +41,6 @@ type v2Stresser struct { wg sync.WaitGroup - mu sync.Mutex atomicModifiedKey int64 cancel func() From 3512f114e4df406c1db7c79819d60404b36e091d Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 13:19:47 -0800 Subject: [PATCH 6/8] e2e: remove unused 'ctlV3GetFailPerm' --- e2e/ctl_v3_auth_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/e2e/ctl_v3_auth_test.go b/e2e/ctl_v3_auth_test.go index 3b5107f46..605762e25 100644 --- a/e2e/ctl_v3_auth_test.go +++ b/e2e/ctl_v3_auth_test.go @@ -325,10 +325,6 @@ func ctlV3PutFailAuthDisabled(cx ctlCtx, key, val string) error { return spawnWithExpect(append(cx.PrefixArgs(), "put", key, val), "authentication is not enabled") } -func ctlV3GetFailPerm(cx ctlCtx, key string) error { - return spawnWithExpect(append(cx.PrefixArgs(), "get", key), "permission denied") -} - func authSetupTestUser(cx ctlCtx) { if err := ctlV3User(cx, []string{"add", "test-user", "--interactive=false"}, "User test-user created", []string{"pass"}); err != nil { cx.t.Fatal(err) From eb8646a381e23e8cbbb3382786fe9a5fed03a248 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 13:25:36 -0800 Subject: [PATCH 7/8] v3rpc: remove unused 'splitMethodName' function --- etcdserver/api/v3rpc/interceptor.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/etcdserver/api/v3rpc/interceptor.go b/etcdserver/api/v3rpc/interceptor.go index 7b693bf61..29aef2914 100644 --- a/etcdserver/api/v3rpc/interceptor.go +++ b/etcdserver/api/v3rpc/interceptor.go @@ -15,7 +15,6 @@ package v3rpc import ( - "strings" "sync" "time" @@ -95,14 +94,6 @@ func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor } } -func splitMethodName(fullMethodName string) (string, string) { - fullMethodName = strings.TrimPrefix(fullMethodName, "/") // remove leading slash - if i := strings.Index(fullMethodName, "/"); i >= 0 { - return fullMethodName[:i], fullMethodName[i+1:] - } - return "unknown", "unknown" -} - type serverStreamWithCtx struct { grpc.ServerStream ctx context.Context From 7e74b3f846922c59509341bb4e28b227a5f4ddee Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 9 Dec 2016 14:31:29 -0800 Subject: [PATCH 8/8] grpcproxy: remove unused field 'wbs *watchBroadcasts' --- proxy/grpcproxy/watch_broadcast.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/proxy/grpcproxy/watch_broadcast.go b/proxy/grpcproxy/watch_broadcast.go index 29fca0d8a..5529fb5a2 100644 --- a/proxy/grpcproxy/watch_broadcast.go +++ b/proxy/grpcproxy/watch_broadcast.go @@ -25,8 +25,6 @@ import ( // watchBroadcast broadcasts a server watcher to many client watchers. type watchBroadcast struct { - // wbs is the backpointer to all broadcasts on this range - wbs *watchBroadcasts // cancel stops the underlying etcd server watcher and closes ch. cancel context.CancelFunc donec chan struct{}