30 lines
761 B
Go
30 lines
761 B
Go
package registry
|
|
|
|
import "testing"
|
|
|
|
func TestValidatePublicURL(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
url string
|
|
wantErr bool
|
|
}{
|
|
{"valid https", "https://crm.example.com", false},
|
|
{"valid http", "http://192.168.1.5:8080", false},
|
|
{"malformed", "://not-a-url", true},
|
|
{"no scheme", "example.com", true},
|
|
{"non-http(s) scheme", "ftp://example.com", true},
|
|
{"host-only garbage", "not a url at all", true},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := validatePublicURL(tc.url)
|
|
if tc.wantErr && err == nil {
|
|
t.Errorf("validatePublicURL(%q) = nil, want error", tc.url)
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Errorf("validatePublicURL(%q) = %v, want nil", tc.url, err)
|
|
}
|
|
})
|
|
}
|
|
}
|