Skip to content

Commit 48a5fb2

Browse files
committed
add test case
1 parent 1d6192c commit 48a5fb2

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

github/issue_import_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,47 @@ func TestIssueImportService_Create_defered(t *testing.T) {
120120
}
121121
}
122122

123+
func TestIssueImportService_Create_badResponse(t *testing.T) {
124+
client, mux, _, teardown := setup()
125+
defer teardown()
126+
127+
createdAt := time.Date(2020, time.August, 11, 15, 30, 0, 0, time.UTC)
128+
input := &IssueImportRequest{
129+
IssueImport: IssueImport{
130+
Assignee: String("developer"),
131+
Body: "Dummy description",
132+
CreatedAt: &Timestamp{createdAt},
133+
Labels: []string{"l1", "l2"},
134+
Milestone: Int(1),
135+
Title: "Dummy Issue",
136+
},
137+
Comments: []*Comment{{
138+
CreatedAt: &Timestamp{createdAt},
139+
Body: "Comment body",
140+
}},
141+
}
142+
143+
mux.HandleFunc("/repos/o/r/import/issues", func(w http.ResponseWriter, r *http.Request) {
144+
v := new(IssueImportRequest)
145+
json.NewDecoder(r.Body).Decode(v)
146+
testMethod(t, r, "POST")
147+
testHeader(t, r, "Accept", mediaTypeIssueImportAPI)
148+
if !cmp.Equal(v, input) {
149+
t.Errorf("Request body = %+v, want %+v", v, input)
150+
}
151+
152+
w.WriteHeader(http.StatusAccepted)
153+
w.Write([]byte("{[}"))
154+
})
155+
156+
ctx := context.Background()
157+
_, _, err := client.IssueImport.Create(ctx, "o", "r", input)
158+
159+
if err == nil || err.Error() != "invalid character '[' looking for beginning of object key string" {
160+
t.Errorf("unexpected error: %v", err)
161+
}
162+
}
163+
123164
func TestIssueImportService_Create_invalidOwner(t *testing.T) {
124165
client, _, _, teardown := setup()
125166
defer teardown()

0 commit comments

Comments
 (0)