-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleHTTP_test.go
59 lines (51 loc) · 1.01 KB
/
SimpleHTTP_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
package simple_http
import (
"os"
"testing"
)
func TestParameterRequest_Send(t *testing.T) {
pr, err := NewParameterRequest("GET", "https://pokeapi.co/api/v2/pokemon")
if err != nil {
panic(err)
}
pr.AddParameter("limit", "2")
// Send the request
response, err := pr.Send()
if err != nil {
panic(err)
}
t.Log(PrettyPrintMap(response))
}
func TestFormRequest_Send(t *testing.T) {
request, err := NewFormRequest("POST", "https://postman-echo.com/post")
if err != nil {
panic(err)
}
TestFilePath := "test_image.png"
//Add a file as a byte array
err = request.AddFileData("bytes", "fake.txt", []byte("SET BY BYTE ARRAY"))
if err != nil {
panic(err)
}
// Add a file by path
f, err := os.Open(TestFilePath)
if err != nil {
panic(err)
}
defer func() {
err = f.Close()
if err != nil {
panic(err)
}
}()
_, err = request.AddFile("file", f)
if err != nil {
panic(err)
}
// Send the request
response, err := request.Send()
if err != nil {
panic(err)
}
t.Log(PrettyPrintMap(response))
}