MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestNormalizeExternalURL

Function TestNormalizeExternalURL

backend/common/util_test.go:164–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestNormalizeExternalURL(t *testing.T) {
165 tests := []struct {
166 url string
167 want string
168 wantErr bool
169 }{
170 {
171 url: "http://localhost:3000",
172 want: "http://localhost:3000",
173 wantErr: false,
174 },
175 {
176 url: "https://localhost:3000",
177 want: "https://localhost:3000",
178 wantErr: false,
179 },
180 {
181 url: "https://localhost",
182 want: "https://localhost",
183 wantErr: false,
184 },
185 {
186 url: "http://localhost:80",
187 want: "http://localhost",
188 wantErr: false,
189 },
190 {
191 url: "https://localhost:443",
192 want: "https://localhost",
193 wantErr: false,
194 },
195 {
196 url: " https://localhost:3000/ ",
197 want: "https://localhost:3000",
198 wantErr: false,
199 },
200 // Missing http:// or https://
201 {
202 url: "localhost:3000",
203 want: "",
204 wantErr: true,
205 },
206 // Invalid port
207 {
208 url: "http://localhost:xxx",
209 want: "",
210 wantErr: true,
211 },
212 }
213 for _, tt := range tests {
214 t.Run(tt.url, func(t *testing.T) {
215 g, err := NormalizeExternalURL(tt.url)
216 if err != nil {
217 if !tt.wantErr {
218 t.Errorf("expect no error, got %s", err.Error())
219 }
220 } else {
221 if tt.wantErr {

Callers

nothing calls this directly

Calls 4

NormalizeExternalURLFunction · 0.85
ErrorfMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected