forked from Virtomize/confluence-go-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent_test.go
140 lines (109 loc) · 3.27 KB
/
content_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package goconfluence
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetContentEndpoints(t *testing.T) {
a, err := NewAPI("https://test.test", "username", "token")
assert.Nil(t, err)
url, err := a.getContentIDEndpoint("test")
assert.Nil(t, err)
assert.Equal(t, "/content/test", url.Path)
url, err = a.getContentEndpoint()
assert.Nil(t, err)
assert.Equal(t, "/content/", url.Path)
url, err = a.getContentChildEndpoint("test", "child")
assert.Nil(t, err)
assert.Equal(t, "/content/test/child/child", url.Path)
url, err = a.getContentGenericEndpoint("test", "child")
assert.Nil(t, err)
assert.Equal(t, "/content/test/child", url.Path)
}
func TestContentGetter(t *testing.T) {
server := confluenceRestAPIStub()
defer server.Close()
api, err := NewAPI(server.URL+"/wiki/rest/api", "userame", "token")
assert.Nil(t, err)
c, err := api.GetContentByID("42", ContentQuery{})
assert.Nil(t, err)
assert.Equal(t, &Content{}, c)
s, err := api.GetContent(ContentQuery{})
assert.Nil(t, err)
assert.Equal(t, &Search{}, s)
s, err = api.GetChildPages("42")
assert.Nil(t, err)
assert.Equal(t, &Search{}, s)
s, err = api.GetComments("42")
assert.Nil(t, err)
assert.Equal(t, &Search{}, s)
s, err = api.GetAttachments("42")
assert.Nil(t, err)
assert.Equal(t, &Search{}, s)
h, err := api.GetHistory("42")
assert.Nil(t, err)
assert.Equal(t, &History{}, h)
l, err := api.GetLabels("42")
assert.Nil(t, err)
assert.Equal(t, &Labels{}, l)
w, err := api.GetWatchers("42")
assert.Nil(t, err)
assert.Equal(t, &Watchers{}, w)
}
func TestAddLabels(t *testing.T) {
server := confluenceRestAPIStub()
defer server.Close()
api, err := NewAPI(server.URL+"/wiki/rest/api", "userame", "token")
assert.Nil(t, err)
l, err := api.AddLabels("42", &[]Label{})
assert.Nil(t, err)
assert.Equal(t, &Labels{}, l)
}
func TestDeleteLabels(t *testing.T) {
server := confluenceRestAPIStub()
defer server.Close()
api, err := NewAPI(server.URL+"/wiki/rest/api", "userame", "token")
assert.Nil(t, err)
l, err := api.DeleteLabel("42", "test")
assert.Nil(t, err)
assert.Equal(t, &Labels{}, l)
}
func TestContent(t *testing.T) {
server := confluenceRestAPIStub()
defer server.Close()
api, err := NewAPI(server.URL+"/wiki/rest/api", "userame", "token")
assert.Nil(t, err)
c, err := api.CreateContent(&Content{})
assert.Nil(t, err)
assert.Equal(t, &Content{}, c)
c, err = api.UpdateContent(&Content{})
assert.Nil(t, err)
assert.Equal(t, &Content{}, c)
c, err = api.DelContent("42")
assert.Nil(t, err)
assert.Equal(t, &Content{}, c)
}
func TestAddContentQueryParams(t *testing.T) {
query := ContentQuery{
Expand: []string{"foo", "bar"},
Limit: 1,
OrderBy: "test",
PostingDay: "test",
SpaceKey: "test",
Start: 1,
Status: "test",
Title: "test",
Trigger: "test",
Type: "test",
}
p := addContentQueryParams(query)
assert.Equal(t, p.Get("expand"), "foo,bar")
assert.Equal(t, p.Get("limit"), "1")
assert.Equal(t, p.Get("orderby"), "test")
assert.Equal(t, p.Get("postingDay"), "test")
assert.Equal(t, p.Get("spaceKey"), "test")
assert.Equal(t, p.Get("start"), "1")
assert.Equal(t, p.Get("status"), "test")
assert.Equal(t, p.Get("title"), "test")
assert.Equal(t, p.Get("trigger"), "test")
assert.Equal(t, p.Get("type"), "test")
}