-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbind_test.go
61 lines (55 loc) · 1.35 KB
/
bind_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
package twiml
import (
"bytes"
"net/http"
"net/url"
"strconv"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func makeRequest(v map[string]string) *http.Request {
apiURL := "https://test.com"
data := url.Values{}
for key, value := range v {
data.Set(key, value)
}
d := data.Encode()
r, _ := http.NewRequest("POST", apiURL, bytes.NewBufferString(d))
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("Content-Length", strconv.Itoa(len(d)))
return r
}
var _ = Describe("Callback binding", func() {
It("can bind a callback request", func() {
values := map[string]string{
"CallSid": "testsid",
"From": "+19999999999",
"To": "+19991111111",
}
exp := VoiceRequest{
CallSid: "testsid",
From: "+19999999999",
To: "+19991111111",
}
r := makeRequest(values)
var vr VoiceRequest
err := Bind(&vr, r)
Expect(err).ToNot(HaveOccurred())
Expect(vr).To(Equal(exp))
})
It("can bind requests for non-string types", func() {
values := map[string]string{
"RecordingUrl": "https://test.api",
"RecordingDuration": "10",
}
exp := RecordActionRequest{
RecordingURL: "https://test.api",
RecordingDuration: 10,
}
r := makeRequest(values)
var vr RecordActionRequest
err := Bind(&vr, r)
Expect(err).ToNot(HaveOccurred())
Expect(vr).To(Equal(exp))
})
})