-
Notifications
You must be signed in to change notification settings - Fork 6
/
json_test.go
65 lines (56 loc) · 1.05 KB
/
json_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
package rq
import (
"fmt"
"testing"
)
var testJSON []byte
func TestJSONify(t *testing.T) {
r := Put("https://ddo.me?k=1")
r.Qs("k", "2", "3")
r.Qs("v", "4")
r.Qs("v", "5", "6")
r.Send("data", "data value 1", "data value 2")
r.Send("extra", "data value 3")
data, err := r.JSONify()
if err != nil {
t.Error()
return
}
if string(data) != `{"url":"https://ddo.me?k=1","method":"PUT","query":{"k":["2","3"],"v":["4","5","6"]},"form":{"data":["data value 1","data value 2"],"extra":["data value 3"]},"header":{}}` {
t.Error()
return
}
testJSON = data
}
func TestNewFromJSON(t *testing.T) {
r, err := NewFromJSON(testJSON)
if err != nil {
fmt.Println(err)
t.Error()
return
}
if r == nil {
t.Error()
return
}
if r.URL != "https://ddo.me?k=1" {
t.Error()
return
}
if len(r.Query) != 2 || len(r.Form) != 2 || len(r.Header) != 0 {
t.Error()
return
}
}
func TestNewFromJSONEmpty(t *testing.T) {
r, err := NewFromJSON([]byte("{}"))
if err != nil {
fmt.Println(err)
t.Error()
return
}
if r != nil {
t.Error()
return
}
}