2014-10-06 21:54:52 -04:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateMirror(t *testing.T) {
|
|
|
|
valid := []string{
|
|
|
|
"http://mirror-1.com",
|
2016-12-21 05:31:05 -05:00
|
|
|
"http://mirror-1.com/",
|
2014-10-06 21:54:52 -04:00
|
|
|
"https://mirror-1.com",
|
2016-12-21 05:31:05 -05:00
|
|
|
"https://mirror-1.com/",
|
2014-10-06 21:54:52 -04:00
|
|
|
"http://localhost",
|
|
|
|
"https://localhost",
|
|
|
|
"http://localhost:5000",
|
|
|
|
"https://localhost:5000",
|
|
|
|
"http://127.0.0.1",
|
|
|
|
"https://127.0.0.1",
|
|
|
|
"http://127.0.0.1:5000",
|
|
|
|
"https://127.0.0.1:5000",
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid := []string{
|
|
|
|
"!invalid!://%as%",
|
|
|
|
"ftp://mirror-1.com",
|
|
|
|
"http://mirror-1.com/?q=foo",
|
|
|
|
"http://mirror-1.com/v1/",
|
|
|
|
"http://mirror-1.com/v1/?q=foo",
|
|
|
|
"http://mirror-1.com/v1/?q=foo#frag",
|
|
|
|
"http://mirror-1.com?q=foo",
|
|
|
|
"https://mirror-1.com#frag",
|
|
|
|
"https://mirror-1.com/#frag",
|
2016-12-21 05:31:05 -05:00
|
|
|
"http://foo:bar@mirror-1.com/",
|
2014-10-06 21:54:52 -04:00
|
|
|
"https://mirror-1.com/v1/",
|
|
|
|
"https://mirror-1.com/v1/#",
|
|
|
|
"https://mirror-1.com?q",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, address := range valid {
|
|
|
|
if ret, err := ValidateMirror(address); err != nil || ret == "" {
|
|
|
|
t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, address := range invalid {
|
|
|
|
if ret, err := ValidateMirror(address); err == nil || ret != "" {
|
|
|
|
t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|