mirror of https://github.com/docker/cli.git
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>
This commit is contained in:
parent
881833232e
commit
63d756f347
|
@ -63,7 +63,7 @@ func ParseHost(defaultToTLS bool, val string) (string, error) {
|
||||||
// parseDockerDaemonHost parses the specified address and returns an address that will be used as the host.
|
// parseDockerDaemonHost parses the specified address and returns an address that will be used as the host.
|
||||||
// Depending of the address specified, this may return one of the global Default* strings defined in hosts.go.
|
// Depending of the address specified, this may return one of the global Default* strings defined in hosts.go.
|
||||||
func parseDockerDaemonHost(addr string) (string, error) {
|
func parseDockerDaemonHost(addr string) (string, error) {
|
||||||
addrParts := strings.Split(addr, "://")
|
addrParts := strings.SplitN(addr, "://", 2)
|
||||||
if len(addrParts) == 1 && addrParts[0] != "" {
|
if len(addrParts) == 1 && addrParts[0] != "" {
|
||||||
addrParts = []string{"tcp", addrParts[0]}
|
addrParts = []string{"tcp", addrParts[0]}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,10 @@ import (
|
||||||
|
|
||||||
func TestParseHost(t *testing.T) {
|
func TestParseHost(t *testing.T) {
|
||||||
invalid := []string{
|
invalid := []string{
|
||||||
"anything",
|
|
||||||
"something with spaces",
|
"something with spaces",
|
||||||
"://",
|
"://",
|
||||||
"unknown://",
|
"unknown://",
|
||||||
"tcp://:port",
|
"tcp://:port",
|
||||||
"tcp://invalid",
|
|
||||||
"tcp://invalid:port",
|
"tcp://invalid:port",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,16 +51,13 @@ func TestParseHost(t *testing.T) {
|
||||||
|
|
||||||
func TestParseDockerDaemonHost(t *testing.T) {
|
func TestParseDockerDaemonHost(t *testing.T) {
|
||||||
invalids := map[string]string{
|
invalids := map[string]string{
|
||||||
"0.0.0.0": "Invalid bind address format: 0.0.0.0",
|
|
||||||
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
||||||
"tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path",
|
"tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path",
|
||||||
"udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1",
|
"udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1",
|
||||||
"udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375",
|
"udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375",
|
||||||
"tcp://unix:///run/docker.sock": "Invalid bind address format: unix",
|
"tcp://unix:///run/docker.sock": "Invalid proto, expected tcp: unix:///run/docker.sock",
|
||||||
" tcp://:7777/path ": "Invalid bind address format: tcp://:7777/path ",
|
" tcp://:7777/path ": "Invalid bind address format: tcp://:7777/path ",
|
||||||
"tcp": "Invalid bind address format: tcp",
|
|
||||||
"unix": "Invalid bind address format: unix",
|
|
||||||
"fd": "Invalid bind address format: fd",
|
|
||||||
"": "Invalid bind address format: ",
|
"": "Invalid bind address format: ",
|
||||||
}
|
}
|
||||||
valids := map[string]string{
|
valids := map[string]string{
|
||||||
|
@ -88,7 +83,7 @@ func TestParseDockerDaemonHost(t *testing.T) {
|
||||||
}
|
}
|
||||||
for invalidAddr, expectedError := range invalids {
|
for invalidAddr, expectedError := range invalids {
|
||||||
if addr, err := parseDockerDaemonHost(invalidAddr); err == nil || err.Error() != expectedError {
|
if addr, err := parseDockerDaemonHost(invalidAddr); err == nil || err.Error() != expectedError {
|
||||||
t.Errorf("tcp %v address expected error %v return, got %s and addr %v", invalidAddr, expectedError, err, addr)
|
t.Errorf("tcp %v address expected error %q return, got %q and addr %v", invalidAddr, expectedError, err, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for validAddr, expectedAddr := range valids {
|
for validAddr, expectedAddr := range valids {
|
||||||
|
@ -103,7 +98,6 @@ func TestParseTCP(t *testing.T) {
|
||||||
defaultHTTPHost = "tcp://127.0.0.1:2376"
|
defaultHTTPHost = "tcp://127.0.0.1:2376"
|
||||||
)
|
)
|
||||||
invalids := map[string]string{
|
invalids := map[string]string{
|
||||||
"0.0.0.0": "Invalid bind address format: 0.0.0.0",
|
|
||||||
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
||||||
"tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path",
|
"tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path",
|
||||||
"udp://127.0.0.1": "Invalid proto, expected tcp: udp://127.0.0.1",
|
"udp://127.0.0.1": "Invalid proto, expected tcp: udp://127.0.0.1",
|
||||||
|
|
Loading…
Reference in New Issue