Merge pull request #5008 from gyuho/gosimple_unused

clean up with gosimple and unused
This commit is contained in:
Gyu-Ho Lee 2016-04-07 23:31:21 -07:00
commit 4041bbe571
16 changed files with 68 additions and 58 deletions

View File

@ -22,6 +22,8 @@ env:
before_install:
- go get -v github.com/chzchzchz/goword
- go get -v honnef.co/go/simple/cmd/gosimple
- go get -v honnef.co/go/unused/cmd/unused
# disable godep restore override
install:

View File

@ -45,16 +45,6 @@ func NewUniqueKV(ctx context.Context, kv v3.KV, pfx, val string, opts ...v3.OpOp
}
}
func waitUpdate(ctx context.Context, client *v3.Client, key string, opts ...v3.OpOption) error {
cctx, cancel := context.WithCancel(ctx)
defer cancel()
wresp, ok := <-client.Watch(cctx, key, opts...)
if !ok {
return ctx.Err()
}
return wresp.Err()
}
func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) error {
cctx, cancel := context.WithCancel(ctx)
defer cancel()

View File

@ -81,9 +81,11 @@ func restoreEtcd() error {
return runCommands(10, 2*time.Second)
}
var clusterHealthRegex = regexp.MustCompile(".*cluster is healthy.*")
var lineSplit = regexp.MustCompile("\n+")
var colonSplit = regexp.MustCompile("\\:")
var (
clusterHealthRegex = regexp.MustCompile(".*cluster is healthy.*")
lineSplit = regexp.MustCompile("\n+")
colonSplit = regexp.MustCompile(`\:`)
)
func runCommands(maxRetry int, interval time.Duration) error {
var retryCnt int

View File

@ -104,7 +104,7 @@ func handleClusterHealth(c *cli.Context) {
}
checked = true
if result.Health == "true" || nresult.Health == true {
if result.Health == "true" || nresult.Health {
health = true
fmt.Printf("member %s is healthy: got healthy result from %s\n", m.ID, url)
} else {

View File

@ -42,18 +42,6 @@ var (
defaultDialTimeout = 30 * time.Second
)
// trimsplit slices s into all substrings separated by sep and returns a
// slice of the substrings between the separator with all leading and trailing
// white space removed, as defined by Unicode.
func trimsplit(s, sep string) []string {
raw := strings.Split(s, ",")
trimmed := make([]string, 0)
for _, r := range raw {
trimmed = append(trimmed, strings.TrimSpace(r))
}
return trimmed
}
func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
if i < len(args) {
return args[i], nil

View File

@ -22,10 +22,7 @@ import (
"github.com/spf13/cobra"
)
var (
memberID uint64
memberPeerURLs string
)
var memberPeerURLs string
// NewMemberCommand returns the cobra command for "member".
func NewMemberCommand() *cobra.Command {

View File

@ -416,7 +416,7 @@ func TestCreateAndUpdateUser(t *testing.T) {
s := store{server: d, timeout: testTimeout, ensuredOnce: true, PasswordStore: fastPasswordStore{}}
out, created, err := s.CreateOrUpdateUser(user)
if created == false {
if !created {
t.Error("Should have created user, instead updated?")
}
if err != nil {
@ -427,7 +427,7 @@ func TestCreateAndUpdateUser(t *testing.T) {
t.Error("UpdateUser doesn't match given update. Got", out, "expected", expected)
}
out, created, err = s.CreateOrUpdateUser(update)
if created == true {
if created {
t.Error("Should have updated user, instead created?")
}
if err != nil {
@ -572,6 +572,7 @@ func TestEnableAuth(t *testing.T) {
t.Error("Unexpected error", err)
}
}
func TestDisableAuth(t *testing.T) {
trueval := "true"
falseval := "false"

View File

@ -144,9 +144,7 @@ func (c *RaftCluster) PeerURLs() []string {
defer c.Unlock()
urls := make([]string, 0)
for _, p := range c.members {
for _, addr := range p.PeerURLs {
urls = append(urls, addr)
}
urls = append(urls, p.PeerURLs...)
}
sort.Strings(urls)
return urls
@ -159,9 +157,7 @@ func (c *RaftCluster) ClientURLs() []string {
defer c.Unlock()
urls := make([]string, 0)
for _, p := range c.members {
for _, url := range p.ClientURLs {
urls = append(urls, url)
}
urls = append(urls, p.ClientURLs...)
}
sort.Strings(urls)
return urls

View File

@ -85,7 +85,7 @@ func (q *statsQueue) Rate() (float64, float64) {
return 0, 0
}
if time.Now().Sub(back.SendingTime) > time.Second {
if time.Since(back.SendingTime) > time.Second {
q.Clear()
return 0, 0
}

View File

@ -57,7 +57,7 @@ func (ss *ServerStats) JSON() []byte {
ss.Lock()
stats := *ss
ss.Unlock()
stats.LeaderInfo.Uptime = time.Now().Sub(stats.LeaderInfo.StartTime).String()
stats.LeaderInfo.Uptime = time.Since(stats.LeaderInfo.StartTime).String()
stats.SendingPkgRate, stats.SendingBandwidthRate = stats.SendRates()
stats.RecvingPkgRate, stats.RecvingBandwidthRate = stats.RecvRates()
b, err := json.Marshal(stats)

View File

@ -48,7 +48,7 @@ func CheckLeakedGoroutine() bool {
}
stackCount := make(map[string]int)
re := regexp.MustCompile("\\(0[0-9a-fx, ]*\\)")
re := regexp.MustCompile(`\(0[0-9a-fx, ]*\)`)
for _, g := range gs {
// strip out pointer arguments in first function of stack dump
normalized := string(re.ReplaceAll([]byte(g), []byte("(...)")))

View File

@ -289,7 +289,7 @@ func (s *store) Compact(rev int64) (<-chan struct{}, error) {
s.fifoSched.Schedule(j)
indexCompactionPauseDurations.Observe(float64(time.Now().Sub(start) / time.Millisecond))
indexCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond))
return ch, nil
}

View File

@ -21,7 +21,7 @@ import (
func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) bool {
totalStart := time.Now()
defer dbCompactionTotalDurations.Observe(float64(time.Now().Sub(totalStart) / time.Millisecond))
defer dbCompactionTotalDurations.Observe(float64(time.Since(totalStart) / time.Millisecond))
end := make([]byte, 8)
binary.BigEndian.PutUint64(end, uint64(compactMainRev+1))
@ -54,7 +54,7 @@ func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struc
// update last
revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last)
tx.Unlock()
dbCompactionPauseDurations.Observe(float64(time.Now().Sub(start) / time.Millisecond))
dbCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond))
select {
case <-time.After(100 * time.Millisecond):

View File

@ -117,10 +117,7 @@ func (eh *EventHistory) clone() *EventHistory {
Back: eh.Queue.Back,
}
for i, e := range eh.Queue.Events {
clonedQueue.Events[i] = e
}
copy(clonedQueue.Events, eh.Queue.Events)
return &EventHistory{
StartIndex: eh.StartIndex,
Queue: clonedQueue,

View File

@ -345,7 +345,7 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
}
// recursive implies dir
if recursive == true {
if recursive {
dir = true
}

55
test
View File

@ -10,6 +10,10 @@
# PKG=snap ./test
set -e
# 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"}
@ -96,15 +100,48 @@ function fmt_tests {
done
echo "Checking goword..."
# get all go files to process
gofiles=`find $FMT -iname '*.go' 2>/dev/null`
# ignore tests and protobuf files
gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"`
# only check for broken exported godocs
gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort`
if [ ! -z "$gowordRes" ]; then
echo -e "goword checking failed:\n${gowordRes}"
exit 255
if which goword >/dev/null; then
echo "goword is installed..."
# get all go files to process
gofiles=`find $FMT -iname '*.go' 2>/dev/null`
# ignore tests and protobuf files
gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"`
# only check for broken exported godocs
gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort`
if [ ! -z "$gowordRes" ]; then
echo -e "goword checking failed:\n${gowordRes}"
exit 255
fi
else
echo "gowrod does not exist... skipping..."
fi
echo "Checking gosimple"
if which gosimple >/dev/null; then
echo "gosimple is installed..."
for path in $GOSIMPLE_UNUSED_PATHS; do
simplResult=$(gosimple $REPO_PATH/${path})
if [ -n "${simplResult}" ]; then
echo -e "gosimple checking ${path} failed:\n${simplResult}"
exit 255
fi
done
else
echo "gosimple does not exist... skipping..."
fi
echo "Checking unused"
if which unused >/dev/null; then
echo "unused is installed..."
for path in $GOSIMPLE_UNUSED_PATHS; do
unusedResult=$(unused $REPO_PATH/${path})
if [ -n "${unusedResult}" ]; then
echo -e "unused checking ${path} failed:\n${unusedResult}"
exit 255
fi
done
else
echo "unused does not exist... skipping..."
fi
echo "Checking for license header..."