Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for path prefixes in the DSN #102

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (dsn Dsn) StoreAPIURL() *url.URL {
if dsn.port != dsn.scheme.defaultPort() {
rawURL += fmt.Sprintf(":%d", dsn.port)
}
if dsn.path != "" {
rawURL += dsn.path
}
rawURL += fmt.Sprintf("/api/%d/store/", dsn.projectID)
parsedURL, _ := url.Parse(rawURL)
return parsedURL
Expand Down
10 changes: 10 additions & 0 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func TestValidDsnNoPort(t *testing.T) {
assertEqual(t, "http://domain/api/42/store/", dsn.StoreAPIURL().String())
}

func TestValidDsnPrefixed(t *testing.T) {
url := "http://username@domain/prefixed/42"
dsn, err := NewDsn(url)

if err != nil {
t.Error("expected dsn to be correctly created")
}
assertEqual(t, "http://domain/prefixed/api/42/store/", dsn.StoreAPIURL().String())
}

func TestValidDsnInsecureNoPort(t *testing.T) {
url := "https://username@domain/42"
dsn, err := NewDsn(url)
Expand Down