This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgowrex_test.go
75 lines (66 loc) · 1.8 KB
/
gowrex_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
package gowrex
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestSpec(t *testing.T) {
Convey("JSON", t, func() {
// JSONReceive - json response
type JSONReceive struct {
ID int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
UserID int64 `json:"userId"`
}
// JSONSend - json post
type JSONSend struct {
ID int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
UserID int64 `json:"userId"`
}
Convey("JSON POST", func() {
timeout := 10 * time.Second
jsonData := &JSONSend{
ID: 12,
Title: "fancy book",
Body: "this is a fancy book",
UserID: 12,
}
req, _ := Request{
URI: "http://jsonplaceholder.typicode.com/posts",
Timeout: timeout}.PostJSON(jsonData)
res, _ := req.Do()
resp := &JSONReceive{}
res.JSON(resp)
So(resp.Body, ShouldEqual, "this is a fancy book")
})
Convey("JSON PUT", func() {
timeout := 10 * time.Second
jsonData := &JSONSend{
ID: 1,
Title: "fancy book",
Body: "this is a fancy book",
UserID: 1,
}
req, _ := Request{
URI: "http://jsonplaceholder.typicode.com/posts/1",
Timeout: timeout}.PutJSON(jsonData)
res, _ := req.Do()
resp := &JSONReceive{}
res.JSON(resp)
So(resp.Body, ShouldEqual, "this is a fancy book")
})
Convey("JSON GET", func() {
timeout := 10 * time.Second
req, _ := Request{
URI: "http://jsonplaceholder.typicode.com/posts/1",
Timeout: timeout}.GetJSON()
res, _ := req.Do()
resp := &JSONReceive{}
res.JSON(resp)
So(resp.Body, ShouldEqual, "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto")
})
})
}