Browse Source

Merge pull request #7703 from gyuho/rafthttp

rafthttp: move test-only functions to '_test.go'
Gyu-Ho Lee 8 years ago
parent
commit
7da79de74b
2 changed files with 27 additions and 27 deletions
  1. 0 27
      rafthttp/util.go
  2. 27 0
      rafthttp/util_test.go

+ 0 - 27
rafthttp/util.go

@@ -16,7 +16,6 @@ package rafthttp
 
 
 import (
 import (
 	"crypto/tls"
 	"crypto/tls"
-	"encoding/binary"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"net"
 	"net"
@@ -27,7 +26,6 @@ import (
 
 
 	"github.com/coreos/etcd/pkg/transport"
 	"github.com/coreos/etcd/pkg/transport"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/pkg/types"
-	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/version"
 	"github.com/coreos/etcd/version"
 	"github.com/coreos/go-semver/semver"
 	"github.com/coreos/go-semver/semver"
 )
 )
@@ -61,31 +59,6 @@ func newStreamRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration)
 	return transport.NewTimeoutTransport(tlsInfo, dialTimeout, ConnReadTimeout, ConnWriteTimeout)
 	return transport.NewTimeoutTransport(tlsInfo, dialTimeout, ConnReadTimeout, ConnWriteTimeout)
 }
 }
 
 
-func writeEntryTo(w io.Writer, ent *raftpb.Entry) error {
-	size := ent.Size()
-	if err := binary.Write(w, binary.BigEndian, uint64(size)); err != nil {
-		return err
-	}
-	b, err := ent.Marshal()
-	if err != nil {
-		return err
-	}
-	_, err = w.Write(b)
-	return err
-}
-
-func readEntryFrom(r io.Reader, ent *raftpb.Entry) error {
-	var l uint64
-	if err := binary.Read(r, binary.BigEndian, &l); err != nil {
-		return err
-	}
-	buf := make([]byte, int(l))
-	if _, err := io.ReadFull(r, buf); err != nil {
-		return err
-	}
-	return ent.Unmarshal(buf)
-}
-
 // createPostRequest creates a HTTP POST request that sends raft message.
 // createPostRequest creates a HTTP POST request that sends raft message.
 func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request {
 func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request {
 	uu := u
 	uu := u

+ 27 - 0
rafthttp/util_test.go

@@ -16,6 +16,8 @@ package rafthttp
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"encoding/binary"
+	"io"
 	"net/http"
 	"net/http"
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
@@ -191,3 +193,28 @@ func TestCheckVersionCompatibility(t *testing.T) {
 		}
 		}
 	}
 	}
 }
 }
+
+func writeEntryTo(w io.Writer, ent *raftpb.Entry) error {
+	size := ent.Size()
+	if err := binary.Write(w, binary.BigEndian, uint64(size)); err != nil {
+		return err
+	}
+	b, err := ent.Marshal()
+	if err != nil {
+		return err
+	}
+	_, err = w.Write(b)
+	return err
+}
+
+func readEntryFrom(r io.Reader, ent *raftpb.Entry) error {
+	var l uint64
+	if err := binary.Read(r, binary.BigEndian, &l); err != nil {
+		return err
+	}
+	buf := make([]byte, int(l))
+	if _, err := io.ReadFull(r, buf); err != nil {
+		return err
+	}
+	return ent.Unmarshal(buf)
+}