-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathgout_global_setdebug_test.go
More file actions
45 lines (37 loc) · 921 Bytes
/
gout_global_setdebug_test.go
File metadata and controls
45 lines (37 loc) · 921 Bytes
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
43
44
45
package gout
import (
"bytes"
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Global_SetDebug(t *testing.T) {
router := setupDataFlow(t)
ts := httptest.NewServer(http.HandlerFunc(router.ServeHTTP))
defer ts.Close()
old := os.Stdout // keep backup of the real stdout
r, w, _ := os.Pipe()
os.Stdout = w
outC := make(chan string)
// copy the output in a separate goroutine so printing can't block indefinitely
go func() {
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
assert.NoError(t, err)
outC <- buf.String()
}()
// reading our temp stdout
// 只设置timeout
SetDebug(true) //设置全局超时时间
err := GET(ts.URL + "/setdebug").Do()
// back to normal state
w.Close()
os.Stdout = old // restoring the real stdout
out := <-outC
assert.NoError(t, err)
assert.NotEqual(t, strings.Index(out, "setdebug"), -1)
}