-
Notifications
You must be signed in to change notification settings - Fork 12
/
http_client_test.go
47 lines (38 loc) · 1.01 KB
/
http_client_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
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestWithUserAgent(t *testing.T) {
client := &http.Client{
Transport: &customTransport{
RoundTripper: http.DefaultTransport,
},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.EqualValues(t, r.UserAgent(), "rainbow/"+buildVersion())
w.WriteHeader(http.StatusOK)
}))
defer ts.Close()
_, err := client.Get(ts.URL)
assert.Nil(t, err)
}
func TestWithAuthorizationBearerToken(t *testing.T) {
secret := "secret"
client := &http.Client{
Transport: &customTransport{
AuthorizationBearerToken: secret,
RoundTripper: http.DefaultTransport,
},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
assert.EqualValues(t, auth, "Bearer "+secret)
w.WriteHeader(http.StatusOK)
}))
defer ts.Close()
_, err := client.Get(ts.URL)
assert.Nil(t, err)
}