-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
service_test.go
50 lines (39 loc) · 992 Bytes
/
service_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
43
44
45
46
47
48
49
50
package bartender_test
import (
"net/http"
"testing"
"github.com/go-rod/bartender"
"github.com/ysmood/got"
)
func TestBasic(t *testing.T) {
g := got.T(t)
website := g.Serve()
website.Route("/a.png", ".png", "image")
website.Route("/", ".html", `<html>
<body></body>
<script>
window.onload = () => {
document.body.innerHTML = location.pathname + location.search
}
</script>
</html>`)
proxy := g.Serve()
bt := bartender.New("", website.URL(), 2)
proxy.Mux.HandleFunc("/", bt.ServeHTTP)
{
//nolint: lll
// browser
res := g.Req("", proxy.URL("/test?q=ok"), http.Header{"User-Agent": {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}})
g.Has(res.String(), "<body></body>")
}
{
// web crawler
res := g.Req("", proxy.URL("/test?q=ok"))
g.Has(res.String(), "/test?q=ok")
}
{
// can get image
res := g.Req("", proxy.URL("/a.png"))
g.Has(res.String(), "image")
}
}