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)
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...)

View File

@ -32,7 +32,7 @@ func TestParseHost(t *testing.T) {
"tcp://host:": fmt.Sprintf("tcp://host:%d", DefaultHTTPPort),
"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]:5555": `tcp://[::1]:5555`,
@ -88,7 +88,7 @@ func TestParseDockerDaemonHost(t *testing.T) {
}
valids := map[string]string{
":": 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:5555": "tcp://0.0.0.1:5555",
"[::1]": fmt.Sprintf("tcp://[::1]:%d", DefaultHTTPPort),