-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
58 lines (46 loc) · 1.12 KB
/
server.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
51
52
53
54
55
56
57
58
package e2e
import (
"net/http"
"net/http/httptest"
)
func startMockServer() *httptest.Server {
handler := http.NewServeMux()
handler.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
body := `
# robotstxt.org/
User-agent: *
Disallow: /forbidden`
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(body))
})
handler.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
body := `
<html>
<h1>Home</h1>
<a href="/about">About</a>
<a href="/forbidden">Forbidden</a>
<a href="https://monzo.com">First</a>
</html>`
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(body))
})
handler.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
body := `
<html>
<h1>About</h1>
<a href="/">Index</a>
<a href="/contact">Contact</a>
</html>`
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(body))
})
handler.HandleFunc("/contact", func(w http.ResponseWriter, r *http.Request) {
body := `
<html>
<h1>Contact</h1>
</html>`
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(body))
})
return httptest.NewServer(handler)
}