Browse code

Fix opts tests after default port fix

The code for default port was already there but
it didn’t work because split function errored out
before. This should be the desired behavior that
matches daemon listen address with swarm listen
address.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/06/22 09:14:55
Showing 2 changed files
... ...
@@ -63,7 +63,7 @@ func ParseHost(defaultToTLS bool, val string) (string, error) {
63 63
 // parseDockerDaemonHost parses the specified address and returns an address that will be used as the host.
64 64
 // Depending of the address specified, this may return one of the global Default* strings defined in hosts.go.
65 65
 func parseDockerDaemonHost(addr string) (string, error) {
66
-	addrParts := strings.Split(addr, "://")
66
+	addrParts := strings.SplitN(addr, "://", 2)
67 67
 	if len(addrParts) == 1 && addrParts[0] != "" {
68 68
 		addrParts = []string{"tcp", addrParts[0]}
69 69
 	}
... ...
@@ -7,12 +7,10 @@ import (
7 7
 
8 8
 func TestParseHost(t *testing.T) {
9 9
 	invalid := []string{
10
-		"anything",
11 10
 		"something with spaces",
12 11
 		"://",
13 12
 		"unknown://",
14 13
 		"tcp://:port",
15
-		"tcp://invalid",
16 14
 		"tcp://invalid:port",
17 15
 	}
18 16
 
... ...
@@ -53,16 +51,13 @@ func TestParseHost(t *testing.T) {
53 53
 
54 54
 func TestParseDockerDaemonHost(t *testing.T) {
55 55
 	invalids := map[string]string{
56
-		"0.0.0.0":                       "Invalid bind address format: 0.0.0.0",
56
+
57 57
 		"tcp:a.b.c.d":                   "Invalid bind address format: tcp:a.b.c.d",
58 58
 		"tcp:a.b.c.d/path":              "Invalid bind address format: tcp:a.b.c.d/path",
59 59
 		"udp://127.0.0.1":               "Invalid bind address format: udp://127.0.0.1",
60 60
 		"udp://127.0.0.1:2375":          "Invalid bind address format: udp://127.0.0.1:2375",
61
-		"tcp://unix:///run/docker.sock": "Invalid bind address format: unix",
61
+		"tcp://unix:///run/docker.sock": "Invalid proto, expected tcp: unix:///run/docker.sock",
62 62
 		" tcp://:7777/path ":            "Invalid bind address format:  tcp://:7777/path ",
63
-		"tcp":                           "Invalid bind address format: tcp",
64
-		"unix":                          "Invalid bind address format: unix",
65
-		"fd":                            "Invalid bind address format: fd",
66 63
 		"":                              "Invalid bind address format: ",
67 64
 	}
68 65
 	valids := map[string]string{
... ...
@@ -88,7 +83,7 @@ func TestParseDockerDaemonHost(t *testing.T) {
88 88
 	}
89 89
 	for invalidAddr, expectedError := range invalids {
90 90
 		if addr, err := parseDockerDaemonHost(invalidAddr); err == nil || err.Error() != expectedError {
91
-			t.Errorf("tcp %v address expected error %v return, got %s and addr %v", invalidAddr, expectedError, err, addr)
91
+			t.Errorf("tcp %v address expected error %q return, got %q and addr %v", invalidAddr, expectedError, err, addr)
92 92
 		}
93 93
 	}
94 94
 	for validAddr, expectedAddr := range valids {
... ...
@@ -103,7 +98,6 @@ func TestParseTCP(t *testing.T) {
103 103
 		defaultHTTPHost = "tcp://127.0.0.1:2376"
104 104
 	)
105 105
 	invalids := map[string]string{
106
-		"0.0.0.0":              "Invalid bind address format: 0.0.0.0",
107 106
 		"tcp:a.b.c.d":          "Invalid bind address format: tcp:a.b.c.d",
108 107
 		"tcp:a.b.c.d/path":     "Invalid bind address format: tcp:a.b.c.d/path",
109 108
 		"udp://127.0.0.1":      "Invalid proto, expected tcp: udp://127.0.0.1",