1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-11-29 22:28:34 +02:00

Added Issue.Delete and unit test.

This commit is contained in:
Garrett Graupmann
2017-02-23 17:41:52 -08:00
parent 39a47d13a0
commit bac2760a87
2 changed files with 38 additions and 0 deletions

View File

@@ -783,3 +783,21 @@ func InitIssueWithMetaAndFields(metaProject *MetaProject, metaIssuetype *MetaIss
return issue, nil
}
// Delete will delete a specified issue.
func (s *IssueService) Delete(issueID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID)
// to enable deletion of subtasks; without this, the request will fail if the issue has subtasks
deletePayload := make(map[string]interface{})
deletePayload["deleteSubtasks"] = "true"
content, _ := json.Marshal(deletePayload)
req, err := s.client.NewRequest("DELETE", apiEndpoint, content)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
return resp, err
}

View File

@@ -957,3 +957,23 @@ func TestInitIssueWithmetaAndFields_FailureWithUnknownValueType(t *testing.T) {
}
}
func TestIssueService_Delete(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10002", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/api/2/issue/10002")
w.WriteHeader(http.StatusNoContent)
fmt.Fprint(w, `{}`)
})
resp, err := testClient.Issue.Delete("10002")
if resp.StatusCode != 204 {
t.Error("Expected issue not deleted.")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}