2014-10-01 02:49:13 +04:00
|
|
|
package flags
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-10-02 00:12:24 +04:00
|
|
|
func TestValidateURLsValueBad(t *testing.T) {
|
2014-10-01 02:49:13 +04:00
|
|
|
tests := []string{
|
|
|
|
// bad IP specification
|
|
|
|
":4001",
|
|
|
|
"127.0:8080",
|
|
|
|
"123:456",
|
|
|
|
// bad port specification
|
|
|
|
"127.0.0.1:foo",
|
|
|
|
"127.0.0.1:",
|
|
|
|
// unix sockets not supported
|
|
|
|
"unix://",
|
|
|
|
"unix://tmp/etcd.sock",
|
|
|
|
// bad strings
|
|
|
|
"somewhere",
|
|
|
|
"234#$",
|
|
|
|
"file://foo/bar",
|
|
|
|
"http://hello/asdf",
|
2014-10-01 22:38:04 +04:00
|
|
|
"http://10.1.1.1",
|
2014-10-01 02:49:13 +04:00
|
|
|
}
|
|
|
|
for i, in := range tests {
|
2014-10-02 00:12:24 +04:00
|
|
|
u := URLsValue{}
|
2014-10-01 02:49:13 +04:00
|
|
|
if err := u.Set(in); err == nil {
|
|
|
|
t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 00:12:24 +04:00
|
|
|
func TestValidateURLsValueGood(t *testing.T) {
|
2014-10-01 02:49:13 +04:00
|
|
|
tests := []string{
|
|
|
|
"https://1.2.3.4:8080",
|
|
|
|
"http://10.1.1.1:80",
|
2014-10-01 22:38:04 +04:00
|
|
|
"http://localhost:80",
|
|
|
|
"http://:80",
|
2014-10-01 02:49:13 +04:00
|
|
|
}
|
|
|
|
for i, in := range tests {
|
2014-10-02 00:12:24 +04:00
|
|
|
u := URLsValue{}
|
2014-10-01 02:49:13 +04:00
|
|
|
if err := u.Set(in); err != nil {
|
|
|
|
t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|