forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epics_test.go
143 lines (116 loc) · 3.63 KB
/
epics_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
package gitlab
import (
"fmt"
"log"
"net/http"
"reflect"
"testing"
)
func TestGetEpic(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/7/epics/8", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":8, "title": "Incredible idea", "description": "This is a test epic", "author" : {"id" : 26, "name": "jramsay"}}`)
})
epic, _, err := client.Epics.GetEpic("7", 8)
if err != nil {
log.Fatal(err)
}
want := &Epic{
ID: 8,
Title: "Incredible idea",
Description: "This is a test epic",
Author: &EpicAuthor{ID: 26, Name: "jramsay"},
}
if !reflect.DeepEqual(want, epic) {
t.Errorf("Epics.GetEpic returned %+v, want %+v", epic, want)
}
}
func TestDeleteEpic(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/7/epics/8", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.Epics.DeleteEpic("7", 8)
if err != nil {
log.Fatal(err)
}
}
func TestListGroupEpics(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/7/epics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testURL(t, r, "/api/v4/groups/7/epics?author_id=26&state=opened")
fmt.Fprint(w, `[{"id":8, "title": "Incredible idea", "description": "This is a test epic", "author" : {"id" : 26, "name": "jramsay"}}]`)
})
listGroupEpics := &ListGroupEpicsOptions{
AuthorID: Int(26),
State: String("opened"),
}
epics, _, err := client.Epics.ListGroupEpics("7", listGroupEpics)
if err != nil {
log.Fatal(err)
}
want := []*Epic{{
ID: 8,
Title: "Incredible idea",
Description: "This is a test epic",
Author: &EpicAuthor{ID: 26, Name: "jramsay"},
}}
if !reflect.DeepEqual(want, epics) {
t.Errorf("Epics.ListGroupEpics returned %+v, want %+v", epics, want)
}
}
func TestCreateEpic(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/7/epics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":8, "title": "Incredible idea", "description": "This is a test epic", "author" : {"id" : 26, "name": "jramsay"}}`)
})
createEpicOptions := &CreateEpicOptions{
Title: String("Incredible idea"),
Description: String("This is a test epic"),
}
epic, _, err := client.Epics.CreateEpic("7", createEpicOptions)
if err != nil {
log.Fatal(err)
}
want := &Epic{
ID: 8,
Title: "Incredible idea",
Description: "This is a test epic",
Author: &EpicAuthor{ID: 26, Name: "jramsay"},
}
if !reflect.DeepEqual(want, epic) {
t.Errorf("Epics.CreateEpic returned %+v, want %+v", epic, want)
}
}
func TestUpdateEpic(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/7/epics/8", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprint(w, `{"id":8, "title": "Incredible idea", "description": "This is a test epic", "author" : {"id" : 26, "name": "jramsay"}}`)
})
updateEpicOptions := &UpdateEpicOptions{
Title: String("Incredible idea"),
Description: String("This is a test epic"),
}
epic, _, err := client.Epics.UpdateEpic("7", 8, updateEpicOptions)
if err != nil {
log.Fatal(err)
}
want := &Epic{
ID: 8,
Title: "Incredible idea",
Description: "This is a test epic",
Author: &EpicAuthor{ID: 26, Name: "jramsay"},
}
if !reflect.DeepEqual(want, epic) {
t.Errorf("Epics.UpdateEpic returned %+v, want %+v", epic, want)
}
}