Merge pull request #8857 from gyuho/test

*: fix naked returns, integrate with CI
This commit is contained in:
Gyu-Ho Lee 2017-11-10 19:12:26 -08:00 committed by GitHub
commit 43dfefe9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 47 additions and 36 deletions

View File

@ -51,6 +51,7 @@ RUN go get -v -u -tags spell github.com/chzchzchz/goword \
&& go get -v -u honnef.co/go/tools/cmd/staticcheck \ && go get -v -u honnef.co/go/tools/cmd/staticcheck \
&& go get -v -u github.com/wadey/gocovmerge \ && go get -v -u github.com/wadey/gocovmerge \
&& go get -v -u github.com/gordonklaus/ineffassign \ && go get -v -u github.com/gordonklaus/ineffassign \
&& go get -v -u github.com/alexkohler/nakedret \
&& /tmp/install-marker.sh amd64 \ && /tmp/install-marker.sh amd64 \
&& rm -f /tmp/install-marker.sh \ && rm -f /tmp/install-marker.sh \
&& curl -s https://codecov.io/bash >/codecov \ && curl -s https://codecov.io/bash >/codecov \

View File

@ -653,8 +653,7 @@ func unmarshalHTTPResponse(code int, header http.Header, body []byte) (res *Resp
default: default:
err = unmarshalFailedKeysResponse(body) err = unmarshalFailedKeysResponse(body)
} }
return res, err
return
} }
func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) { func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) {

View File

@ -192,7 +192,7 @@ func parseEndpoint(endpoint string) (proto string, host string, scheme string) {
host = endpoint host = endpoint
url, uerr := url.Parse(endpoint) url, uerr := url.Parse(endpoint)
if uerr != nil || !strings.Contains(endpoint, "://") { if uerr != nil || !strings.Contains(endpoint, "://") {
return return proto, host, scheme
} }
scheme = url.Scheme scheme = url.Scheme
@ -206,7 +206,7 @@ func parseEndpoint(endpoint string) (proto string, host string, scheme string) {
default: default:
proto, host = "", "" proto, host = "", ""
} }
return return proto, host, scheme
} }
func (c *Client) processCreds(scheme string) (creds *credentials.TransportCredentials) { func (c *Client) processCreds(scheme string) (creds *credentials.TransportCredentials) {
@ -225,7 +225,7 @@ func (c *Client) processCreds(scheme string) (creds *credentials.TransportCreden
default: default:
creds = nil creds = nil
} }
return return creds
} }
// dialSetupOpts gives the dial opts prior to any authentication // dialSetupOpts gives the dial opts prior to any authentication

View File

@ -133,7 +133,7 @@ func (rc *raftNode) entriesToApply(ents []raftpb.Entry) (nents []raftpb.Entry) {
if rc.appliedIndex-firstIdx+1 < uint64(len(ents)) { if rc.appliedIndex-firstIdx+1 < uint64(len(ents)) {
nents = ents[rc.appliedIndex-firstIdx+1:] nents = ents[rc.appliedIndex-firstIdx+1:]
} }
return return nents
} }
// publishEntries writes committed log entries to commit channel and returns // publishEntries writes committed log entries to commit channel and returns

View File

@ -108,10 +108,10 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
}() }()
if e.Peers, err = startPeerListeners(cfg); err != nil { if e.Peers, err = startPeerListeners(cfg); err != nil {
return return e, err
} }
if e.sctxs, err = startClientListeners(cfg); err != nil { if e.sctxs, err = startClientListeners(cfg); err != nil {
return return e, err
} }
for _, sctx := range e.sctxs { for _, sctx := range e.sctxs {
e.Clients = append(e.Clients, sctx.l) e.Clients = append(e.Clients, sctx.l)
@ -177,7 +177,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
} }
if e.Server, err = etcdserver.NewServer(srvcfg); err != nil { if e.Server, err = etcdserver.NewServer(srvcfg); err != nil {
return return e, err
} }
// buffer channel so goroutines on closed connections won't wait forever // buffer channel so goroutines on closed connections won't wait forever
@ -190,7 +190,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
var peerTLScfg *tls.Config var peerTLScfg *tls.Config
if !cfg.PeerTLSInfo.Empty() { if !cfg.PeerTLSInfo.Empty() {
if peerTLScfg, err = cfg.PeerTLSInfo.ServerConfig(); err != nil { if peerTLScfg, err = cfg.PeerTLSInfo.ServerConfig(); err != nil {
return return e, err
} }
} }
for _, p := range e.Peers { for _, p := range e.Peers {
@ -214,10 +214,10 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
} }
if err = e.serve(); err != nil { if err = e.serve(); err != nil {
return return e, err
} }
serving = true serving = true
return return e, nil
} }
// Config returns the current configuration. // Config returns the current configuration.

