This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
68 lines (58 loc) · 1.48 KB
/
request_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
61
62
63
64
65
66
67
68
package geyser_test
import (
"context"
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/13k/geyser/v2"
"github.com/13k/geyser/v2/schema"
)
func TestRequest_GettersSetters(t *testing.T) {
assert := assert.New(t)
si := &schema.Interface{}
sm := &schema.Method{}
ctx := context.Background()
form := url.Values{"form": {"data"}}
body := map[string]interface{}{"field": "value"}
result := map[string]interface{}{}
req := geyser.NewRequest(si, sm).
SetContext(ctx).
SetHeader("X-Keep", "keep").
SetHeader("X-Override", "initial").
SetHeaders(http.Header{
"X-Append": {"append"},
"X-Override": {"overridden"},
}).
SetQueryParam("keep", "keep").
SetQueryParam("override", "initial").
SetQueryParams(url.Values{
"append": {"append"},
"override": {"overridden"},
}).
SetAPIKey("abc123xyz").
SetLanguage("de").
SetForm(form).
SetBody(body).
SetResult(result)
assert.Same(si, req.Interface)
assert.Same(sm, req.Method)
assert.Same(ctx, req.Context)
assert.Exactly(form, req.Form)
assert.Exactly(body, req.Body)
assert.Exactly(result, req.Result)
expectedHeader := http.Header{
"X-Keep": {"keep"},
"X-Override": {"overridden"},
"X-Append": {"append"},
}
expectedQuery := url.Values{
"keep": {"keep"},
"override": {"overridden"},
"append": {"append"},
"key": {"abc123xyz"},
"language": {"de"},
}
assert.Exactly(expectedHeader, req.Header)
assert.Exactly(expectedQuery, req.Query)
}