Merge pull request #509 from runatlantis/bb-server-basepath

Support basepath for bitbucket server
This commit is contained in:
Luke Kysow
2019-03-01 09:17:13 -05:00
committed by GitHub
2 changed files with 55 additions and 3 deletions

View File

@@ -42,7 +42,6 @@ func NewClient(httpClient *http.Client, username string, password string, baseUR
if httpClient == nil {
httpClient = http.DefaultClient
}
// Remove the trailing '/' from the URL.
parsedURL, err := url.Parse(baseURL)
if err != nil {
return nil, errors.Wrapf(err, "parsing %s", baseURL)
@@ -50,12 +49,11 @@ func NewClient(httpClient *http.Client, username string, password string, baseUR
if parsedURL.Scheme == "" {
return nil, fmt.Errorf("must have 'http://' or 'https://' in base url %q", baseURL)
}
urlWithoutPath := fmt.Sprintf("%s://%s", parsedURL.Scheme, parsedURL.Host)
return &Client{
HTTPClient: httpClient,
Username: username,
Password: password,
BaseURL: urlWithoutPath,
BaseURL: strings.TrimRight(parsedURL.String(), "/"),
AtlantisURL: atlantisURL,
}, nil
}

View File

@@ -14,6 +14,60 @@ import (
. "github.com/runatlantis/atlantis/testing"
)
// Test that we include the base path in our base url.
func TestClient_BasePath(t *testing.T) {
cases := []struct {
inputURL string
expURL string
expErr string
}{
{
inputURL: "mycompany.com",
expErr: `must have 'http://' or 'https://' in base url "mycompany.com"`,
},
{
inputURL: "https://mycompany.com",
expURL: "https://mycompany.com",
},
{
inputURL: "http://mycompany.com",
expURL: "http://mycompany.com",
},
{
inputURL: "http://mycompany.com:7990",
expURL: "http://mycompany.com:7990",
},
{
inputURL: "http://mycompany.com/",
expURL: "http://mycompany.com",
},
{
inputURL: "http://mycompany.com:7990/",
expURL: "http://mycompany.com:7990",
},
{
inputURL: "http://mycompany.com/basepath/",
expURL: "http://mycompany.com/basepath",
},
{
inputURL: "http://mycompany.com:7990/basepath/",
expURL: "http://mycompany.com:7990/basepath",
},
}
for _, c := range cases {
t.Run(c.inputURL, func(t *testing.T) {
client, err := bitbucketserver.NewClient(nil, "u", "p", c.inputURL, "atlantis-url")
if c.expErr != "" {
ErrEquals(t, c.expErr, err)
} else {
Ok(t, err)
Equals(t, c.expURL, client.BaseURL)
}
})
}
}
// Should follow pagination properly.
func TestClient_GetModifiedFilesPagination(t *testing.T) {
respTemplate := `