-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
51 lines (42 loc) · 993 Bytes
/
utils_test.go
File metadata and controls
51 lines (42 loc) · 993 Bytes
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
package main
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
)
// Helper methods and structs for integration testing
// struct that contains only uint ID
// it will be returned from:
// * POST /api/urls
// * PATCH /api/urls/{ID}
type IDObject struct {
ID uint `json:"id"`
}
// Used in integration tests
//
// * POST /api/urls
// * PATCH /api/urls/{ID}
// * DELETE /api/urls/{ID}
func requestID(method, url string, body io.Reader) (result []byte, code int, err error) {
req, err := http.NewRequest(method, url, body)
if err != nil {
return
}
rsp, err := (&http.Client{}).Do(req)
if err != nil {
return
}
defer rsp.Body.Close()
code = rsp.StatusCode
result, err = ioutil.ReadAll(rsp.Body)
return
}
// Prepares 5kb+ payload that is well formed json as well
func prepareBigPayload() ([]byte, error) {
payload := make([]string, 0)
for len(payload) < 128 {
payload = append(payload, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
}
return json.Marshal(payload)
}