mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-23 00:07:40 +02:00
Updated test to use already built testClient. Fixed jira error functions to receive jira.Response instead of http.Response
This commit is contained in:
3
error.go
3
error.go
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -19,7 +18,7 @@ type Error struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewJiraError creates a new jira Error
|
// NewJiraError creates a new jira Error
|
||||||
func NewJiraError(resp *http.Response, httpError error) error {
|
func NewJiraError(resp *Response, httpError error) error {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,27 +2,31 @@ package jira
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestError_NewJiraError(t *testing.T) {
|
func TestError_NewJiraError(t *testing.T) {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
setup()
|
||||||
io.WriteString(w, `{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}`)
|
defer teardown()
|
||||||
}
|
|
||||||
|
|
||||||
req := httptest.NewRequest("GET", "http://example.com/foo", nil)
|
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w := httptest.NewRecorder()
|
fmt.Fprint(w, `{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}`)
|
||||||
handler(w, req)
|
})
|
||||||
resp := w.Result()
|
|
||||||
|
req, _ := testClient.NewRequest("GET", "/", nil)
|
||||||
|
resp, _ := testClient.Do(req, nil)
|
||||||
|
|
||||||
err := NewJiraError(resp, errors.New("Original http error"))
|
err := NewJiraError(resp, errors.New("Original http error"))
|
||||||
if err, ok := err.(*Error); !ok {
|
if err, ok := err.(*Error); !ok {
|
||||||
t.Errorf("Expected jira Error. Got %s", err.Error())
|
t.Errorf("Expected jira Error. Got %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Issue does not exist") {
|
||||||
|
t.Errorf("Expected issue message. Got: %s", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestError_NilOriginalMessage(t *testing.T) {
|
func TestError_NilOriginalMessage(t *testing.T) {
|
||||||
|
2
issue.go
2
issue.go
@ -363,7 +363,7 @@ func (s *IssueService) Get(issueID string) (*Issue, *Response, error) {
|
|||||||
issue := new(Issue)
|
issue := new(Issue)
|
||||||
resp, err := s.client.Do(req, issue)
|
resp, err := s.client.Do(req, issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jerr := NewJiraError(resp.Response, err)
|
jerr := NewJiraError(resp, err)
|
||||||
return nil, resp, jerr
|
return nil, resp, jerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user