From c66a9e0e77f8586dae36938064c15e75fa18c4ef Mon Sep 17 00:00:00 2001 From: Evgen Kostenko Date: Thu, 16 Jun 2016 12:20:47 +0300 Subject: [PATCH] add delete board with tests + go fmt --- board.go | 30 ++++++++++++++++++++++-------- board_test.go | 24 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/board.go b/board.go index 5c29246..e413f3e 100644 --- a/board.go +++ b/board.go @@ -21,11 +21,11 @@ type BoardsList struct { // Board represents a JIRA board type Board struct { - ID int `json:"id",omitempty"` - Self string `json:"self",omitempty"` - Name string `json:"name",omitempty"` - Type string `json:"type",omitempty"` - FilterId int `omitempty` + ID int `json:"id",omitempty"` + Self string `json:"self",omitempty"` + Name string `json:"name",omitempty"` + Type string `json:"type",omitempty"` + FilterId int `omitempty` } // BoardListOptions specifies the optional parameters to the BoardService.GetList @@ -71,8 +71,8 @@ func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Respon } // Returns the board for the given board Id. This board will only be returned if the user has permission to view it. -func (s *BoardService) Get(boardID string) (*Board, *http.Response, error) { - apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%s", boardID) +func (s *BoardService) Get(boardID int) (*Board, *http.Response, error) { + apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID) req, err := s.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err @@ -92,7 +92,7 @@ func (s *BoardService) Get(boardID string) (*Board, *http.Response, error) { // filterId - Id of a filter that the user has permissions to view. // Note, if the user does not have the 'Create shared objects' permission and tries to create a shared board, a private // board will be created instead (remember that board sharing depends on the filter sharing). - +// // JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-createBoard func (s *BoardService) Create(board *Board) (*Board, *http.Response, error) { @@ -109,3 +109,17 @@ func (s *BoardService) Create(board *Board) (*Board, *http.Response, error) { } return responseBoard, resp, nil } + +// Deletes the board. +// +// https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-deleteBoard +func (s *BoardService) Delete(boardID int) (*Board, *http.Response, error) { + apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%v", boardID) + req, err := s.client.NewRequest("DELETE", apiEndpoint, nil) + if err != nil { + return nil, nil, err + } + + resp, err := s.client.Do(req, nil) + return nil, resp, err +} diff --git a/board_test.go b/board_test.go index 2dc7f9e..727d928 100644 --- a/board_test.go +++ b/board_test.go @@ -75,7 +75,7 @@ func TestBoardGet(t *testing.T) { fmt.Fprint(w, `{"id":4,"self":"https://test.jira.org/rest/agile/1.0/board/1","name":"Test Weekly","type":"scrum"}`) }) - board, _, err := testClient.Board.Get("1") + board, _, err := testClient.Board.Get(1) if board == nil { t.Error("Expected board list. Board list is nil") } @@ -95,7 +95,7 @@ func TestBoardGet_NoBoard(t *testing.T) { fmt.Fprint(w, nil) }) - board, resp, err := testClient.Board.Get("99999999") + board, resp, err := testClient.Board.Get(99999999) if board != nil { t.Errorf("Expected nil. Got %s", err) } @@ -132,3 +132,23 @@ func TestBoardCreate(t *testing.T) { t.Errorf("Error given: %s", err) } } + +func TestBoardDelete(t *testing.T) { + setup() + defer teardown() + testMux.HandleFunc("/rest/agile/1.0/board/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testRequestURL(t, r, "/rest/agile/1.0/board/1") + + w.WriteHeader(http.StatusNoContent) + fmt.Fprint(w, `{}`) + }) + + _, resp, err := testClient.Board.Delete(1) + if resp.StatusCode != 204 { + t.Error("Expected board not deleted.") + } + if err != nil { + t.Errorf("Error given: %s", err) + } +}