瀏覽代碼

*: clean up if, bool comparison

Gyu-Ho Lee 9 年之前
父節點
當前提交
b0cc0e443c

+ 1 - 1
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)
 		}
 

+ 3 - 3
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

+ 1 - 1
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)
 		}
 

+ 1 - 1
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 {

+ 3 - 3
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)
 	}
 }

+ 1 - 1
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)
 		}
 

+ 1 - 1
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
 		}

+ 2 - 2
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)
 	}
 }

+ 1 - 8
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
 	}