View File

@ -169,7 +169,7 @@ func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string
strings.Join(m.ClientURLs, ","), strings.Join(m.ClientURLs, ","),
}) })
} }
return return hdr, rows
} }
func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) { func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) {
@ -185,7 +185,7 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri
fmt.Sprint(status.Resp.RaftIndex), fmt.Sprint(status.Resp.RaftIndex),
}) })
} }
return return hdr, rows
} }
func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) { func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) {
@ -196,7 +196,7 @@ func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string
fmt.Sprint(h.Resp.Hash), fmt.Sprint(h.Resp.Hash),
}) })
} }
return return hdr, rows
} }
func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) { func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) {
@ -207,5 +207,5 @@ func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) {
fmt.Sprint(ds.TotalKey), fmt.Sprint(ds.TotalKey),
humanize.Bytes(uint64(ds.TotalSize)), humanize.Bytes(uint64(ds.TotalSize)),
}) })
return return hdr, rows
} }

View File

@ -416,7 +416,7 @@ func startNode(cfg ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id
raftStatus = n.Status raftStatus = n.Status
raftStatusMu.Unlock() raftStatusMu.Unlock()
advanceTicksForElection(n, c.ElectionTick) advanceTicksForElection(n, c.ElectionTick)
return return id, n, s, w
} }
func restartNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { func restartNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) {

View File

@ -94,5 +94,5 @@ func readWAL(waldir string, snap walpb.Snapshot) (w *wal.WAL, id, cid types.ID,
pbutil.MustUnmarshal(&metadata, wmetadata) pbutil.MustUnmarshal(&metadata, wmetadata)
id = types.ID(metadata.NodeID) id = types.ID(metadata.NodeID)
cid = types.ID(metadata.ClusterID) cid = types.ID(metadata.ClusterID)
return return w, id, cid, st, ents
} }

View File

@ -224,5 +224,5 @@ func (b *bridge) ioCopy(bc *bridgeConn, dst io.Writer, src io.Reader) (err error
break break
} }
} }
return return err
} }

View File

@ -151,7 +151,7 @@ func newEmbedURLs(n int) (urls []url.URL) {
u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d%06d", os.Getpid(), i)) u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d%06d", os.Getpid(), i))
urls = append(urls, *u) urls = append(urls, *u)
} }
return return urls
} }
func setupEmbedCfg(cfg *embed.Config, curls []url.URL, purls []url.URL) { func setupEmbedCfg(cfg *embed.Config, curls []url.URL, purls []url.URL) {

View File

@ -121,5 +121,5 @@ func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.O
err = syscall.EINVAL err = syscall.EINVAL
} }
} }
return return err
} }

View File

@ -246,5 +246,5 @@ func parsePREFSRC(m *syscall.NetlinkMessage) (host string, oif uint32, err error
if oif == 0 { if oif == 0 {
err = errNoDefaultRoute err = errNoDefaultRoute
} }
return return host, oif, err
} }

View File

@ -127,13 +127,13 @@ func copyMap(m map[string]int) (c map[string]int) {
for k, v := range m { for k, v := range m {
c[k] = v c[k] = v
} }
return return c
} }
func copyFloats(s []float64) (c []float64) { func copyFloats(s []float64) (c []float64) {
c = make([]float64, len(s)) c = make([]float64, len(s))
copy(c, s) copy(c, s)
return return c
} }
func (r *report) String() (s string) { func (r *report) String() (s string) {
@ -221,7 +221,7 @@ func percentiles(nums []float64) (data []float64) {
j++ j++
} }
} }
return return data
} }
func (r *report) sprintLatencies() string { func (r *report) sprintLatencies() string {

View File

@ -135,5 +135,5 @@ func interestingGoroutines() (gs []string) {
gs = append(gs, stack) gs = append(gs, stack)
} }
sort.Strings(gs) sort.Strings(gs)
return return gs
} }

