mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-07-01 00:25:00 +02:00
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
This commit is contained in:
@ -79,10 +79,10 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
|
return false, fmt.Errorf("auth at Jira instance failed (HTTP(S) request). %s", err)
|
||||||
}
|
}
|
||||||
if resp != nil && resp.StatusCode != 200 {
|
if resp != nil && resp.StatusCode != 200 {
|
||||||
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). Status code: %d", resp.StatusCode)
|
return false, fmt.Errorf("auth at Jira instance failed (HTTP(S) request). Status code: %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.client.session = session
|
s.client.session = session
|
||||||
@ -127,15 +127,15 @@ func (s *AuthenticationService) Logout() error {
|
|||||||
apiEndpoint := "rest/auth/1/session"
|
apiEndpoint := "rest/auth/1/session"
|
||||||
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
|
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Creating the request to log the user out failed : %s", err)
|
return fmt.Errorf("creating the request to log the user out failed : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := s.client.Do(req, nil)
|
resp, err := s.client.Do(req, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error sending the logout request: %s", err)
|
return fmt.Errorf("error sending the logout request: %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 204 {
|
if resp.StatusCode != 204 {
|
||||||
return fmt.Errorf("The logout was unsuccessful with status %d", resp.StatusCode)
|
return fmt.Errorf("the logout was unsuccessful with status %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If logout successful, delete session
|
// If logout successful, delete session
|
||||||
@ -150,37 +150,37 @@ func (s *AuthenticationService) Logout() error {
|
|||||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#auth/1/session
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#auth/1/session
|
||||||
func (s *AuthenticationService) GetCurrentUser() (*Session, error) {
|
func (s *AuthenticationService) GetCurrentUser() (*Session, error) {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return nil, fmt.Errorf("AUthenticaiton Service is not instantiated")
|
return nil, fmt.Errorf("authenticaiton Service is not instantiated")
|
||||||
}
|
}
|
||||||
if s.authType != authTypeSession || s.client.session == nil {
|
if s.authType != authTypeSession || s.client.session == nil {
|
||||||
return nil, fmt.Errorf("No user is authenticated yet")
|
return nil, fmt.Errorf("no user is authenticated yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
apiEndpoint := "rest/auth/1/session"
|
apiEndpoint := "rest/auth/1/session"
|
||||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not create request for getting user info : %s", err)
|
return nil, fmt.Errorf("could not create request for getting user info : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := s.client.Do(req, nil)
|
resp, err := s.client.Do(req, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error sending request to get user info : %s", err)
|
return nil, fmt.Errorf("error sending request to get user info : %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return nil, fmt.Errorf("Getting user info failed with status : %d", resp.StatusCode)
|
return nil, fmt.Errorf("getting user info failed with status : %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
ret := new(Session)
|
ret := new(Session)
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Couldn't read body from the response : %s", err)
|
return nil, fmt.Errorf("couldn't read body from the response : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(data, &ret)
|
err = json.Unmarshal(data, &ret)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not unmarshall received user info : %s", err)
|
return nil, fmt.Errorf("could not unmarshall received user info : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
@ -19,10 +19,10 @@ func TestAuthenticationService_AcquireSessionCookie_Failure(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +53,10 @@ func TestAuthenticationService_AcquireSessionCookie_Success(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +144,10 @@ func TestAithenticationService_GetUserInfo_AccessForbidden_Fail(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,10 +182,10 @@ func TestAuthenticationService_GetUserInfo_NonOkStatusCode_Fail(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,10 +238,10 @@ func TestAuthenticationService_GetUserInfo_Success(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,10 +280,10 @@ func TestAuthenticationService_Logout_Success(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error in read body: %s", err)
|
t.Errorf("Error in read body: %s", err)
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
|
||||||
t.Error("No username found")
|
t.Error("No username found")
|
||||||
}
|
}
|
||||||
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
|
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
|
||||||
t.Error("No password found")
|
t.Error("No password found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,13 +204,13 @@ func TestBoardService_GetAllSprintsWithOptions(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
sprints, _, err := testClient.Board.GetAllSprintsWithOptions(123, &GetAllSprintsOptions{State: "active,future"})
|
sprints, _, err := testClient.Board.GetAllSprintsWithOptions(123, &GetAllSprintsOptions{State: "active,future"})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error: %v", err)
|
t.Errorf("Got error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sprints == nil {
|
if sprints == nil {
|
||||||
t.Error("Expected sprint list. Got nil.")
|
t.Error("Expected sprint list. Got nil.")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sprints.Values) != 1 {
|
if len(sprints.Values) != 1 {
|
||||||
@ -235,13 +235,13 @@ func TestBoardService_GetBoardConfigoration(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
boardConfiguration, _, err := testClient.Board.GetBoardConfiguration(35)
|
boardConfiguration, _, err := testClient.Board.GetBoardConfiguration(35)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error: %v", err)
|
t.Errorf("Got error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if boardConfiguration == nil {
|
if boardConfiguration == nil {
|
||||||
t.Error("Expected boardConfiguration. Got nil.")
|
t.Error("Expected boardConfiguration. Got nil.")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(boardConfiguration.ColumnConfig.Columns) != 6 {
|
if len(boardConfiguration.ColumnConfig.Columns) != 6 {
|
||||||
|
4
error.go
4
error.go
@ -34,12 +34,12 @@ func NewJiraError(resp *Response, httpError error) error {
|
|||||||
if strings.HasPrefix(contentType, "application/json") {
|
if strings.HasPrefix(contentType, "application/json") {
|
||||||
err = json.Unmarshal(body, &jerr)
|
err = json.Unmarshal(body, &jerr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error())
|
httpError = errors.Wrap(errors.New("could not parse JSON"), httpError.Error())
|
||||||
return errors.Wrap(err, httpError.Error())
|
return errors.Wrap(err, httpError.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if httpError == nil {
|
if httpError == nil {
|
||||||
return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body))
|
return fmt.Errorf("got response status %s:%s", resp.Status, string(body))
|
||||||
}
|
}
|
||||||
return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body)))
|
return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body)))
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,8 @@ func TestError_BadJSON(t *testing.T) {
|
|||||||
err := NewJiraError(resp, errors.New("Original http error"))
|
err := NewJiraError(resp, errors.New("Original http error"))
|
||||||
msg := err.Error()
|
msg := err.Error()
|
||||||
|
|
||||||
if !strings.Contains(msg, "Could not parse JSON") {
|
if !strings.Contains(msg, "could not parse JSON") {
|
||||||
t.Errorf("Expected the 'Could not parse JSON' error message: Got\n%s\n", msg)
|
t.Errorf("Expected the 'could not parse JSON' error message: Got\n%s\n", msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func TestFilterService_Get(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
testMethod(t, request, "GET")
|
testMethod(t, request, "GET")
|
||||||
testRequestURL(t, request, testAPIEndpoint)
|
testRequestURL(t, request, testAPIEndpoint)
|
||||||
fmt.Fprintf(writer, string(raw))
|
fmt.Fprint(writer, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
filter, _, err := testClient.Filter.Get(10000)
|
filter, _, err := testClient.Filter.Get(10000)
|
||||||
|
12
issue.go
12
issue.go
@ -192,7 +192,7 @@ func (i *IssueFields) UnmarshalJSON(data []byte) error {
|
|||||||
options := strings.Split(tagDetail, ",")
|
options := strings.Split(tagDetail, ",")
|
||||||
|
|
||||||
if len(options) == 0 {
|
if len(options) == 0 {
|
||||||
return fmt.Errorf("No tags options found for %s", field.Name)
|
return fmt.Errorf("no tags options found for %s", field.Name)
|
||||||
}
|
}
|
||||||
// the first one is the json tag
|
// the first one is the json tag
|
||||||
key := options[0]
|
key := options[0]
|
||||||
@ -757,11 +757,11 @@ func (s *IssueService) Create(issue *Issue) (*Issue, *Response, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, fmt.Errorf("Could not read the returned data")
|
return nil, resp, fmt.Errorf("could not read the returned data")
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(data, responseIssue)
|
err = json.Unmarshal(data, responseIssue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, fmt.Errorf("Could not unmarshall the data into struct")
|
return nil, resp, fmt.Errorf("could not unmarshall the data into struct")
|
||||||
}
|
}
|
||||||
return responseIssue, resp, nil
|
return responseIssue, resp, nil
|
||||||
}
|
}
|
||||||
@ -939,7 +939,7 @@ func (s *IssueService) UpdateWorklogRecord(issueID, worklogID string, record *Wo
|
|||||||
//
|
//
|
||||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
|
||||||
func (s *IssueService) AddLink(issueLink *IssueLink) (*Response, error) {
|
func (s *IssueService) AddLink(issueLink *IssueLink) (*Response, error) {
|
||||||
apiEndpoint := fmt.Sprintf("rest/api/2/issueLink")
|
apiEndpoint := "rest/api/2/issueLink"
|
||||||
req, err := s.client.NewRequest("POST", apiEndpoint, issueLink)
|
req, err := s.client.NewRequest("POST", apiEndpoint, issueLink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1195,7 +1195,7 @@ func InitIssueWithMetaAndFields(metaProject *MetaProject, metaIssuetype *MetaIss
|
|||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unknown issue type encountered: %s for %s", valueType, key)
|
return nil, fmt.Errorf("unknown issue type encountered: %s for %s", valueType, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1240,8 +1240,8 @@ func (s *IssueService) GetWatchers(issueID string) (*[]User, *Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := []User{}
|
result := []User{}
|
||||||
user := new(User)
|
|
||||||
for _, watcher := range watches.Watchers {
|
for _, watcher := range watches.Watchers {
|
||||||
|
var user *User
|
||||||
if watcher.AccountID != "" {
|
if watcher.AccountID != "" {
|
||||||
user, resp, err = s.client.User.GetByAccountID(watcher.AccountID)
|
user, resp, err = s.client.User.GetByAccountID(watcher.AccountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -322,15 +322,16 @@ func TestIssueService_AddLink(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp, err := testClient.Issue.AddLink(il)
|
resp, err := testClient.Issue.AddLink(il)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
t.Error("Expected response. Response is nil")
|
t.Error("Expected response. Response is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("Expected Status code 200. Given %d", resp.StatusCode)
|
t.Errorf("Expected Status code 200. Given %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueService_Get_Fields(t *testing.T) {
|
func TestIssueService_Get_Fields(t *testing.T) {
|
||||||
@ -344,8 +345,12 @@ func TestIssueService_Get_Fields(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
issue, _, err := testClient.Issue.Get("10002", nil)
|
issue, _, err := testClient.Issue.Get("10002", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Error("Expected issue. Issue is nil")
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(issue.Fields.Labels, []string{"test"}) {
|
if !reflect.DeepEqual(issue.Fields.Labels, []string{"test"}) {
|
||||||
t.Error("Expected labels for the returned issue")
|
t.Error("Expected labels for the returned issue")
|
||||||
@ -357,10 +362,6 @@ func TestIssueService_Get_Fields(t *testing.T) {
|
|||||||
if issue.Fields.Epic == nil {
|
if issue.Fields.Epic == nil {
|
||||||
t.Error("Epic expected but not found")
|
t.Error("Epic expected but not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueService_Get_RenderedFields(t *testing.T) {
|
func TestIssueService_Get_RenderedFields(t *testing.T) {
|
||||||
@ -374,8 +375,12 @@ func TestIssueService_Get_RenderedFields(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
issue, _, err := testClient.Issue.Get("10002", nil)
|
issue, _, err := testClient.Issue.Get("10002", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Error("Expected issue. Issue is nil")
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if issue.RenderedFields.Updated != "2 hours ago" {
|
if issue.RenderedFields.Updated != "2 hours ago" {
|
||||||
t.Error("Expected updated to equla '2 hours ago' for rendered field")
|
t.Error("Expected updated to equla '2 hours ago' for rendered field")
|
||||||
@ -388,10 +393,6 @@ func TestIssueService_Get_RenderedFields(t *testing.T) {
|
|||||||
if comment.Body != "This <strong>is</strong> HTML" {
|
if comment.Body != "This <strong>is</strong> HTML" {
|
||||||
t.Errorf("Wrong comment body returned in RenderedField. Got %s", comment.Body)
|
t.Errorf("Wrong comment body returned in RenderedField. Got %s", comment.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueService_DownloadAttachment(t *testing.T) {
|
func TestIssueService_DownloadAttachment(t *testing.T) {
|
||||||
@ -408,8 +409,12 @@ func TestIssueService_DownloadAttachment(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
resp, err := testClient.Issue.DownloadAttachment("10000")
|
resp, err := testClient.Issue.DownloadAttachment("10000")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
t.Error("Expected response. Response is nil")
|
t.Error("Expected response. Response is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@ -424,9 +429,6 @@ func TestIssueService_DownloadAttachment(t *testing.T) {
|
|||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("Expected Status code 200. Given %d", resp.StatusCode)
|
t.Errorf("Expected Status code 200. Given %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueService_DownloadAttachment_BadStatus(t *testing.T) {
|
func TestIssueService_DownloadAttachment_BadStatus(t *testing.T) {
|
||||||
@ -443,6 +445,7 @@ func TestIssueService_DownloadAttachment_BadStatus(t *testing.T) {
|
|||||||
resp, err := testClient.Issue.DownloadAttachment("10000")
|
resp, err := testClient.Issue.DownloadAttachment("10000")
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
t.Error("Expected response. Response is nil")
|
t.Error("Expected response. Response is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@ -1638,6 +1641,7 @@ func TestIssueService_Get_Fields_Changelog(t *testing.T) {
|
|||||||
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand: "changelog"})
|
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand: "changelog"})
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Error("Expected issue. Issue is nil")
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(issue.Changelog.Histories) != 1 {
|
if len(issue.Changelog.Histories) != 1 {
|
||||||
@ -1668,6 +1672,7 @@ func TestIssueService_Get_Transitions(t *testing.T) {
|
|||||||
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand: "transitions"})
|
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand: "transitions"})
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Error("Expected issue. Issue is nil")
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(issue.Transitions) != 1 {
|
if len(issue.Transitions) != 1 {
|
||||||
@ -1696,8 +1701,12 @@ func TestIssueService_Get_Fields_AffectsVersions(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
issue, _, err := testClient.Issue.Get("10002", nil)
|
issue, _, err := testClient.Issue.Get("10002", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Error("Expected issue. Issue is nil")
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(issue.Fields.AffectsVersions, []*AffectsVersion{
|
if !reflect.DeepEqual(issue.Fields.AffectsVersions, []*AffectsVersion{
|
||||||
{
|
{
|
||||||
@ -1712,10 +1721,6 @@ func TestIssueService_Get_Fields_AffectsVersions(t *testing.T) {
|
|||||||
}) {
|
}) {
|
||||||
t.Error("Expected AffectsVersions for the returned issue")
|
t.Error("Expected AffectsVersions for the returned issue")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueService_GetRemoteLinks(t *testing.T) {
|
func TestIssueService_GetRemoteLinks(t *testing.T) {
|
||||||
@ -1736,13 +1741,13 @@ func TestIssueService_GetRemoteLinks(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
remoteLinks, _, err := testClient.Issue.GetRemoteLinks("123")
|
remoteLinks, _, err := testClient.Issue.GetRemoteLinks("123")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error: %v", err)
|
t.Errorf("Got error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if remoteLinks == nil {
|
if remoteLinks == nil {
|
||||||
t.Error("Expected remote links list. Got nil.")
|
t.Error("Expected remote links list. Got nil.")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*remoteLinks) != 2 {
|
if len(*remoteLinks) != 2 {
|
||||||
|
@ -68,12 +68,12 @@ func (s *IssueLinkTypeService) Create(linkType *IssueLinkType) (*IssueLinkType,
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could not read the returned data")
|
e := fmt.Errorf("could not read the returned data")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(data, responseLinkType)
|
err = json.Unmarshal(data, responseLinkType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could no unmarshal the data into struct")
|
e := fmt.Errorf("could no unmarshal the data into struct")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
return linkType, resp, nil
|
return linkType, resp, nil
|
||||||
|
3
jira.go
3
jira.go
@ -285,7 +285,7 @@ func CheckResponse(r *http.Response) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := fmt.Errorf("Request failed. Please analyze the request body for more details. Status code: %d", r.StatusCode)
|
err := fmt.Errorf("request failed. Please analyze the request body for more details. Status code: %d", r.StatusCode)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,6 @@ func (r *Response) populatePageValues(v interface{}) {
|
|||||||
r.MaxResults = value.MaxResults
|
r.MaxResults = value.MaxResults
|
||||||
r.Total = value.Total
|
r.Total = value.Total
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BasicAuthTransport is an http.RoundTripper that authenticates all requests
|
// BasicAuthTransport is an http.RoundTripper that authenticates all requests
|
||||||
|
@ -28,8 +28,6 @@ var (
|
|||||||
testServer *httptest.Server
|
testServer *httptest.Server
|
||||||
)
|
)
|
||||||
|
|
||||||
type testValues map[string]string
|
|
||||||
|
|
||||||
// setup sets up a test HTTP server along with a jira.Client that is configured to talk to that test server.
|
// setup sets up a test HTTP server along with a jira.Client that is configured to talk to that test server.
|
||||||
// Tests should register handlers on mux which provide mock responses for the API method being tested.
|
// Tests should register handlers on mux which provide mock responses for the API method being tested.
|
||||||
func setup() {
|
func setup() {
|
||||||
@ -89,12 +87,12 @@ func TestNewClient_WithHttpClient(t *testing.T) {
|
|||||||
httpClient := http.DefaultClient
|
httpClient := http.DefaultClient
|
||||||
httpClient.Timeout = 10 * time.Minute
|
httpClient.Timeout = 10 * time.Minute
|
||||||
c, err := NewClient(httpClient, testJIRAInstanceURL)
|
c, err := NewClient(httpClient, testJIRAInstanceURL)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got an error: %s", err)
|
t.Errorf("Got an error: %s", err)
|
||||||
}
|
}
|
||||||
if c == nil {
|
if c == nil {
|
||||||
t.Error("Expected a client. Got none")
|
t.Error("Expected a client. Got none")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(c.client, httpClient) {
|
if !reflect.DeepEqual(c.client, httpClient) {
|
||||||
t.Errorf("HTTP clients are not equal. Injected %+v, got %+v", httpClient, c.client)
|
t.Errorf("HTTP clients are not equal. Injected %+v, got %+v", httpClient, c.client)
|
||||||
@ -378,10 +376,6 @@ func TestClient_Do_HTTPResponse(t *testing.T) {
|
|||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
type foo struct {
|
|
||||||
A string
|
|
||||||
}
|
|
||||||
|
|
||||||
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if m := "GET"; m != r.Method {
|
if m := "GET"; m != r.Method {
|
||||||
t.Errorf("Request method = %v, want %v", r.Method, m)
|
t.Errorf("Request method = %v, want %v", r.Method, m)
|
||||||
|
10
metaissue.go
10
metaissue.go
@ -101,7 +101,7 @@ func (s *IssueService) GetEditMeta(issue *Issue) (*EditMetaInfo, *Response, erro
|
|||||||
// The comparison of the name is case insensitive.
|
// The comparison of the name is case insensitive.
|
||||||
func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
|
func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
|
||||||
for _, m := range m.Projects {
|
for _, m := range m.Projects {
|
||||||
if strings.ToLower(m.Name) == strings.ToLower(name) {
|
if strings.EqualFold(m.Name, name) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
|
|||||||
// The comparison of the name is case insensitive.
|
// The comparison of the name is case insensitive.
|
||||||
func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
|
func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
|
||||||
for _, m := range m.Projects {
|
for _, m := range m.Projects {
|
||||||
if strings.ToLower(m.Key) == strings.ToLower(key) {
|
if strings.EqualFold(m.Key, key) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
|
|||||||
// The comparison of the name is case insensitive
|
// The comparison of the name is case insensitive
|
||||||
func (p *MetaProject) GetIssueTypeWithName(name string) *MetaIssueType {
|
func (p *MetaProject) GetIssueTypeWithName(name string) *MetaIssueType {
|
||||||
for _, m := range p.IssueTypes {
|
for _, m := range p.IssueTypes {
|
||||||
if strings.ToLower(m.Name) == strings.ToLower(name) {
|
if strings.EqualFold(m.Name, name) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (boo
|
|||||||
for name := range mandatory {
|
for name := range mandatory {
|
||||||
requiredFields = append(requiredFields, name)
|
requiredFields = append(requiredFields, name)
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("Required field not found in provided jira.fields. Required are: %#v", requiredFields)
|
return false, fmt.Errorf("required field not found in provided jira.fields. Required are: %#v", requiredFields)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (boo
|
|||||||
for name := range all {
|
for name := range all {
|
||||||
availableFields = append(availableFields, name)
|
availableFields = append(availableFields, name)
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("Fields in jira.fields are not available in jira. Available are: %#v", availableFields)
|
return false, fmt.Errorf("fields in jira.fields are not available in jira. Available are: %#v", availableFields)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (s *PermissionSchemeService) Get(schemeID int) (*PermissionScheme, *Respons
|
|||||||
return nil, resp, jerr
|
return nil, resp, jerr
|
||||||
}
|
}
|
||||||
if ps.Self == "" {
|
if ps.Self == "" {
|
||||||
return nil, resp, fmt.Errorf("No permissionscheme with ID %d found", schemeID)
|
return nil, resp, fmt.Errorf("no permissionscheme with ID %d found", schemeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps, resp, nil
|
return ps, resp, nil
|
||||||
|
@ -19,19 +19,20 @@ func TestPermissionSchemeService_GetList(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testAPIEndpoint)
|
testRequestURL(t, r, testAPIEndpoint)
|
||||||
fmt.Fprintf(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
permissionScheme, _, err := testClient.PermissionScheme.GetList()
|
permissionScheme, _, err := testClient.PermissionScheme.GetList()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %v", err)
|
||||||
|
}
|
||||||
if permissionScheme == nil {
|
if permissionScheme == nil {
|
||||||
t.Error("Expected permissionScheme list. PermissionScheme list is nil")
|
t.Error("Expected permissionScheme list. PermissionScheme list is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if len(permissionScheme.PermissionSchemes) != 2 {
|
if len(permissionScheme.PermissionSchemes) != 2 {
|
||||||
t.Errorf("Expected %d permissionSchemes but got %d", 2, len(permissionScheme.PermissionSchemes))
|
t.Errorf("Expected %d permissionSchemes but got %d", 2, len(permissionScheme.PermissionSchemes))
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPermissionSchemeService_GetList_NoList(t *testing.T) {
|
func TestPermissionSchemeService_GetList_NoList(t *testing.T) {
|
||||||
@ -46,7 +47,7 @@ func TestPermissionSchemeService_GetList_NoList(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testAPIEndpoint)
|
testRequestURL(t, r, testAPIEndpoint)
|
||||||
fmt.Fprintf(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
permissionScheme, _, err := testClient.PermissionScheme.GetList()
|
permissionScheme, _, err := testClient.PermissionScheme.GetList()
|
||||||
@ -69,7 +70,7 @@ func TestPermissionSchemeService_Get(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
testMethod(t, request, "GET")
|
testMethod(t, request, "GET")
|
||||||
testRequestURL(t, request, testAPIEdpoint)
|
testRequestURL(t, request, testAPIEdpoint)
|
||||||
fmt.Fprintf(writer, string(raw))
|
fmt.Fprint(writer, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
permissionScheme, _, err := testClient.PermissionScheme.Get(10100)
|
permissionScheme, _, err := testClient.PermissionScheme.Get(10100)
|
||||||
@ -92,7 +93,7 @@ func TestPermissionSchemeService_Get_NoScheme(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
testMethod(t, request, "GET")
|
testMethod(t, request, "GET")
|
||||||
testRequestURL(t, request, testAPIEdpoint)
|
testRequestURL(t, request, testAPIEdpoint)
|
||||||
fmt.Fprintf(writer, string(raw))
|
fmt.Fprint(writer, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
permissionScheme, _, err := testClient.PermissionScheme.Get(99999)
|
permissionScheme, _, err := testClient.PermissionScheme.Get(99999)
|
||||||
|
@ -71,12 +71,13 @@ func TestProjectService_Get(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
projects, _, err := testClient.Project.Get("12310505")
|
projects, _, err := testClient.Project.Get("12310505")
|
||||||
if projects == nil {
|
|
||||||
t.Error("Expected project list. Project list is nil")
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error given: %s", err)
|
t.Errorf("Error given: %s", err)
|
||||||
}
|
}
|
||||||
|
if projects == nil {
|
||||||
|
t.Error("Expected project list. Project list is nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(projects.Roles) != 9 {
|
if len(projects.Roles) != 9 {
|
||||||
t.Errorf("Expected 9 roles but got %d", len(projects.Roles))
|
t.Errorf("Expected 9 roles but got %d", len(projects.Roles))
|
||||||
}
|
}
|
||||||
|
2
role.go
2
role.go
@ -69,7 +69,7 @@ func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
|
|||||||
return nil, resp, jerr
|
return nil, resp, jerr
|
||||||
}
|
}
|
||||||
if role.Self == "" {
|
if role.Self == "" {
|
||||||
return nil, resp, fmt.Errorf("No role with ID %d found", roleID)
|
return nil, resp, fmt.Errorf("no role with ID %d found", roleID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return role, resp, err
|
return role, resp, err
|
||||||
|
15
role_test.go
15
role_test.go
@ -20,7 +20,7 @@ func TestRoleService_GetList_NoList(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testAPIEndpoint)
|
testRequestURL(t, r, testAPIEndpoint)
|
||||||
fmt.Fprintf(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
roles, _, err := testClient.Role.GetList()
|
roles, _, err := testClient.Role.GetList()
|
||||||
@ -44,19 +44,20 @@ func TestRoleService_GetList(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, "GET")
|
testMethod(t, r, "GET")
|
||||||
testRequestURL(t, r, testAPIEndpoint)
|
testRequestURL(t, r, testAPIEndpoint)
|
||||||
fmt.Fprintf(w, string(raw))
|
fmt.Fprint(w, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
roles, _, err := testClient.Role.GetList()
|
roles, _, err := testClient.Role.GetList()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %v", err)
|
||||||
|
}
|
||||||
if roles == nil {
|
if roles == nil {
|
||||||
t.Error("Expected role list. Role list is nil")
|
t.Error("Expected role list. Role list is nil")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if len(*roles) != 2 {
|
if len(*roles) != 2 {
|
||||||
t.Errorf("Expected %d roles but got %d", 2, len(*roles))
|
t.Errorf("Expected %d roles but got %d", 2, len(*roles))
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error given: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRoleService_Get_NoRole(t *testing.T) {
|
func TestRoleService_Get_NoRole(t *testing.T) {
|
||||||
@ -70,7 +71,7 @@ func TestRoleService_Get_NoRole(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
testMethod(t, request, "GET")
|
testMethod(t, request, "GET")
|
||||||
testRequestURL(t, request, testAPIEdpoint)
|
testRequestURL(t, request, testAPIEdpoint)
|
||||||
fmt.Fprintf(writer, string(raw))
|
fmt.Fprint(writer, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
role, _, err := testClient.Role.Get(99999)
|
role, _, err := testClient.Role.Get(99999)
|
||||||
@ -93,7 +94,7 @@ func TestRoleService_Get(t *testing.T) {
|
|||||||
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
testMethod(t, request, "GET")
|
testMethod(t, request, "GET")
|
||||||
testRequestURL(t, request, testAPIEdpoint)
|
testRequestURL(t, request, testAPIEdpoint)
|
||||||
fmt.Fprintf(writer, string(raw))
|
fmt.Fprint(writer, string(raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
role, _, err := testClient.Role.Get(10002)
|
role, _, err := testClient.Role.Get(10002)
|
||||||
|
@ -80,8 +80,12 @@ func TestSprintService_GetIssue(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
issue, _, err := testClient.Sprint.GetIssue("10002", nil)
|
issue, _, err := testClient.Sprint.GetIssue("10002", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
if issue == nil {
|
if issue == nil {
|
||||||
t.Errorf("Expected issue. Issue is nil %v", err)
|
t.Errorf("Expected issue. Issue is nil %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(issue.Fields.Labels, []string{"test"}) {
|
if !reflect.DeepEqual(issue.Fields.Labels, []string{"test"}) {
|
||||||
t.Error("Expected labels for the returned issue")
|
t.Error("Expected labels for the returned issue")
|
||||||
@ -109,5 +113,4 @@ func TestSprintService_GetIssue(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error given: %s", err)
|
t.Errorf("Error given: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
4
user.go
4
user.go
@ -106,12 +106,12 @@ func (s *UserService) Create(user *User) (*User, *Response, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could not read the returned data")
|
e := fmt.Errorf("could not read the returned data")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(data, responseUser)
|
err = json.Unmarshal(data, responseUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could not unmarshall the data into struct")
|
e := fmt.Errorf("could not unmarshall the data into struct")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
return responseUser, resp, nil
|
return responseUser, resp, nil
|
||||||
|
@ -64,12 +64,12 @@ func (s *VersionService) Create(version *Version) (*Version, *Response, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could not read the returned data")
|
e := fmt.Errorf("could not read the returned data")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(data, responseVersion)
|
err = json.Unmarshal(data, responseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Could not unmarshall the data into struct")
|
e := fmt.Errorf("could not unmarshall the data into struct")
|
||||||
return nil, resp, NewJiraError(resp, e)
|
return nil, resp, NewJiraError(resp, e)
|
||||||
}
|
}
|
||||||
return responseVersion, resp, nil
|
return responseVersion, resp, nil
|
||||||
|
Reference in New Issue
Block a user