forked from sogko/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 2
/
taxonomies_test.go
63 lines (56 loc) · 1.43 KB
/
taxonomies_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 wordpress_test
import (
"net/http"
"testing"
)
func TestTaxonomiesList(t *testing.T) {
wp := initTestClient()
taxonomies, resp, body, err := wp.Taxonomies().List(nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if body == nil {
t.Errorf("Should not return nil body")
}
if taxonomies == nil {
t.Errorf("Should not return nil taxonomies")
}
if len(taxonomies) != 2 {
t.Errorf("Should return two taxonomies")
}
}
func TestTaxonomiesGet_TaxonomyExists(t *testing.T) {
wp := initTestClient()
taxonomy, resp, body, err := wp.Taxonomies().Get("post_tag", nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if body == nil {
t.Errorf("Should not return nil body")
}
if taxonomy == nil {
t.Errorf("Should not return nil taxonomies")
}
}
func TestTaxonomiesGet_TaxonomyDoesNotExists(t *testing.T) {
wp := initTestClient()
taxonomy, resp, body, err := wp.Taxonomies().Get("RANDOM", nil)
if err == nil {
t.Errorf("Should return error")
}
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Expected 404 Not Found, got %v", resp.Status)
}
if body == nil {
t.Errorf("Should not return nil body")
}
if taxonomy == nil {
t.Errorf("Should not return nil taxonomies")
}
}