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
|
package main
import (
"fmt"
"testing"
)
const URL_GET = "https://jsonplaceholder.typicode.com/todos/:id"
const URL_POST = "https://jsonplaceholder.typicode.com/posts"
type TestStruct struct {
UserId int `json:"userId"`
Id int `json:"id"`
Title string `json:"title"`
Completed bool `json:"completed"`
}
func TestGET(t *testing.T) {
url := FormatUrl(
URL_GET,
map[string]string{
"id": "1",
},
map[string]string{},
)
codec := NewJsonCodec[TestStruct]()
res, status, err := HttpGet(
url,
map[string]string{},
codec,
)
if err != nil {
t.Errorf("%s", err.Error())
t.FailNow()
}
fmt.Println("res:", res, ", status:", status)
}
func TestPOST(t *testing.T) {
res, status, err := HttpPost(
URL_POST,
map[string]string{
"id": "1",
},
map[string]string{},
&TestStruct{
UserId: 1,
Id: 1,
Title: "TEST",
Completed: false,
},
NewJsonCodec[TestStruct](),
NewJsonCodec[TestStruct](),
)
if err != nil {
t.Errorf("%s", err.Error())
t.FailNow()
}
fmt.Println("res:", res, ", status:", status)
}
|