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

Instead of baking config into the client, adds a method call that allows options to be passed in

This commit is contained in:
spmassot
2018-10-17 15:17:08 -04:00
parent 00a32a0fd7
commit 9049c9ff74
10 changed files with 62 additions and 104 deletions

View File

@ -38,10 +38,7 @@ func setup() {
testServer = httptest.NewServer(testMux)
// jira client configured to use test server
config = ServiceConfig{
Notify: true,
}
testClient, _ = NewClient(nil, testServer.URL, config)
testClient, _ = NewClient(nil, testServer.URL)
}
// teardown closes the test HTTP server.
@ -62,10 +59,7 @@ func testRequestURL(t *testing.T, r *http.Request, want string) {
}
func TestNewClient_WrongUrl(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, "://issues.apache.org/jira/", config)
c, err := NewClient(nil, "://issues.apache.org/jira/")
if err == nil {
t.Error("Expected an error. Got none")
@ -78,10 +72,7 @@ func TestNewClient_WrongUrl(t *testing.T) {
func TestNewClient_WithHttpClient(t *testing.T) {
httpClient := http.DefaultClient
httpClient.Timeout = 10 * time.Minute
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(httpClient, testJIRAInstanceURL, config)
c, err := NewClient(httpClient, testJIRAInstanceURL)
if err != nil {
t.Errorf("Got an error: %s", err)
@ -95,10 +86,7 @@ func TestNewClient_WithHttpClient(t *testing.T) {
}
func TestNewClient_WithServices(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("Got an error: %s", err)
@ -154,10 +142,7 @@ func TestCheckResponse(t *testing.T) {
}
func TestClient_NewRequest(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -179,10 +164,7 @@ func TestClient_NewRequest(t *testing.T) {
}
func TestClient_NewRawRequest(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -215,10 +197,7 @@ func testURLParseError(t *testing.T, err error) {
}
func TestClient_NewRequest_BadURL(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -227,10 +206,7 @@ func TestClient_NewRequest_BadURL(t *testing.T) {
}
func TestClient_NewRequest_SessionCookies(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -259,10 +235,7 @@ func TestClient_NewRequest_SessionCookies(t *testing.T) {
}
func TestClient_NewRequest_BasicAuth(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -288,10 +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) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -305,10 +275,7 @@ func TestClient_NewRequest_EmptyBody(t *testing.T) {
}
func TestClient_NewMultiPartRequest(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -341,10 +308,7 @@ func TestClient_NewMultiPartRequest(t *testing.T) {
}
func TestClient_NewMultiPartRequest_BasicAuth(t *testing.T) {
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
}
@ -463,10 +427,7 @@ func TestClient_GetBaseURL_WithURL(t *testing.T) {
t.Errorf("URL parsing -> Got an error: %s", err)
}
config = ServiceConfig{
Notify: true,
}
c, err := NewClient(nil, testJIRAInstanceURL, config)
c, err := NewClient(nil, testJIRAInstanceURL)
if err != nil {
t.Errorf("Client creation -> Got an error: %s", err)
}
@ -503,10 +464,7 @@ func TestBasicAuthTransport(t *testing.T) {
Password: password,
}
config = ServiceConfig{
Notify: true,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, config)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -557,10 +515,7 @@ func TestCookieAuthTransport_SessionObject_Exists(t *testing.T) {
SessionObject: []*http.Cookie{testCookie},
}
config = ServiceConfig{
Notify: true,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, config)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -596,10 +551,7 @@ func TestCookieAuthTransport_SessionObject_ExistsWithEmptyCookie(t *testing.T) {
SessionObject: []*http.Cookie{emptyCookie, testCookie},
}
config = ServiceConfig{
Notify: true,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, config)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}
@ -640,10 +592,7 @@ func TestCookieAuthTransport_SessionObject_DoesNotExist(t *testing.T) {
AuthURL: ts.URL,
}
config = ServiceConfig{
Notify: true,
}
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL, config)
basicAuthClient, _ := NewClient(tp.Client(), testServer.URL)
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
basicAuthClient.Do(req, nil)
}