From b0cc0e443c163f36f29d078dd855ca9c7b68e612 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sat, 2 Apr 2016 12:55:11 -0700 Subject: [PATCH] *: clean up if, bool comparison --- clientv3/integration/watch_test.go | 2 +- clientv3/op.go | 6 +++--- clientv3/watch.go | 2 +- e2e/etcd_test.go | 2 +- etcdserver/server_test.go | 6 +++--- integration/v3_grpc_test.go | 2 +- integration/v3_watch_test.go | 2 +- pkg/fileutil/fileutil_test.go | 4 ++-- storage/key_index.go | 9 +-------- 9 files changed, 14 insertions(+), 21 deletions(-) diff --git a/clientv3/integration/watch_test.go b/clientv3/integration/watch_test.go index c24249344..f5e6deda6 100644 --- a/clientv3/integration/watch_test.go +++ b/clientv3/integration/watch_test.go @@ -124,7 +124,7 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) { got = append(got, string(ev.Kv.Value)) } sort.Strings(got) - if reflect.DeepEqual(expected, got) == false { + if !reflect.DeepEqual(expected, got) { t.Errorf("got %v, expected %v", got, expected) } diff --git a/clientv3/op.go b/clientv3/op.go index b0e715f5b..fb29f47c0 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -95,7 +95,7 @@ func OpDelete(key string, opts ...OpOption) Op { panic("unexpected revision in delete") case ret.sort != nil: panic("unexpected sort in delete") - case ret.serializable != false: + case ret.serializable: panic("unexpected serializable in delete") } return ret @@ -113,7 +113,7 @@ func OpPut(key, val string, opts ...OpOption) Op { panic("unexpected revision in put") case ret.sort != nil: panic("unexpected sort in put") - case ret.serializable != false: + case ret.serializable: panic("unexpected serializable in delete") } return ret @@ -129,7 +129,7 @@ func opWatch(key string, opts ...OpOption) Op { panic("unexpected limit in watch") case ret.sort != nil: panic("unexpected sort in watch") - case ret.serializable != false: + case ret.serializable: panic("unexpected serializable in watch") } return ret diff --git a/clientv3/watch.go b/clientv3/watch.go index fc49dd17e..5633caa5c 100644 --- a/clientv3/watch.go +++ b/clientv3/watch.go @@ -521,7 +521,7 @@ func (w *watcher) resumeWatchers(wc pb.Watch_WatchClient) error { resp, err := wc.Recv() if err != nil { return err - } else if len(resp.Events) != 0 || resp.Created != true { + } else if len(resp.Events) != 0 || !resp.Created { return fmt.Errorf("watcher: unexpected response (%+v)", resp) } diff --git a/e2e/etcd_test.go b/e2e/etcd_test.go index 559f78c32..4cc8534ce 100644 --- a/e2e/etcd_test.go +++ b/e2e/etcd_test.go @@ -275,7 +275,7 @@ func newEtcdProcessCluster(cfg *etcdProcessClusterConfig) (*etcdProcessCluster, } func newEtcdProcess(cfg *etcdProcessConfig) (*etcdProcess, error) { - if fileutil.Exist("../bin/etcd") == false { + if !fileutil.Exist("../bin/etcd") { return nil, fmt.Errorf("could not find etcd binary") } if err := os.RemoveAll(cfg.dataDirPath); err != nil { diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 2e17d3fad..ffecedef4 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -563,7 +563,7 @@ func TestApplyConfChangeShouldStop(t *testing.T) { if err != nil { t.Fatalf("unexpected error %v", err) } - if shouldStop != false { + if shouldStop { t.Errorf("shouldStop = %t, want %t", shouldStop, false) } @@ -573,7 +573,7 @@ func TestApplyConfChangeShouldStop(t *testing.T) { if err != nil { t.Fatalf("unexpected error %v", err) } - if shouldStop != true { + if !shouldStop { t.Errorf("shouldStop = %t, want %t", shouldStop, true) } } @@ -610,7 +610,7 @@ func TestApplyMultiConfChangeShouldStop(t *testing.T) { } _, shouldStop := srv.apply(ents, &raftpb.ConfState{}) - if shouldStop == false { + if !shouldStop { t.Errorf("shouldStop = %t, want %t", shouldStop, true) } } diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index e17ac9e80..c794eea8c 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -362,7 +362,7 @@ func TestV3DeleteRange(t *testing.T) { for j := range rresp.Kvs { keys = append(keys, rresp.Kvs[j].Key) } - if reflect.DeepEqual(tt.wantSet, keys) == false { + if !reflect.DeepEqual(tt.wantSet, keys) { t.Errorf("expected %v on test %v, got %v", tt.wantSet, i, keys) } diff --git a/integration/v3_watch_test.go b/integration/v3_watch_test.go index 79da449ad..083926012 100644 --- a/integration/v3_watch_test.go +++ b/integration/v3_watch_test.go @@ -226,7 +226,7 @@ func TestV3WatchFromCurrentRevision(t *testing.T) { t.Errorf("#%d: wStream.Recv error: %v", i, err) continue } - if cresp.Created != true { + if !cresp.Created { t.Errorf("#%d: did not create watchid, got +%v", i, cresp) continue } diff --git a/pkg/fileutil/fileutil_test.go b/pkg/fileutil/fileutil_test.go index 3d914b3ad..89d12088c 100644 --- a/pkg/fileutil/fileutil_test.go +++ b/pkg/fileutil/fileutil_test.go @@ -87,12 +87,12 @@ func TestExist(t *testing.T) { } f.Close() - if g := Exist(f.Name()); g != true { + if g := Exist(f.Name()); !g { t.Errorf("exist = %v, want true", g) } os.Remove(f.Name()) - if g := Exist(f.Name()); g != false { + if g := Exist(f.Name()); g { t.Errorf("exist = %v, want false", g) } } diff --git a/storage/key_index.go b/storage/key_index.go index 550169464..e8a344ec2 100644 --- a/storage/key_index.go +++ b/storage/key_index.go @@ -131,14 +131,7 @@ func (ki *keyIndex) get(atRev int64) (modified, created revision, ver int64, err return revision{}, revision{}, 0, ErrRevisionNotFound } - f := func(rev revision) bool { - if rev.main <= atRev { - return false - } - return true - } - - n := g.walk(f) + n := g.walk(func(rev revision) bool { return rev.main > atRev }) if n != -1 { return g.revs[n], g.created, g.ver - int64(len(g.revs)-n-1), nil }