-
Notifications
You must be signed in to change notification settings - Fork 5
/
wikies_test.go
183 lines (142 loc) · 3.8 KB
/
wikies_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package redmine
import (
"os"
"strconv"
"testing"
)
var (
testWikiTitle = "TestTitle"
testWikiText = "TestText"
testWikiComment = "TestComment"
testWikiTextUpdated = "TestTextUpdated"
testWikiCommentUpdated = "TestCommentUpdated"
)
func TestWikiesCRUD(t *testing.T) {
var r Context
// Get env variables
testIssueTrackerID, err := strconv.ParseInt(os.Getenv("REDMINE_TRACKER_ID"), 10, 64)
if err != nil {
t.Fatal("Wiki test error: env variable `REDMINE_TRACKER_ID` is incorrect")
}
if testIssueTrackerID == 0 {
t.Fatal("Wiki test error: env variable `REDMINE_TRACKER_ID` does not set")
}
// Init Redmine context
initTest(&r, t)
// Preparing auxiliary data
pCreated := testProjectCreate(t, r, []int64{testIssueTrackerID})
defer testProjectDetele(t, r, pCreated.Identifier)
// Add and delete
testWikiCreate(t, r, pCreated.Identifier, testWikiTitle)
defer testWikiDetele(t, r, pCreated.Identifier, testWikiTitle)
// Get all
testwikiAllGet(t, r, pCreated.Identifier)
// Single get
testWikiSingleGet(t, r, pCreated.Identifier, testWikiTitle)
// Update
testWikiUpdate(t, r, pCreated.Identifier, testWikiTitle)
// Single version get
testWikiSingleVersionGet(t, r, pCreated.Identifier, testWikiTitle, 2)
}
func testWikiCreate(t *testing.T, r Context, projectID, wikiTitle string) WikiObject {
u, s, err := r.AttachmentUpload(testAttachmentFile)
if err != nil {
t.Fatal("Wiki create error:", err, s)
}
w, s, err := r.WikiCreate(
projectID,
wikiTitle,
WikiCreate{
WikiPage: WikiCreateObject{
Text: testWikiText,
Comments: &testWikiComment,
Uploads: &[]AttachmentUploadObject{u},
},
},
)
if err != nil {
t.Fatal("Wiki create error:", err, s)
}
if w.Title != wikiTitle {
t.Fatal("Wiki get error: incorrect title")
}
t.Logf("Wiki create: success")
return w
}
func testwikiAllGet(t *testing.T, r Context, projectID string) {
w, s, err := r.WikiAllGet(projectID)
if err != nil {
t.Fatal("Wikies all get error:", err, s)
}
if len(w) == 0 {
t.Fatal("Wikies all get error: can't find any wikies satisfies specified filters")
}
t.Logf("Wikies all get: success")
}
func testWikiSingleGet(t *testing.T, r Context, projectID, wikiTitle string) {
w, s, err := r.WikiSingleGet(
projectID,
wikiTitle,
WikiSingleGetRequest{
Includes: []WikiInclude{
WikiIncludeAttachments,
},
})
if err != nil {
t.Fatal("Wiki get error:", err, s)
}
if w.Title != wikiTitle {
t.Fatal("Wiki get error: incorrect title")
}
if len(*w.Attachments) == 0 {
t.Fatal("Wiki get error: incorrect attachments count")
}
if (*w.Attachments)[0].FileName != testAttachmentFile {
t.Fatal("Wiki get error: incorrect attachments name")
}
t.Logf("Wiki get: success")
}
func testWikiSingleVersionGet(t *testing.T, r Context, projectID, wikiTitle string, version int64) {
w, s, err := r.WikiSingleVersionGet(
projectID,
wikiTitle,
version,
WikiSingleGetRequest{
Includes: []WikiInclude{
WikiIncludeAttachments,
},
})
if err != nil {
t.Fatal("Wiki version get error:", err, s)
}
if w.Title != wikiTitle {
t.Fatal("Wiki version get error: incorrect title")
}
if w.Text != testWikiTextUpdated {
t.Fatal("Wiki version get error: incorrect text")
}
t.Logf("Wiki version get: success")
}
func testWikiUpdate(t *testing.T, r Context, projectID, wikiTitle string) {
s, err := r.WikiUpdate(
projectID,
wikiTitle,
WikiUpdate{
WikiPage: WikiUpdateObject{
Text: testWikiTextUpdated,
Comments: &testWikiCommentUpdated,
},
},
)
if err != nil {
t.Fatal("Wiki update error:", err, s)
}
t.Logf("Wiki update: success")
}
func testWikiDetele(t *testing.T, r Context, projectID, wikiTitle string) {
_, err := r.WikiDelete(projectID, wikiTitle)
if err != nil {
t.Fatal("Wiki delete error:", err)
}
t.Logf("Wiki delete: success")
}