Skip to content

Commit 36e1ac9

Browse files
committed
chore: fix dsn test
1 parent 3505e7a commit 36e1ac9

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

uptrace/dsn.go

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ func ParseDSN(dsnStr string) (*DSN, error) {
7676
if dsn.Host == "api.uptrace.dev" {
7777
dsn.Host = "uptrace.dev"
7878
}
79+
if dsn.HTTPPort == "" {
80+
switch dsn.Scheme {
81+
case "http":
82+
dsn.HTTPPort = "80"
83+
case "https":
84+
dsn.HTTPPort = "443"
85+
}
86+
}
7987

8088
query := u.Query()
8189
if grpc := query.Get("grpc"); grpc != "" {

uptrace/dsn_test.go

+32-7
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,61 @@ import (
1212
func TestParseDSN(t *testing.T) {
1313
type Test struct {
1414
dsn string
15-
otlp string
15+
grpc string
16+
http string
1617
siteURL string
1718
}
1819

1920
tests := []Test{
20-
{"https://token@uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
21-
{"https://token@api.uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
21+
{
22+
"https://token@uptrace.dev/1",
23+
"otlp.uptrace.dev:4317",
24+
"otlp.uptrace.dev:443",
25+
"https://app.uptrace.dev",
26+
},
27+
{
28+
"https://token@api.uptrace.dev/1",
29+
"otlp.uptrace.dev:4317",
30+
"otlp.uptrace.dev:443",
31+
"https://app.uptrace.dev",
32+
},
2233
{
2334
"https://token@demo.uptrace.dev/1?grpc=4317",
2435
"demo.uptrace.dev:4317",
25-
"https://demo.uptrace.dev",
36+
"demo.uptrace.dev:443",
37+
"https://demo.uptrace.dev:443",
38+
},
39+
{
40+
"https://token@localhost:1234/1",
41+
"localhost:1234",
42+
"localhost:1234",
43+
"https://localhost:1234",
44+
},
45+
{
46+
"http://token@localhost:14317/project_id",
47+
"localhost:14317",
48+
"localhost:14318",
49+
"http://localhost:14318",
2650
},
27-
{"https://token@localhost:1234/1", "localhost:1234", "https://localhost:1234"},
28-
{"http://token@localhost:14317/project_id", "localhost:14317", "http://localhost:14318"},
2951
{
3052
"https://AQDan_E_EPe3QAF9fMP0PiVr5UWOu4q5@demo-api.uptrace.dev:4317/1",
3153
"demo-api.uptrace.dev:4317",
54+
"demo-api.uptrace.dev:4317",
3255
"https://demo-api.uptrace.dev:4317",
3356
},
3457
{
3558
"http://Qcn7rcwWO_w0ePo7WmeUtw@localhost:14318?grpc=14317",
3659
"localhost:14317",
60+
"localhost:14318",
3761
"http://localhost:14318",
3862
},
3963
}
4064
for i, test := range tests {
4165
t.Run(fmt.Sprint(i), func(t *testing.T) {
4266
dsn, err := uptrace.ParseDSN(test.dsn)
4367
require.NoError(t, err)
44-
require.Equal(t, test.otlp, dsn.OTLPEndpoint())
68+
require.Equal(t, test.grpc, dsn.OTLPGrpcEndpoint())
69+
require.Equal(t, test.http, dsn.OTLPHttpEndpoint())
4570
require.Equal(t, test.siteURL, dsn.SiteURL())
4671
})
4772
}

0 commit comments

Comments
 (0)