-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhellosign_suite_test.go
90 lines (80 loc) · 1.65 KB
/
hellosign_suite_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package hellosign_test
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net/http"
"net/http/httputil"
"strings"
"testing"
"unicode"
"github.com/jarcoal/httpmock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func DumpRequest(req *http.Request) {
d, err := httputil.DumpRequest(req, true)
if err == nil {
fmt.Println(string(d))
}
}
func ReplaceWhitespace(str string) string {
return strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}, str)
}
func StringsNonWhitespaceEqual(a, b string) bool {
return ReplaceWhitespace(a) == ReplaceWhitespace(b)
}
var _ = BeforeSuite(func() {
// block all HTTP requests
httpmock.Activate()
})
var _ = BeforeEach(func() {
// remove any mocks
httpmock.Reset()
})
var _ = AfterSuite(func() {
httpmock.DeactivateAndReset()
})
func TestHellosign(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Hellosign Suite")
}
func parseRequestParameters(req *http.Request) (map[string]string, error) {
var params map[string]string
mediaType, params, err := mime.ParseMediaType(req.Header.Get("Content-Type"))
if err != nil {
return params, err
}
if !strings.HasPrefix(mediaType, "multipart/") {
return params, fmt.Errorf("invalid media type")
}
body, err := ioutil.ReadAll(req.Body)
if err != nil {
return params, err
}
mr := multipart.NewReader(bytes.NewReader(body), params["boundary"])
for {
p, err := mr.NextPart()
if err == io.EOF {
break
}
if err != nil {
return params, err
}
key := p.FormName()
b, err := ioutil.ReadAll(p)
if err != nil {
return params, err
}
params[key] = string(b)
}
return params, nil
}