View File

@ -79,7 +79,7 @@ func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) {
kac.SetKeepAlive(true) kac.SetKeepAlive(true)
kac.SetKeepAlivePeriod(30 * time.Second) kac.SetKeepAlivePeriod(30 * time.Second)
c = tls.Server(c, l.config) c = tls.Server(c, l.config)
return return c, nil
} }
// NewListener creates a Listener which accepts connections from an inner // NewListener creates a Listener which accepts connections from an inner

View File

@ -61,7 +61,7 @@ func (us *unsafeSet) Remove(value string) {
// Contains returns whether the set contains the given value // Contains returns whether the set contains the given value
func (us *unsafeSet) Contains(value string) (exists bool) { func (us *unsafeSet) Contains(value string) (exists bool) {
_, exists = us.d[value] _, exists = us.d[value]
return return exists
} }
// ContainsAll returns whether the set contains all given values // ContainsAll returns whether the set contains all given values
@ -94,7 +94,7 @@ func (us *unsafeSet) Values() (values []string) {
for val := range us.d { for val := range us.d {
values = append(values, val) values = append(values, val)
} }
return return values
} }
// Copy creates a new Set containing the values of the first // Copy creates a new Set containing the values of the first

View File

@ -350,7 +350,7 @@ func (n *node) Compare(prevValue string, prevIndex uint64) (ok bool, which int)
default: default:
which = CompareNotMatch which = CompareNotMatch
} }
return return ok, which
} }
// Clone function clone the node recursively and return the new node. // Clone function clone the node recursively and return the new node.

11
test
View File

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

View File

@ -40,7 +40,7 @@ func getBuckets(dbPath string) (buckets []string, err error) {
return nil return nil
}) })
}) })
return return buckets, err
} }
func iterateBucket(dbPath, bucket string, limit uint64) (err error) { func iterateBucket(dbPath, bucket string, limit uint64) (err error) {
@ -70,7 +70,7 @@ func iterateBucket(dbPath, bucket string, limit uint64) (err error) {
return nil return nil
}) })
return return err
} }
func getHash(dbPath string) (hash uint32, err error) { func getHash(dbPath string) (hash uint32, err error) {

View File

@ -141,7 +141,7 @@ func parseWALMetadata(b []byte) (id, cid types.ID) {
pbutil.MustUnmarshal(&metadata, b) pbutil.MustUnmarshal(&metadata, b)
id = types.ID(metadata.NodeID) id = types.ID(metadata.NodeID)
cid = types.ID(metadata.ClusterID) cid = types.ID(metadata.ClusterID)
return return id, cid
} }
func genIDSlice(a []uint64) []types.ID { func genIDSlice(a []uint64) []types.ID {

View File

@ -119,7 +119,7 @@ func decodeFrameSize(lenField int64) (recBytes int64, padBytes int64) {
// padding is stored in lower 3 bits of length MSB // padding is stored in lower 3 bits of length MSB
padBytes = int64((uint64(lenField) >> 56) & 0x7) padBytes = int64((uint64(lenField) >> 56) & 0x7)
} }
return return recBytes, padBytes
} }
// isTornEntry determines whether the last entry of the WAL was partially written // isTornEntry determines whether the last entry of the WAL was partially written

View File

@ -103,7 +103,7 @@ func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) {
if padBytes != 0 { if padBytes != 0 {
lenField |= uint64(0x80|padBytes) << 56 lenField |= uint64(0x80|padBytes) << 56
} }
return return lenField, padBytes
} }
func (e *encoder) flush() error { func (e *encoder) flush() error {

View File

@ -55,7 +55,7 @@ func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) {
case f = <-fp.filec: case f = <-fp.filec:
case err = <-fp.errc: case err = <-fp.errc:
} }
return return f, err
} }
func (fp *filePipeline) Close() error { func (fp *filePipeline) Close() error {