github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/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 "http://mirror-1.com/", 11 "https://mirror-1.com", 12 "https://mirror-1.com/", 13 "http://localhost", 14 "https://localhost", 15 "http://localhost:5000", 16 "https://localhost:5000", 17 "http://127.0.0.1", 18 "https://127.0.0.1", 19 "http://127.0.0.1:5000", 20 "https://127.0.0.1:5000", 21 } 22 23 invalid := []string{ 24 "!invalid!://%as%", 25 "ftp://mirror-1.com", 26 "http://mirror-1.com/?q=foo", 27 "http://mirror-1.com/v1/", 28 "http://mirror-1.com/v1/?q=foo", 29 "http://mirror-1.com/v1/?q=foo#frag", 30 "http://mirror-1.com?q=foo", 31 "https://mirror-1.com#frag", 32 "https://mirror-1.com/#frag", 33 "http://foo:bar@mirror-1.com/", 34 "https://mirror-1.com/v1/", 35 "https://mirror-1.com/v1/#", 36 "https://mirror-1.com?q", 37 } 38 39 for _, address := range valid { 40 if ret, err := ValidateMirror(address); err != nil || ret == "" { 41 t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) 42 } 43 } 44 45 for _, address := range invalid { 46 if ret, err := ValidateMirror(address); err == nil || ret != "" { 47 t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) 48 } 49 } 50 }