1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-03 14:52:10 +02:00

test: Add unit test for priority api

This commit is contained in:
Thibaut Rousseau 2018-06-12 10:38:13 +02:00
parent 8491cb0034
commit e3ab82535d
No known key found for this signature in database
GPG Key ID: BCA6444086610E3D
3 changed files with 75 additions and 1 deletions

42
mocks/all_priorities.json Normal file
View File

@ -0,0 +1,42 @@
[
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/1",
"statusColor": "#cc0000",
"description": "Blocks development and/or testing work, production could not run",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/blocker.svg",
"name": "Blocker",
"id": "1"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/2",
"statusColor": "#ff0000",
"description": "Crashes, loss of data, severe memory leak.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/critical.svg",
"name": "Critical",
"id": "2"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/3",
"statusColor": "#009900",
"description": "Major loss of function.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/major.svg",
"name": "Major",
"id": "3"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/4",
"statusColor": "#006600",
"description": "Minor loss of function, or other problem where easy workaround is present.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/minor.svg",
"name": "Minor",
"id": "4"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/5",
"statusColor": "#003300",
"description": "Cosmetic problem like misspelt words or misaligned text.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/trivial.svg",
"name": "Trivial",
"id": "5"
}
]

View File

@ -29,7 +29,7 @@ func (s *PriorityService) GetList() ([]Priority, *Response, error) {
}
priorityList := []Priority{}
resp, err := s.client.Do(req, priorityList)
resp, err := s.client.Do(req, &priorityList)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}

32
priority_test.go Normal file
View File

@ -0,0 +1,32 @@
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestPriorityService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/priority"
raw, err := ioutil.ReadFile("./mocks/all_priorities.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))
})
priorities, _, err := testClient.Priority.GetList()
if priorities == nil {
t.Error("Expected priority list. Priority list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}