forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epics_test.go
159 lines (131 loc) · 4.26 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// Copyright 2021, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
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, http.MethodGet)
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, http.MethodDelete)
})
_, 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, http.MethodGet)
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, http.MethodPost)
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, http.MethodPut)
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)
}
}