1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-04 15:35:18 +02:00
parent 31fb92c609
commit 306b8c89e8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 3 additions and 3 deletions

View file

@ -542,7 +542,7 @@ func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *testing.T) {
cmdArgs := make([]string, 0, len(listeningPorts)*2) cmdArgs := make([]string, 0, len(listeningPorts)*2)
for _, l := range listeningPorts { 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...) s.d.StartWithBusybox(c, cmdArgs...)

View file

@ -32,7 +32,7 @@ func TestParseHost(t *testing.T) {
"tcp://host:": fmt.Sprintf("tcp://host:%d", DefaultHTTPPort), "tcp://host:": fmt.Sprintf("tcp://host:%d", DefaultHTTPPort),
"tcp://": DefaultTCPHost, "tcp://": DefaultTCPHost,
"tcp://:": DefaultTCPHost, "tcp://:": DefaultTCPHost,
"tcp://:5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), "tcp://:5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case.
"tcp://[::1]": fmt.Sprintf(`tcp://[::1]:%d`, DefaultHTTPPort), "tcp://[::1]": fmt.Sprintf(`tcp://[::1]:%d`, DefaultHTTPPort),
"tcp://[::1]:": fmt.Sprintf(`tcp://[::1]:%d`, DefaultHTTPPort), "tcp://[::1]:": fmt.Sprintf(`tcp://[::1]:%d`, DefaultHTTPPort),
"tcp://[::1]:5555": `tcp://[::1]:5555`, "tcp://[::1]:5555": `tcp://[::1]:5555`,
@ -88,7 +88,7 @@ func TestParseDockerDaemonHost(t *testing.T) {
} }
valids := map[string]string{ valids := map[string]string{
":": DefaultTCPHost, ":": DefaultTCPHost,
":5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), ":5555": fmt.Sprintf("tcp://%s:5555", DefaultHTTPHost), //nolint:nosprintfhostport // sprintf is more readable for this case.
"0.0.0.1:": fmt.Sprintf("tcp://0.0.0.1:%d", DefaultHTTPPort), "0.0.0.1:": fmt.Sprintf("tcp://0.0.0.1:%d", DefaultHTTPPort),
"0.0.0.1:5555": "tcp://0.0.0.1:5555", "0.0.0.1:5555": "tcp://0.0.0.1:5555",
"[::1]": fmt.Sprintf("tcp://[::1]:%d", DefaultHTTPPort), "[::1]": fmt.Sprintf("tcp://[::1]:%d", DefaultHTTPPort),