-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhelper_test.go
40 lines (34 loc) · 924 Bytes
/
helper_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
package nylas
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/google/go-cmp/cmp"
)
func withTestServer(ts *httptest.Server) Option {
return WithBaseURL(ts.URL)
}
func assertBasicAuth(t *testing.T, r *http.Request, user, pass string) {
t.Helper()
gotUser, gotPass, ok := r.BasicAuth()
if !ok {
t.Errorf("basic auth not provided")
}
if user != gotUser || pass != gotPass {
t.Errorf("basic auth: got %q:%q; want %q;%q", gotUser, gotPass, user, pass)
}
}
func assertQueryParams(t *testing.T, r *http.Request, want url.Values) {
t.Helper()
got := r.URL.Query()
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("query params: (-got +want):\n%s", diff)
}
}
func assertMethodPath(t *testing.T, r *http.Request, method, path string) {
t.Helper()
if r.Method != method || r.URL.Path != path {
t.Errorf("req: got %v %v; want %v %v", r.Method, r.URL.Path, method, path)
}
}