1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-24 08:22:42 +02:00

Add delete method for user

This commit is contained in:
Vladimir N. Indik 2018-07-11 10:53:16 +02:00 committed by Andy Grunwald
parent 13606a505f
commit 8201aaa4d4
2 changed files with 38 additions and 0 deletions

18
user.go
View File

@ -90,6 +90,24 @@ func (s *UserService) Create(user *User) (*User, *Response, error) {
return responseUser, resp, nil
}
// Delete deletes an user from JIRA.
// Returns http.StatusNoContent on success.
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-user-delete
func (s *UserService) Delete(username string) (*Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/2/user?username=%s", username)
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, NewJiraError(resp, err)
}
return resp, nil
}
// GetGroups returns the groups which the user belongs to
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-getUserGroups

View File

@ -56,6 +56,26 @@ func TestUserService_Create(t *testing.T) {
}
}
func TestUserService_Delete(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/user", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/api/2/user?username=fred")
w.WriteHeader(http.StatusNoContent)
})
resp, err := testClient.User.Delete("fred")
if err != nil {
t.Errorf("Error given: %s", err)
}
if resp.StatusCode != http.StatusNoContent {
t.Errorf("Wrong status code: %d. Expected %d", resp.StatusCode, http.StatusNoContent)
}
}
func TestUserService_GetGroups(t *testing.T) {
setup()
defer teardown()