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

Updates tests and examples to work with proposed changes

This commit is contained in:
spmassot
2018-10-16 13:41:50 -04:00
parent c6f546da3a
commit 02a41efba4
8 changed files with 27 additions and 51 deletions

View File

@ -38,7 +38,7 @@ func setup() {
testServer = httptest.NewServer(testMux)
// jira client configured to use test server
testClient, _ = NewClient(nil, testServer.URL)
testClient, _ = NewClient(nil, testServer.URL, true)
}
// teardown closes the test HTTP server.
@ -59,7 +59,7 @@ func testRequestURL(t *testing.T, r *http.Request, want string) {
}
func TestNewClient_WrongUrl(t *testing.T) {
c, err := NewClient(nil, "://issues.apache.org/jira/")
c, err := NewClient(nil, "://issues.apache.org/jira/", true)
if err == nil {
t.Error("Expected an error. Got none")
@ -72,7 +72,7 @@ func TestNewClient_WrongUrl(t *testing.T) {
func TestNewClient_WithHttpClient(t *testing.T) {
httpClient := http.DefaultClient
httpClient.Timeout = 10 * time.Minute
c, err := NewClient(httpClient, testJIRAInstanceURL)
c, err := NewClient(httpClient, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("Got an error: %s", err)
@ -86,7 +86,7 @@ func TestNewClient_WithHttpClient(t *testing.T) {
}
func TestNewClient_WithServices(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("Got an error: %s", err)
@ -142,7 +142,7 @@ func TestCheckResponse(t *testing.T) {
}
func TestClient_NewRequest(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -164,7 +164,7 @@ func TestClient_NewRequest(t *testing.T) {
}
func TestClient_NewRawRequest(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -197,7 +197,7 @@ func testURLParseError(t *testing.T, err error) {
}
func TestClient_NewRequest_BadURL(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -206,7 +206,7 @@ func TestClient_NewRequest_BadURL(t *testing.T) {
}
func TestClient_NewRequest_SessionCookies(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -235,7 +235,7 @@ func TestClient_NewRequest_SessionCookies(t *testing.T) {
}
func TestClient_NewRequest_BasicAuth(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -261,7 +261,7 @@ func TestClient_NewRequest_BasicAuth(t *testing.T) {
// since there is no difference between an HTTP request body that is an empty string versus one that is not set at all.
// However in certain cases, intermediate systems may treat these differently resulting in subtle errors.
func TestClient_NewRequest_EmptyBody(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -275,7 +275,7 @@ func TestClient_NewRequest_EmptyBody(t *testing.T) {
}
func TestClient_NewMultiPartRequest(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -308,7 +308,7 @@ func TestClient_NewMultiPartRequest(t *testing.T) {
}
func TestClient_NewMultiPartRequest_BasicAuth(t *testing.T) {
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -427,7 +427,7 @@ func TestClient_GetBaseURL_WithURL(t *testing.T) {
t.Errorf("URL parsing -> Got an error: %s", err)
}
c, err := NewClient(nil, testJIRAInstanceURL)
c, err := NewClient(nil, testJIRAInstanceURL, true)
if err != nil {
t.Errorf("Client creation -> Got an error: %s", err)
}
@ -440,30 +440,6 @@ func TestClient_GetBaseURL_WithURL(t *testing.T) {
}
}
// REMOVED : This actually calls a live URL. It's not a unit test.
// I'm also not really sure what it's testing.
// func TestClient_Do_PagingInfoEmptyByDefault(t *testing.T) {
// c, _ := NewClient(nil, testJIRAInstanceURL)
// req, _ := c.NewRequest("GET", "/", nil)
// t.Errorf("%v\n", req)
// type foo struct {
// A string
// }
// body := new(foo)
// resp, _ := c.Do(req, body)
// if resp.StartAt != 0 {
// t.Errorf("StartAt not equal to 0")
// }
// if resp.MaxResults != 0 {
// t.Errorf("StartAt not equal to 0")
// }
// if resp.Total != 0 {
// t.Errorf("StartAt not equal to 0")
// }
// }
func TestBasicAuthTransport(t *testing.T) {
setup()
defer teardown()
@ -488,7 +464,7 @@ func TestBasicAuthTransport(t *testing.T) {
Password: password,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, true)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -539,7 +515,7 @@ func TestCookieAuthTransport_SessionObject_Exists(t *testing.T) {
SessionObject: []*http.Cookie{testCookie},
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, true)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -575,7 +551,7 @@ func TestCookieAuthTransport_SessionObject_ExistsWithEmptyCookie(t *testing.T) {
SessionObject: []*http.Cookie{emptyCookie, testCookie},
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, true)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -616,7 +592,7 @@ func TestCookieAuthTransport_SessionObject_DoesNotExist(t *testing.T) {
AuthURL: ts.URL,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, true)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}