-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_extensions_test.go
55 lines (53 loc) · 1.58 KB
/
http_extensions_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
package attest
import (
"io/ioutil"
"net/http"
"testing"
)
func Test_NewRecorder(t *testing.T) {
test := New(t)
rec, req := test.NewRecorder()
test.Equals("GET", req.Method)
test.Equals("/", req.URL.Path)
test.Equals("example.com", req.URL.Host)
test.Equals("http", req.URL.Scheme)
test.TypeIs("http.noBody", req.Body)
test.TypeIs("*httptest.ResponseRecorder", rec)
rec, req = test.NewRecorder("http://different-url.and/path")
test.Equals("GET", req.Method)
test.Equals("/path", req.URL.Path)
test.Equals("different-url.and", req.URL.Host)
test.Equals("http", req.URL.Scheme)
test.TypeIs("http.noBody", req.Body)
test.TypeIs("*httptest.ResponseRecorder", rec)
rec, req = test.NewRecorder(
"GET",
"http://a-url.and/path",
"A string to go in the body",
)
test.Equals("GET", req.Method)
test.Equals("/path", req.URL.Path)
test.Equals("a-url.and", req.URL.Host)
test.Equals("http", req.URL.Scheme)
readBack, err := ioutil.ReadAll(req.Body)
req.Body.Close()
test.Handle(err)
test.Equals("A string to go in the body", string(readBack))
test.TypeIs("*httptest.ResponseRecorder", rec)
rec, req = test.NewRecorder("/just/the/path")
test.Equals("GET", req.Method)
test.Equals("/just/the/path", req.URL.Path)
test.Equals("example.com", req.URL.Host)
test.Equals("http", req.URL.Scheme)
test.TypeIs("http.noBody", req.Body)
test.TypeIs("*httptest.ResponseRecorder", rec)
}
func Test_ResponseOK(t *testing.T) {
test := New(t)
rec, req := test.NewRecorder()
func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
}(rec, req)
res := rec.Result()
test.ResponseOK(res)
}