-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathhost_serve_mux_test.go
70 lines (64 loc) · 1.79 KB
/
host_serve_mux_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package tigertonic
import (
"net/http"
"testing"
)
func TestHostnameFound(t *testing.T) {
mux := NewHostServeMux()
mux.HandleFunc("example.com", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
w := &testResponseWriter{}
r, _ := http.NewRequest("GET", "http://example.com/", nil)
mux.ServeHTTP(w, r)
if http.StatusNoContent != w.StatusCode {
t.Fatal(w.StatusCode)
}
}
func TestHostnameFoundInURL(t *testing.T) {
mux := NewHostServeMux()
mux.HandleFunc("example.com", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
w := &testResponseWriter{}
r, _ := http.NewRequest("GET", "http://example.com/", nil)
r.Host = ""
mux.ServeHTTP(w, r)
if http.StatusNoContent != w.StatusCode {
t.Fatal(w.StatusCode)
}
}
func TestHostnameNotFound(t *testing.T) {
mux := NewHostServeMux()
w := &testResponseWriter{}
r, _ := http.NewRequest("GET", "http://example.com/", nil)
mux.ServeHTTP(w, r)
if http.StatusNotFound != w.StatusCode {
t.Fatal(w.StatusCode)
}
}
func TestHostnameWithPortFound(t *testing.T) {
mux := NewHostServeMux()
mux.HandleFunc("example.com", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
w := &testResponseWriter{}
r, _ := http.NewRequest("GET", "http://example.com:80/", nil)
mux.ServeHTTP(w, r)
if http.StatusNoContent != w.StatusCode {
t.Fatal(w.StatusCode)
}
}
func TestHostnameWithPortFoundInURL(t *testing.T) {
mux := NewHostServeMux()
mux.HandleFunc("example.com", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
w := &testResponseWriter{}
r, _ := http.NewRequest("GET", "http://example.com:80/", nil)
r.Host = ""
mux.ServeHTTP(w, r)
if http.StatusNoContent != w.StatusCode {
t.Fatal(w.StatusCode)
}
}