github.com/kobeld/docker@v1.12.0-rc1/registry/config_test.go (about) 1 package registry 2 3 import ( 4 "testing" 5 ) 6 7 func TestValidateMirror(t *testing.T) { 8 valid := []string{ 9 "http://mirror-1.com", 10 "https://mirror-1.com", 11 "http://localhost", 12 "https://localhost", 13 "http://localhost:5000", 14 "https://localhost:5000", 15 "http://127.0.0.1", 16 "https://127.0.0.1", 17 "http://127.0.0.1:5000", 18 "https://127.0.0.1:5000", 19 } 20 21 invalid := []string{ 22 "!invalid!://%as%", 23 "ftp://mirror-1.com", 24 "http://mirror-1.com/", 25 "http://mirror-1.com/?q=foo", 26 "http://mirror-1.com/v1/", 27 "http://mirror-1.com/v1/?q=foo", 28 "http://mirror-1.com/v1/?q=foo#frag", 29 "http://mirror-1.com?q=foo", 30 "https://mirror-1.com#frag", 31 "https://mirror-1.com/", 32 "https://mirror-1.com/#frag", 33 "https://mirror-1.com/v1/", 34 "https://mirror-1.com/v1/#", 35 "https://mirror-1.com?q", 36 } 37 38 for _, address := range valid { 39 if ret, err := ValidateMirror(address); err != nil || ret == "" { 40 t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) 41 } 42 } 43 44 for _, address := range invalid { 45 if ret, err := ValidateMirror(address); err == nil || ret != "" { 46 t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) 47 } 48 } 49 }