Skip to content

Commit

Permalink
chore: fix dsn test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed May 7, 2024
1 parent 3505e7a commit 36e1ac9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
8 changes: 8 additions & 0 deletions uptrace/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func ParseDSN(dsnStr string) (*DSN, error) {
if dsn.Host == "api.uptrace.dev" {
dsn.Host = "uptrace.dev"
}
if dsn.HTTPPort == "" {
switch dsn.Scheme {
case "http":
dsn.HTTPPort = "80"
case "https":
dsn.HTTPPort = "443"
}
}

query := u.Query()
if grpc := query.Get("grpc"); grpc != "" {
Expand Down
39 changes: 32 additions & 7 deletions uptrace/dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,61 @@ import (
func TestParseDSN(t *testing.T) {
type Test struct {
dsn string
otlp string
grpc string
http string
siteURL string
}

tests := []Test{
{"https://[email protected]/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
{"https://[email protected]/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
{
"https://[email protected]/1",
"otlp.uptrace.dev:4317",
"otlp.uptrace.dev:443",
"https://app.uptrace.dev",
},
{
"https://[email protected]/1",
"otlp.uptrace.dev:4317",
"otlp.uptrace.dev:443",
"https://app.uptrace.dev",
},
{
"https://[email protected]/1?grpc=4317",
"demo.uptrace.dev:4317",
"https://demo.uptrace.dev",
"demo.uptrace.dev:443",
"https://demo.uptrace.dev:443",
},
{
"https://token@localhost:1234/1",
"localhost:1234",
"localhost:1234",
"https://localhost:1234",
},
{
"http://token@localhost:14317/project_id",
"localhost:14317",
"localhost:14318",
"http://localhost:14318",
},
{"https://token@localhost:1234/1", "localhost:1234", "https://localhost:1234"},
{"http://token@localhost:14317/project_id", "localhost:14317", "http://localhost:14318"},
{
"https://[email protected]:4317/1",
"demo-api.uptrace.dev:4317",
"demo-api.uptrace.dev:4317",
"https://demo-api.uptrace.dev:4317",
},
{
"http://Qcn7rcwWO_w0ePo7WmeUtw@localhost:14318?grpc=14317",
"localhost:14317",
"localhost:14318",
"http://localhost:14318",
},
}
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
dsn, err := uptrace.ParseDSN(test.dsn)
require.NoError(t, err)
require.Equal(t, test.otlp, dsn.OTLPEndpoint())
require.Equal(t, test.grpc, dsn.OTLPGrpcEndpoint())
require.Equal(t, test.http, dsn.OTLPHttpEndpoint())
require.Equal(t, test.siteURL, dsn.SiteURL())
})
}
Expand Down

0 comments on commit 36e1ac9

Please sign in to comment.