-
Notifications
You must be signed in to change notification settings - Fork 50
/
authorizer_test.go
60 lines (54 loc) · 1.26 KB
/
authorizer_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
package gofast_test
import (
"io/ioutil"
"net/http"
"strings"
"testing"
"github.com/yookoala/gofast"
)
func TestNewAuthRequest(t *testing.T) {
// generate new request to clone from
content := "hello world 1234"
raw, err := http.NewRequest(
"POST",
"http://foobar.com/hello",
strings.NewReader(content),
)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
// clone the request into 2
r, req, err := gofast.NewAuthRequest(raw)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
// the original body is read and became "empty"
body, err := ioutil.ReadAll(raw.Body)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
if want, have := "", string(body); want != have {
t.Errorf("expected: %#v, got %#v", want, have)
}
// examine the r.Body reader
body, err = ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
if want, have := content, string(body); want != have {
t.Errorf("expected: %#v, got %#v", want, have)
}
// examine the req.Stdin reader
stdin, err := ioutil.ReadAll(req.Stdin)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
if want, have := content, string(stdin); want != have {
t.Errorf("expected: %#v, got %#v", want, have)
}
}