forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_test.go
44 lines (35 loc) · 972 Bytes
/
rest_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
//go:build !integration
// +build !integration
package disgord
import (
"context"
"net/http"
"testing"
"github.com/andersfylling/disgord/internal/httd"
)
func verifyQueryString(t *testing.T, params URLQueryStringer, wants string) {
got := params.URLQueryString()
if got != wants {
t.Errorf("incorrect query param string. Got '%s', wants '%s'", got, wants)
}
}
// reqMocker for testing rest endpoint configurations with having to test the request logic in httd as well
type reqMocker struct {
err error
body []byte
resp *http.Response
req *httd.Request
}
func (gm *reqMocker) Do(ctx context.Context, req *httd.Request) (*http.Response, []byte, error) {
gm.req = req
gm.req.Ctx = ctx
return gm.resp, gm.body, gm.err
}
var _ httd.Requester = (*reqMocker)(nil)
func TestParamHolder_URLQueryString(t *testing.T) {
params := urlQuery{}
params["a"] = 45
verifyQueryString(t, params, "?a=45")
params = urlQuery{}
verifyQueryString(t, params, "")
}