mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-14 23:45:03 +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:
@ -2,27 +2,31 @@ package jira
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestError_NewJiraError(t *testing.T) {
|
||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, `{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}`)
|
||||
}
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
req := httptest.NewRequest("GET", "http://example.com/foo", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler(w, req)
|
||||
resp := w.Result()
|
||||
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}`)
|
||||
})
|
||||
|
||||
req, _ := testClient.NewRequest("GET", "/", nil)
|
||||
resp, _ := testClient.Do(req, nil)
|
||||
|
||||
err := NewJiraError(resp, errors.New("Original http error"))
|
||||
if err, ok := err.(*Error); !ok {
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user