Debian Codegraph @

pkg/util/url_test.go

raw symbols SCIP
1 package utilscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/
2
3 import (
4 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
5 "testingscip-go gomod github.com/golang/go/src . testing/"
6
7 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/"
8 )
9
10 func TestURLUserPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/TestURLUserPassword().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
11 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
12
13 tests := []struct {
14 name string
15 user string
16 password string
17 wantUsername string
18 wantPassword string
19 wantNil bool
20 }{
21 {
22 name: "returns user with password when both provided",
23 user: "admin",
24 password: "secret",
25 wantUsername: "admin",
26 wantPassword: "secret",
27 wantNil: false,
28 },
29 {
30 name: "returns user without password when only user provided",
31 user: "admin",
32 password: "",
33 wantUsername: "admin",
34 wantPassword: "",
35 wantNil: false,
36 },
37 {
38 name: "returns nil when neither user nor password provided",
39 user: "",
40 password: "",
41 wantUsername: "",
42 wantPassword: "",
43 wantNil: true,
44 },
45 {
46 name: "returns user with password when user is empty but password is provided",
47 user: "",
48 password: "secret",
49 wantUsername: "",
50 wantPassword: "secret",
51 wantNil: false,
52 },
53 {
54 name: "handles special characters in credentials",
55 user: "[email protected]",
56 password: "p@ssw0rd!#$%",
57 wantUsername: "[email protected]",
58 wantPassword: "p@ssw0rd!#$%",
59 wantNil: false,
60 },
61 {
62 name: "handles unicode characters",
63 user: "用户",
64 password: "密码",
65 wantUsername: "用户",
66 wantPassword: "密码",
67 wantNil: false,
68 },
69 {
70 name: "handles very long credentials",
71 user: "averylongusernamethatcouldbeused",
72 password: "anextremelylongpasswordthatnobodyshouldusebutwestilltest",
73 wantUsername: "averylongusernamethatcouldbeused",
74 wantPassword: "anextremelylongpasswordthatnobodyshouldusebutwestilltest",
75 wantNil: false,
76 },
77 }
78
79 for _, tt := range tests {
80 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
81 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
82
83 got := URLUserPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/URLUserPassword().(tt.user, tt.password)
84
85 if tt.wantNil {
86 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, got, "URLUserPassword(%q, %q) should return nil", tt.user, tt.password)
87 } else {
88 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, got, "URLUserPassword(%q, %q) should not return nil", tt.user, tt.password)
89 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantUsername, got.Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().(), "Username mismatch")
90 gotPassword, _ := got.Passwordscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Password().()
91 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantPassword, gotPassword, "Password mismatch")
92 }
93 })
94 }
95 }
96
97 func TestURLUserPassword_Integrationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/TestURLUserPassword_Integration().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
98 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
99
100 // Verify the returned Userinfo works correctly with url.URL
101 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().("works with url.URL", func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
102 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
103
104 userinfo := URLUserPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/URLUserPassword().("admin", "secret")
105 testURL := &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{
106 Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: "https",
107 Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: "example.com",
108 Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: userinfo,
109 Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: "/path",
110 }
111
112 expected := "https://admin:[email protected]/path"
113 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expected, testURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().(), "URL with userinfo should serialize correctly")
114 })
115
116 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().("nil userinfo serializes to empty string", func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
117 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
118
119 userinfo := URLUserPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util`/URLUserPassword().("", "")
120 testURL := &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{
121 Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: "https",
122 Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: "example.com",
123 Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: userinfo,
124 Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: "/path",
125 }
126
127 expected := "https://example.com/path"
128 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expected, testURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().(), "URL with nil userinfo should not include @")
129 })
130 }