From d855447c469935596dc5893ea7099db835606508 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 4 Sep 2022 15:35:18 +0200 Subject: [PATCH] linting: host:port in url should be constructed with net.JoinHostPort integration-cli/docker_cli_daemon_test.go:545:54: host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf (nosprintfhostport) cmdArgs = append(cmdArgs, "--tls=false", "--host", fmt.Sprintf("tcp://%s:%s", l.daemon, l.port)) ^ opts/hosts_test.go:35:31: host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf (nosprintfhostport) "tcp://:5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), ^ opts/hosts_test.go:91:30: host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf (nosprintfhostport) ":5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 306b8c89e8186bc88105a41a5d8acf6ae92dea08) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e9e7491f2b9d661a9227073aebda7fde5abfda95) Signed-off-by: Cory Snider --- integration-cli/docker_cli_daemon_test.go | 2 +- opts/hosts_test.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 74ce390257..ba8a245869 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -541,7 +541,7 @@ func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *testing.T) { cmdArgs := make([]string, 0, len(listeningPorts)*2) for _, l := range listeningPorts { - cmdArgs = append(cmdArgs, "--tls=false", "--host", fmt.Sprintf("tcp://%s:%s", l.daemon, l.port)) + cmdArgs = append(cmdArgs, "--tls=false", "--host", "tcp://"+net.JoinHostPort(l.daemon, l.port)) } s.d.StartWithBusybox(c, cmdArgs...) diff --git a/opts/hosts_test.go b/opts/hosts_test.go index 7a0a943adf..2e15b8fafe 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -23,13 +23,13 @@ func TestParseHost(t *testing.T) { "fd://something": "fd://something", "tcp://host:": fmt.Sprintf("tcp://host:%d", DefaultHTTPPort), "tcp://": DefaultTCPHost, - "tcp://:2375": fmt.Sprintf("tcp://%s:2375", DefaultHTTPHost), - "tcp://:2376": fmt.Sprintf("tcp://%s:2376", DefaultHTTPHost), + "tcp://:2375": fmt.Sprintf("tcp://%s:2375", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. + "tcp://:2376": fmt.Sprintf("tcp://%s:2376", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. "tcp://0.0.0.0:8080": "tcp://0.0.0.0:8080", "tcp://192.168.0.0:12000": "tcp://192.168.0.0:12000", "tcp://192.168:8080": "tcp://192.168:8080", - "tcp://0.0.0.0:1234567890": "tcp://0.0.0.0:1234567890", // yeah it's valid :P - " tcp://:7777/path ": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), + "tcp://0.0.0.0:1234567890": "tcp://0.0.0.0:1234567890", // yeah it's valid :P + " tcp://:7777/path ": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. "tcp://docker.com:2375": "tcp://docker.com:2375", "unix://": "unix://" + DefaultUnixSocket, "unix://path/to/socket": "unix://path/to/socket", @@ -69,11 +69,11 @@ func TestParseDockerDaemonHost(t *testing.T) { "[::1]:5555/path": "tcp://[::1]:5555/path", "[0:0:0:0:0:0:0:1]:": "tcp://[0:0:0:0:0:0:0:1]:2375", "[0:0:0:0:0:0:0:1]:5555/path": "tcp://[0:0:0:0:0:0:0:1]:5555/path", - ":6666": fmt.Sprintf("tcp://%s:6666", DefaultHTTPHost), - ":6666/path": fmt.Sprintf("tcp://%s:6666/path", DefaultHTTPHost), + ":6666": fmt.Sprintf("tcp://%s:6666", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. + ":6666/path": fmt.Sprintf("tcp://%s:6666/path", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. "tcp://": DefaultTCPHost, - "tcp://:7777": fmt.Sprintf("tcp://%s:7777", DefaultHTTPHost), - "tcp://:7777/path": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), + "tcp://:7777": fmt.Sprintf("tcp://%s:7777", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. + "tcp://:7777/path": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case. "unix:///run/docker.sock": "unix:///run/docker.sock", "unix://": "unix://" + DefaultUnixSocket, "fd://": "fd://",