mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-09 19:21:52 +08:00
Use the readable indentation for error flow
This commit is contained in:
parent
d710784914
commit
e09914bfa3
33
cmux_test.go
33
cmux_test.go
@ -109,21 +109,23 @@ func runTestHTTPServer(errCh chan<- error, l net.Listener) {
|
||||
}
|
||||
|
||||
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)
|
||||
} else {
|
||||
defer func() {
|
||||
if err := r.Body.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
if b, err := ioutil.ReadAll(r.Body); err != nil {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err = r.Body.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if string(b) != testHTTP1Resp {
|
||||
t.Fatalf("invalid response: want=%s got=%s", testHTTP1Resp, b)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(b) != testHTTP1Resp {
|
||||
t.Fatalf("invalid response: want=%s got=%s", testHTTP1Resp, b)
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,9 +210,12 @@ func TestRead(t *testing.T) {
|
||||
}
|
||||
for i := 0; i < mult; i++ {
|
||||
var b [len(payload)]byte
|
||||
if n, err := muxedConn.Read(b[:]); err != nil {
|
||||
n, err := muxedConn.Read(b[:])
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user