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

252 lines
6.1 KiB
Go
Raw Permalink Normal View History

package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestBoardService_GetAllBoards(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/agile/1.0/board"
raw, err := ioutil.ReadFile("./mocks/all_boards.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Board.GetAllBoards(nil)
if projects == nil {
t.Error("Expected boards list. Boards list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
// Test with params
func TestBoardService_GetAllBoards_WithFilter(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/agile/1.0/board"
raw, err := ioutil.ReadFile("./mocks/all_boards_filtered.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
testRequestParams(t, r, map[string]string{"type": "scrum", "name": "Test", "startAt": "1", "maxResults": "10", "projectKeyOrId": "TE"})
fmt.Fprint(w, string(raw))
})
2016-06-16 09:52:16 +02:00
boardsListOptions := &BoardListOptions{
2016-06-15 19:15:12 +02:00
BoardType: "scrum",
Name: "Test",
ProjectKeyOrID: "TE",
}
boardsListOptions.StartAt = 1
boardsListOptions.MaxResults = 10
projects, _, err := testClient.Board.GetAllBoards(boardsListOptions)
if projects == nil {
t.Error("Expected boards list. Boards list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
2016-06-16 09:52:16 +02:00
func TestBoardService_GetBoard(t *testing.T) {
2016-06-16 09:52:16 +02:00
setup()
defer teardown()
testAPIEdpoint := "/rest/agile/1.0/board/1"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
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.GetBoard(1)
2016-06-16 09:52:16 +02:00
if board == nil {
t.Error("Expected board list. Board list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestBoardService_GetBoard_WrongID(t *testing.T) {
2016-06-16 09:52:16 +02:00
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/board/99999999"
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, nil)
})
board, resp, err := testClient.Board.GetBoard(99999999)
2016-06-16 09:52:16 +02:00
if board != nil {
t.Errorf("Expected nil. Got %s", err)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err == nil {
t.Errorf("Error given: %s", err)
}
}
func TestBoardService_CreateBoard(t *testing.T) {
2016-06-16 09:52:16 +02:00
setup()
defer teardown()
testMux.HandleFunc("/rest/agile/1.0/board", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testRequestURL(t, r, "/rest/agile/1.0/board")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"id":17,"self":"https://test.jira.org/rest/agile/1.0/board/17","name":"Test","type":"kanban"}`)
})
b := &Board{
Name: "Test",
Type: "kanban",
FilterID: 17,
2016-06-16 09:52:16 +02:00
}
issue, _, err := testClient.Board.CreateBoard(b)
2016-06-16 09:52:16 +02:00
if issue == nil {
t.Error("Expected board. Board is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
2016-06-16 11:20:47 +02:00
func TestBoardService_DeleteBoard(t *testing.T) {
2016-06-16 11:20:47 +02:00
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.DeleteBoard(1)
2016-06-16 11:20:47 +02:00
if resp.StatusCode != 204 {
t.Error("Expected board not deleted.")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestBoardService_GetAllSprints(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/agile/1.0/board/123/sprint"
raw, err := ioutil.ReadFile("./mocks/sprints.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})
sprints, _, err := testClient.Board.GetAllSprints("123")
if err != nil {
t.Errorf("Got error: %v", err)
}
if sprints == nil {
t.Error("Expected sprint list. Got nil.")
}
if len(sprints) != 4 {
t.Errorf("Expected 4 transitions. Got %d", len(sprints))
}
}
func TestBoardService_GetAllSprintsWithOptions(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/agile/1.0/board/123/sprint"
raw, err := ioutil.ReadFile("./mocks/sprints_filtered.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})
sprints, _, err := testClient.Board.GetAllSprintsWithOptions(123, &GetAllSprintsOptions{State: "active,future"})
if err != nil {
t.Errorf("Got error: %v", err)
}
if sprints == nil {
t.Error("Expected sprint list. Got nil.")
style: Fix staticcheck (static analysis) errors for this library (#283) * style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)" staticcheck is a static analysis tool for go. It reports several "error strings should not be capitalized (ST1005)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)" staticcheck is a static analysis tool for go. It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "type X is unused (U1000)" staticcheck is a static analysis tool for go. It reports several "type X is unused (U1000)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)" staticcheck is a static analysis tool for go. It reports several - should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003) - should use strings.EqualFold instead (SA6005) messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)" staticcheck is a static analysis tool for go. It report several "unnecessary use of fmt.Sprintf (S1039)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "this value of X is never used (SA4006)" staticcheck is a static analysis tool for go. It report several "this value of X is never used (SA4006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "redundant return statement (S1023)" staticcheck is a static analysis tool for go. It report several "redundant return statement (S1023)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)" staticcheck is a static analysis tool for go. It report several file.go:Line:character: possible nil pointer dereference (SA5011) file.go:Line:character: this check suggests that the pointer can be nil messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "this value of X is never used (SA4006)" staticcheck is a static analysis tool for go. It report several "this value of X is never used (SA4006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280
2020-05-02 23:08:01 +02:00
return
}
if len(sprints.Values) != 1 {
t.Errorf("Expected 1 transition. Got %d", len(sprints.Values))
}
}
2019-08-18 16:17:16 +02:00
func TestBoardService_GetBoardConfigoration(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/agile/1.0/board/35/configuration"
raw, err := ioutil.ReadFile("./mocks/board_configuration.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})
boardConfiguration, _, err := testClient.Board.GetBoardConfiguration(35)
if err != nil {
t.Errorf("Got error: %v", err)
}
if boardConfiguration == nil {
t.Error("Expected boardConfiguration. Got nil.")
style: Fix staticcheck (static analysis) errors for this library (#283) * style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)" staticcheck is a static analysis tool for go. It reports several "error strings should not be capitalized (ST1005)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)" staticcheck is a static analysis tool for go. It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "type X is unused (U1000)" staticcheck is a static analysis tool for go. It reports several "type X is unused (U1000)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)" staticcheck is a static analysis tool for go. It reports several - should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003) - should use strings.EqualFold instead (SA6005) messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)" staticcheck is a static analysis tool for go. It report several "unnecessary use of fmt.Sprintf (S1039)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "this value of X is never used (SA4006)" staticcheck is a static analysis tool for go. It report several "this value of X is never used (SA4006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "redundant return statement (S1023)" staticcheck is a static analysis tool for go. It report several "redundant return statement (S1023)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)" staticcheck is a static analysis tool for go. It report several file.go:Line:character: possible nil pointer dereference (SA5011) file.go:Line:character: this check suggests that the pointer can be nil messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280 * style: Fix staticcheck errors for "this value of X is never used (SA4006)" staticcheck is a static analysis tool for go. It report several "this value of X is never used (SA4006)" messages. Here, we fix it to be more compliant with the go coding styleguide. Related: #280
2020-05-02 23:08:01 +02:00
return
2019-08-18 16:17:16 +02:00
}
if len(boardConfiguration.ColumnConfig.Columns) != 6 {
t.Errorf("Expected 6 columns. go %d", len(boardConfiguration.ColumnConfig.Columns))
}
}