forked from writeas/go-writeas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection_test.go
63 lines (55 loc) · 1.23 KB
/
collection_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
package writeas
import (
"fmt"
"testing"
)
func TestGetCollection(t *testing.T) {
wac := NewClient()
res, err := wac.GetCollection("blog")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Collection: %+v", res)
if res.Title != "write.as" {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
}
func TestGetCollectionPosts(t *testing.T) {
wac := NewClient()
res, err := wac.GetCollectionPosts("blog")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
if len(*res) == 0 {
t.Errorf("No posts returned!")
}
}
}
func TestGetUserCollections(t *testing.T) {
wac := NewDevClient()
_, err := wac.LogIn("demo", "demo")
if err != nil {
t.Fatalf("Unable to log in: %v", err)
}
defer wac.LogOut()
res, err := wac.GetUserCollections()
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("User collections: %+v", res)
if len(*res) == 0 {
t.Errorf("No collections returned!")
}
}
}
func ExampleClient_GetCollection() {
c := NewClient()
coll, err := c.GetCollection("blog")
if err != nil {
fmt.Printf("%v", err)
return
}
fmt.Printf("%s", coll.Title)
// Output: write.as
}