forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_wikis_test.go
119 lines (99 loc) · 3.79 KB
/
group_wikis_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
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListGroupWikis(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/wikis",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `[{"content":"content here","format":"markdown","slug":"deploy","title":"deploy title"}]`)
})
groupwikis, _, err := client.GroupWikis.ListGroupWikis(1, &ListGroupWikisOptions{})
if err != nil {
t.Errorf("GroupWikis.ListGroupWikis returned error: %v", err)
}
want := []*GroupWiki{{Content: "content here", Format: WikiFormatMarkdown, Slug: "deploy", Title: "deploy title"}}
if !reflect.DeepEqual(want, groupwikis) {
t.Errorf("GroupWikis.ListGroupWikis returned %+v, want %+v", groupwikis, want)
}
}
func TestGetGroupWikiPage(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/wikis/deploy",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"content":"content here","format":"asciidoc","slug":"deploy","title":"deploy title"}`)
})
groupwiki, _, err := client.GroupWikis.GetGroupWikiPage(1, "deploy")
if err != nil {
t.Errorf("GroupWikis.GetGroupWikiPage returned error: %v", err)
}
want := &GroupWiki{Content: "content here", Format: WikiFormatASCIIDoc, Slug: "deploy", Title: "deploy title"}
if !reflect.DeepEqual(want, groupwiki) {
t.Errorf("GroupWikis.GetGroupWikiPage returned %+v, want %+v", groupwiki, want)
}
}
func TestCreateGroupWikiPage(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/wikis",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"content":"content here","format":"rdoc","slug":"deploy","title":"deploy title"}`)
})
groupwiki, _, err := client.GroupWikis.CreateGroupWikiPage(1, &CreateGroupWikiPageOptions{
Content: String("content here"),
Title: String("deploy title"),
Format: WikiFormat(WikiFormatRDoc),
})
if err != nil {
t.Errorf("GroupWikis.CreateGroupWikiPage returned error: %v", err)
}
want := &GroupWiki{Content: "content here", Format: WikiFormatRDoc, Slug: "deploy", Title: "deploy title"}
if !reflect.DeepEqual(want, groupwiki) {
t.Errorf("GroupWikis.CreateGroupWikiPage returned %+v, want %+v", groupwiki, want)
}
}
func TestEditGroupWikiPage(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/wikis/deploy",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"content":"content here","format":"asciidoc","slug":"deploy","title":"deploy title"}`)
})
groupwiki, _, err := client.GroupWikis.EditGroupWikiPage(1, "deploy", &EditGroupWikiPageOptions{
Content: String("content here"),
Title: String("deploy title"),
Format: WikiFormat(WikiFormatRDoc),
})
if err != nil {
t.Errorf("GroupWikis.EditGroupWikiPage returned error: %v", err)
}
want := &GroupWiki{Content: "content here", Format: WikiFormatASCIIDoc, Slug: "deploy", Title: "deploy title"}
if !reflect.DeepEqual(want, groupwiki) {
t.Errorf("GroupWikis.EditGroupWikiPage returned %+v, want %+v", groupwiki, want)
}
}
func TestDeleteGroupWikiPage(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/wikis/deploy",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
w.WriteHeader(204)
})
r, err := client.GroupWikis.DeleteGroupWikiPage(1, "deploy")
if err != nil {
t.Errorf("GroupWikis.DeleteGroupWikiPage returned error: %v", err)
}
if r.StatusCode != 204 {
t.Errorf("GroupWikis.DeleteGroupWikiPage returned wrong status code %d != 204", r.StatusCode)
}
}