Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 394e800

Browse files
Moved test data, wrote more tests
1 parent 15ef837 commit 394e800

5 files changed

+96
-51
lines changed

draft_notes_test.go

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package gitlab
1818

1919
import (
20-
"fmt"
2120
"net/http"
2221
"reflect"
2322
"testing"
@@ -27,7 +26,7 @@ func TestGetDraftNote(t *testing.T) {
2726
mux, client := setup(t)
2827
mux.HandleFunc("/api/v4/projects/1/merge_requests/4329/draft_notes/3", func(w http.ResponseWriter, r *http.Request) {
2928
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")
3130
})
3231

3332
note, _, err := client.DraftNotes.GetDraftNote("1", 4329, 3)
@@ -56,53 +55,7 @@ func TestListDraftNotes(t *testing.T) {
5655
mux, client := setup(t)
5756
mux.HandleFunc("/api/v4/projects/1/merge_requests/4329/draft_notes", func(w http.ResponseWriter, r *http.Request) {
5857
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")
10659
})
10760

10861
notes, _, err := client.DraftNotes.ListDraftNotes("1", 4329, nil)
@@ -164,7 +117,7 @@ func TestCreateDraftNote(t *testing.T) {
164117
mux, client := setup(t)
165118
mux.HandleFunc("/api/v4/projects/1/merge_requests/4329/draft_notes", func(w http.ResponseWriter, r *http.Request) {
166119
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")
168121
})
169122

170123
note, _, err := client.DraftNotes.CreateDraftNote("1", 4329, &CreateDraftNoteOptions{
@@ -197,7 +150,7 @@ func TestUpdateDraftNote(t *testing.T) {
197150
mux, client := setup(t)
198151
mux.HandleFunc("/api/v4/projects/1/merge_requests/4329/draft_notes/3", func(w http.ResponseWriter, r *http.Request) {
199152
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")
201154
})
202155

203156
note, _, err := client.DraftNotes.UpdateDraftNote("1", 4329, 3, &UpdateDraftNoteOptions{
@@ -224,3 +177,15 @@ func TestUpdateDraftNote(t *testing.T) {
224177
t.Errorf("DraftNotes.UpdateDraftNote want %#v, got %#v", note, want)
225178
}
226179
}
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+
}

testdata/create_draft_note.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": 37349980,
3+
"author_id": 10271899,
4+
"merge_request_id": 291473309,
5+
"resolve_discussion": false,
6+
"discussion_id": null,
7+
"note": "Some new draft note",
8+
"commit_id": null,
9+
"position": null,
10+
"line_code": null
11+
}

testdata/get_draft_note.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": 37349978,
3+
"author_id": 10271899,
4+
"merge_request_id": 291473309,
5+
"resolve_discussion": false,
6+
"discussion_id": null,
7+
"note": "Some draft note",
8+
"commit_id": null,
9+
"position": null,
10+
"line_code": null
11+
}

testdata/list_draft_notes.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
{
3+
"id": 37349978,
4+
"author_id": 10271899,
5+
"merge_request_id": 291473309,
6+
"resolve_discussion": false,
7+
"discussion_id": null,
8+
"note": "Some draft note",
9+
"commit_id": null,
10+
"position": null,
11+
"line_code": null
12+
},
13+
{
14+
"id": 37349979,
15+
"author_id": 10271899,
16+
"merge_request_id": 291473309,
17+
"resolve_discussion": false,
18+
"discussion_id": null,
19+
"note": "Some draft note 2",
20+
"commit_id": null,
21+
"line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
22+
"position": {
23+
"base_sha": "64581c4ee41beb44d943d7801f82d9038e25e453",
24+
"start_sha": "87bffbff93bf334889780f54ae1922355661f867",
25+
"head_sha": "2c972dbf9094c380f5f00dcd8112d2c69b24c859",
26+
"old_path": "src/some-dir/some-file.js",
27+
"new_path": "src/some-dir/some-file.js",
28+
"position_type": "text",
29+
"old_line": null,
30+
"new_line": 9,
31+
"line_range": {
32+
"start": {
33+
"line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
34+
"type": "new",
35+
"old_line": null,
36+
"new_line": 9
37+
},
38+
"end": {
39+
"line_code": "3dacf79e0d779e2baa1c700cf56510e42f55cf85_10_9",
40+
"type": "new",
41+
"old_line": null,
42+
"new_line": 9
43+
}
44+
}
45+
}
46+
}
47+
]

testdata/update_draft_note.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": 37349980,
3+
"author_id": 10271899,
4+
"merge_request_id": 291473309,
5+
"resolve_discussion": false,
6+
"discussion_id": null,
7+
"note": "Some changed draft note",
8+
"commit_id": null,
9+
"position": null,
10+
"line_code": null
11+
}

0 commit comments

Comments
 (0)