forked from winterssy/ghttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_test.go
42 lines (38 loc) · 946 Bytes
/
debug_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ghttp
import (
"fmt"
"io/ioutil"
"net/http"
neturl "net/url"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDebugger_Enter(t *testing.T) {
dummyRequest := &Request{
Request: &http.Request{
Method: MethodPost,
URL: &neturl.URL{
Scheme: "https",
Host: "httpbin.org",
Path: "/post",
},
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(http.Header),
Body: &dummyBody{errFlag: errRead},
Host: "httpbin.org",
},
}
debugger := &debugger{out: ioutil.Discard, body: true}
err := debugger.Enter(dummyRequest)
assert.Equal(t, errAccessDummyBody, err)
}
func TestDebugger_Exit(t *testing.T) {
var sb strings.Builder
debugger := &debugger{out: &sb, body: true}
var dummyResponse *Response
debugger.Exit(dummyResponse, errAccessDummyBody)
assert.Equal(t, fmt.Sprintf("* ghttp [ERROR] %s\r\n", errAccessDummyBody), sb.String())
}