2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-10 11:41:52 +08:00

Merge pull request #21 from soheilhy/devel

Use the readable indentation for error flow
This commit is contained in:
Soheil Hassas Yeganeh 2016-02-27 18:16:04 -05:00
commit 7ec7ce7ad1

View File

@ -109,23 +109,25 @@ func runTestHTTPServer(errCh chan<- error, l net.Listener) {
} }
func runTestHTTP1Client(t *testing.T, addr net.Addr) { func runTestHTTP1Client(t *testing.T, addr net.Addr) {
if r, err := http.Get("http://" + addr.String()); err != nil { r, err := http.Get("http://" + addr.String())
if err != nil {
t.Fatal(err) t.Fatal(err)
} else { }
defer func() { defer func() {
if err := r.Body.Close(); err != nil { if err = r.Body.Close(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
}() }()
if b, err := ioutil.ReadAll(r.Body); err != nil {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err) t.Fatal(err)
} else { }
if string(b) != testHTTP1Resp { if string(b) != testHTTP1Resp {
t.Fatalf("invalid response: want=%s got=%s", testHTTP1Resp, b) t.Fatalf("invalid response: want=%s got=%s", testHTTP1Resp, b)
} }
} }
}
}
type TestRPCRcvr struct{} type TestRPCRcvr struct{}
@ -208,9 +210,12 @@ func TestRead(t *testing.T) {
} }
for i := 0; i < mult; i++ { for i := 0; i < mult; i++ {
var b [len(payload)]byte var b [len(payload)]byte
if n, err := muxedConn.Read(b[:]); err != nil { n, err := muxedConn.Read(b[:])
if err != nil {
t.Error(err) t.Error(err)
} else if e := len(b); n != e { continue
}
if e := len(b); n != e {
t.Errorf("expected to read %d bytes, but read %d bytes", e, n) t.Errorf("expected to read %d bytes, but read %d bytes", e, n)
} }
} }