1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package flags
16
17 import (
18 "net/url"
19 "reflect"
20 "testing"
21 )
22
23 func TestValidateURLsValueBad(t *testing.T) {
24 tests := []string{
25
26 ":2379",
27 "127.0:8080",
28 "123:456",
29
30 "127.0.0.1:foo",
31 "127.0.0.1:",
32
33 "somewhere",
34 "234#$",
35 "file://foo/bar",
36 "http://hello/asdf",
37 "http://10.1.1.1",
38 }
39 for i, in := range tests {
40 u := URLsValue{}
41 if err := u.Set(in); err == nil {
42 t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
43 }
44 }
45 }
46
47 func TestNewURLsValue(t *testing.T) {
48 tests := []struct {
49 s string
50 exp []url.URL
51 }{
52 {s: "https://1.2.3.4:8080", exp: []url.URL{{Scheme: "https", Host: "1.2.3.4:8080"}}},
53 {s: "http://10.1.1.1:80", exp: []url.URL{{Scheme: "http", Host: "10.1.1.1:80"}}},
54 {s: "http://localhost:80", exp: []url.URL{{Scheme: "http", Host: "localhost:80"}}},
55 {s: "http://:80", exp: []url.URL{{Scheme: "http", Host: ":80"}}},
56 {s: "unix://tmp/etcd.sock", exp: []url.URL{{Scheme: "unix", Host: "tmp", Path: "/etcd.sock"}}},
57 {s: "unix:///tmp/127.27.84.4:23432", exp: []url.URL{{Scheme: "unix", Path: "/tmp/127.27.84.4:23432"}}},
58 {s: "unix://127.0.0.5:1456", exp: []url.URL{{Scheme: "unix", Host: "127.0.0.5:1456"}}},
59 {
60 s: "http://localhost:1,https://localhost:2",
61 exp: []url.URL{
62 {Scheme: "http", Host: "localhost:1"},
63 {Scheme: "https", Host: "localhost:2"},
64 },
65 },
66 }
67 for i := range tests {
68 uu := []url.URL(*NewURLsValue(tests[i].s))
69 if !reflect.DeepEqual(tests[i].exp, uu) {
70 t.Fatalf("#%d: expected %+v, got %+v", i, tests[i].exp, uu)
71 }
72 }
73 }
74
View as plain text