-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebber_test.go
More file actions
65 lines (49 loc) · 1.2 KB
/
webber_test.go
File metadata and controls
65 lines (49 loc) · 1.2 KB
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 webber
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type TestPost struct {
UserID int `json:"userId"`
ID int `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
}
func TestCanGet(t *testing.T) {
uri := "https://jsonplaceholder.typicode.com/posts"
params := make(map[string]string)
params["Id"] = "2"
wbr := &Request{URI: uri}
res, err := wbr.Get(params)
require.Nil(t, err)
err = res.Read(false)
require.Nil(t, err)
var tpp []TestPost
err = json.Unmarshal(res.Data, &tpp)
require.Nil(t, err)
require.NotEmpty(t, tpp)
for _, tp := range tpp {
assert.True(t, tp.ID > 0)
assert.True(t, tp.UserID > 0)
assert.NotEmpty(t, tp.Title)
assert.NotEmpty(t, tp.Body)
}
}
func TestCanPost(t *testing.T) {
uri := "https://jsonplaceholder.typicode.com/posts"
tp := TestPost{
Body: "Hello body",
Title: "Hello title",
UserID: 1,
}
wbr := &Request{URI: uri, ContentType: ContentTypeApplicationJSON}
res, err := wbr.Post(tp)
require.Nil(t, err)
err = res.Read(false)
require.Nil(t, err)
err = json.Unmarshal(res.Data, &tp)
require.Nil(t, err)
assert.True(t, tp.UserID > 0)
}