17
17
package gitlab
18
18
19
19
import (
20
- "fmt"
21
20
"net/http"
22
21
"reflect"
23
22
"testing"
@@ -27,7 +26,7 @@ func TestGetDraftNote(t *testing.T) {
27
26
mux , client := setup (t )
28
27
mux .HandleFunc ("/api/v4/projects/1/merge_requests/4329/draft_notes/3" , func (w http.ResponseWriter , r * http.Request ) {
29
28
testMethod (t , r , http .MethodGet )
30
- fmt . Fprint ( w , `{"id": 37349978 , "author_id": 10271899, "merge_request_id": 291473309, "resolve_discussion": false, "discussion_id": null, "note": "Some draft note", "commit_id": null, "position": null, "line_code": null}` )
29
+ mustWriteHTTPResponse ( t , w , "testdata/get_draft_note.json" )
31
30
})
32
31
33
32
note , _ , err := client .DraftNotes .GetDraftNote ("1" , 4329 , 3 )
@@ -56,53 +55,7 @@ func TestListDraftNotes(t *testing.T) {
56
55
mux , client := setup (t )
57
56
mux .HandleFunc ("/api/v4/projects/1/merge_requests/4329/draft_notes" , func (w http.ResponseWriter , r * http.Request ) {
58
57
testMethod (t , r , http .MethodGet )
59
- fmt .Fprintf (w , `[
60
- {
61
- "id": 37349978,
62
- "author_id": 10271899,
63
- "merge_request_id": 291473309,
64
- "resolve_discussion": false,
65
- "discussion_id": null,
66
- "note": "Some draft note",
67
- "commit_id": null,
68
- "position": null,
69
- "line_code": null
70
- },
71
- {
72
- "id": 37349979,
73
- "author_id": 10271899,
74
- "merge_request_id": 291473309,
75
- "resolve_discussion": false,
76
- "discussion_id": null,
77
- "note": "Some draft note 2",
78
- "commit_id": null,
79
- "line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
80
- "position": {
81
- "base_sha": "64581c4ee41beb44d943d7801f82d9038e25e453",
82
- "start_sha": "87bffbff93bf334889780f54ae1922355661f867",
83
- "head_sha": "2c972dbf9094c380f5f00dcd8112d2c69b24c859",
84
- "old_path": "src/some-dir/some-file.js",
85
- "new_path": "src/some-dir/some-file.js",
86
- "position_type": "text",
87
- "old_line": null,
88
- "new_line": 9,
89
- "line_range": {
90
- "start": {
91
- "line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
92
- "type": "new",
93
- "old_line": null,
94
- "new_line": 9
95
- },
96
- "end": {
97
- "line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
98
- "type": "new",
99
- "old_line": null,
100
- "new_line": 9
101
- }
102
- }
103
- }
104
- }
105
- ]` )
58
+ mustWriteHTTPResponse (t , w , "testdata/list_draft_notes.json" )
106
59
})
107
60
108
61
notes , _ , err := client .DraftNotes .ListDraftNotes ("1" , 4329 , nil )
@@ -164,7 +117,7 @@ func TestCreateDraftNote(t *testing.T) {
164
117
mux , client := setup (t )
165
118
mux .HandleFunc ("/api/v4/projects/1/merge_requests/4329/draft_notes" , func (w http.ResponseWriter , r * http.Request ) {
166
119
testMethod (t , r , http .MethodPost )
167
- fmt . Fprint ( w , `{"id": 37349980 , "author_id": 10271899, "merge_request_id": 291473309, "resolve_discussion": false, "discussion_id": null, "note": "Some new draft note", "commit_id": null, "position": null, "line_code": null}` )
120
+ mustWriteHTTPResponse ( t , w , "testdata/create_draft_note.json" )
168
121
})
169
122
170
123
note , _ , err := client .DraftNotes .CreateDraftNote ("1" , 4329 , & CreateDraftNoteOptions {
@@ -197,7 +150,7 @@ func TestUpdateDraftNote(t *testing.T) {
197
150
mux , client := setup (t )
198
151
mux .HandleFunc ("/api/v4/projects/1/merge_requests/4329/draft_notes/3" , func (w http.ResponseWriter , r * http.Request ) {
199
152
testMethod (t , r , http .MethodPut )
200
- fmt . Fprint ( w , `{"id": 37349980 , "author_id": 10271899, "merge_request_id": 291473309, "resolve_discussion": false, "discussion_id": null, "note": "Some changed draft note", "commit_id": null, "position": null, "line_code": null}` )
153
+ mustWriteHTTPResponse ( t , w , "testdata/update_draft_note.json" )
201
154
})
202
155
203
156
note , _ , err := client .DraftNotes .UpdateDraftNote ("1" , 4329 , 3 , & UpdateDraftNoteOptions {
@@ -224,3 +177,15 @@ func TestUpdateDraftNote(t *testing.T) {
224
177
t .Errorf ("DraftNotes.UpdateDraftNote want %#v, got %#v" , note , want )
225
178
}
226
179
}
180
+
181
+ func TestDeleteDraftNote (t * testing.T ) {
182
+ mux , client := setup (t )
183
+ mux .HandleFunc ("/api/v4/projects/1/merge_requests/4329/draft_notes/3" , func (w http.ResponseWriter , r * http.Request ) {
184
+ testMethod (t , r , http .MethodDelete )
185
+ })
186
+
187
+ _ , err := client .DraftNotes .DeleteDraftNote ("1" , 4329 , 3 )
188
+ if err != nil {
189
+ t .Errorf ("DraftNotes.DeleteDraftNote returned error: %v" , err )
190
+ }
191
+ }
0 commit comments