fix linting issues

Some false positives from gosec (G602: slice index out of range)

    integration-cli/daemon/daemon.go:109:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic)
    // Deprecated: use cli.WaitCmd instead
    ^
    integration-cli/docker_cli_build_test.go:562:3: dupOption: function argument `build.WithFile("test_file3", "test3")` is duplicated (gocritic)
            build.WithFile("test_file3", "test3"),
            ^
    integration-cli/docker_utils_test.go:250:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic)
    // Deprecated: use cli.WaitFor
    ^
    daemon/libnetwork/ipams/defaultipam/address_space.go:45:39: G602: slice index out of range (gosec)
            if predefined[j].Overlaps(predefined[i].Base) {
                                                ^
    daemon/libnetwork/ipams/defaultipam/address_space.go:49:29: G602: slice index out of range (gosec)
            predefined[j] = predefined[i]
                                      ^
    daemon/libnetwork/libnetwork_linux_test.go:1492:9: G602: slice index out of range (gosec)
            sboxes[thd-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", thd))
                  ^
    daemon/libnetwork/networkdb/cluster_test.go:111:21: G602: slice index out of range (gosec)
                mean, stdev := nf[0], nf[1]
                                 ^
    daemon/libnetwork/osl/interface_linux.go:586:54: G602: slice index out of range (gosec)
                log.G(ctx).WithField("portState", stateFileContent[0]).Debug("waiting for bridge port to be forwarding")
                                                                  ^
    daemon/libnetwork/osl/interface_linux.go:594:32: G602: slice index out of range (gosec)
            "portState": stateFileContent[0],
                                         ^
    daemon/libnetwork/portallocator/osallocator_linux_test.go:358:13: G602: slice index out of range (gosec)
            if payload[0] != 0x1 {
                      ^
    daemon/libnetwork/portallocator/osallocator_linux_test.go:359:68: G602: slice index out of range (gosec)
                readCh <- fmt.Errorf("expected payload 0x1, but got %x", payload[0])
                                                                                ^
    daemon/logger/gelf/gelf_test.go:197:9: nilness: impossible condition: nil != nil (govet)
        if err != nil {
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-12-10 13:40:44 +01:00
parent d83a2e644a
commit 1f498c5ff0
5 changed files with 7 additions and 5 deletions

View File

@@ -106,6 +106,7 @@ func (d *Daemon) WaitRun(contID string) error {
}
// WaitInspectWithArgs waits for the specified expression to be equals to the specified expected string in the given time.
//
// Deprecated: use cli.WaitCmd instead
func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time.Duration, arg ...string) error {
after := time.After(timeout)

View File

@@ -560,8 +560,8 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
build.WithFile("test_file1", "test1"),
build.WithFile("test_file2", "test2"),
build.WithFile("test_file3", "test3"),
build.WithFile("test_file3", "test3"),
build.WithFile("test_file4", "test4")))
build.WithFile("test_file4", "test4"),
))
}
// These tests are mainly for user namespaces to verify that new directories

View File

@@ -178,7 +178,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) {
// wait test1 to stop
hostArgs := []string{"--host", s.d.Sock()}
err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...)
err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated.
assert.NilError(c, err, "test1 should exit but not")
// record last start time
@@ -189,7 +189,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) {
s.d.Restart(c)
// test1 shouldn't restart at all
err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...)
err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated.
assert.NilError(c, err, "test1 should exit but not")
// make sure test1 isn't restarted when daemon restart

View File

@@ -247,6 +247,7 @@ func appendBaseEnv(isTLS bool, env ...string) []string {
// waitInspect will wait for the specified container to have the specified string
// in the inspect output. It will wait until the specified timeout (in seconds)
// is reached.
//
// Deprecated: use cli.WaitFor
func waitInspect(name, expr, expected string, timeout time.Duration) error {
return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout)