Browse code

fix emptyStringTest from go-critic

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Matthieu MOREL authored on 2025/05/27 05:58:13
Showing 49 changed files
... ...
@@ -118,9 +118,9 @@ linters:
118 118
         - deferInLoop
119 119
         - deprecatedComment
120 120
         - dupImport
121
+        - dupSubExpr
121 122
         - elseif
122 123
         - emptyFallthrough
123
-        - emptyStringTest
124 124
         - equalFold
125 125
         - evalOrder
126 126
         - exitAfterDefer
... ...
@@ -121,7 +121,7 @@ func TestVersionMiddlewareVersion(t *testing.T) {
121 121
 func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
122 122
 	handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
123 123
 		v := httputils.VersionFromContext(ctx)
124
-		assert.Check(t, len(v) != 0)
124
+		assert.Check(t, v != "")
125 125
 		return nil
126 126
 	}
127 127
 
... ...
@@ -113,7 +113,7 @@ func (ir *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrit
113 113
 			return errdefs.InvalidParameter(err)
114 114
 		}
115 115
 
116
-		if len(comment) == 0 {
116
+		if comment == "" {
117 117
 			comment = "Imported from " + src
118 118
 		}
119 119
 
... ...
@@ -368,7 +368,7 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
368 368
 	ulimits, err := toBuildkitUlimits(opt.Options.Ulimits)
369 369
 	if err != nil {
370 370
 		return nil, err
371
-	} else if len(ulimits) > 0 {
371
+	} else if ulimits != "" {
372 372
 		frontendAttrs["ulimit"] = ulimits
373 373
 	}
374 374
 
... ...
@@ -60,7 +60,7 @@ func (c *imageProber) Probe(parentID string, runConfig *container.Config, platfo
60 60
 	if err != nil {
61 61
 		return "", err
62 62
 	}
63
-	if len(cacheID) == 0 {
63
+	if cacheID == "" {
64 64
 		log.G(context.TODO()).Debugf("[BUILDER] Cache miss: %s", runConfig.Cmd)
65 65
 		c.cacheBusted = true
66 66
 		return "", nil
... ...
@@ -106,7 +106,7 @@ func inspectResponse(ct string, r io.Reader, clen int64) (string, io.Reader, err
106 106
 	// content type for files without an extension (e.g. 'Dockerfile')
107 107
 	// so if we receive this value we better check for text content
108 108
 	contentType := ct
109
-	if len(ct) == 0 || ct == mimeTypeOctetStream {
109
+	if ct == "" || ct == mimeTypeOctetStream {
110 110
 		contentType, err = detectContentType(preamble)
111 111
 		if err != nil {
112 112
 			return contentType, bodyReader, err
... ...
@@ -115,7 +115,7 @@ func inspectResponse(ct string, r io.Reader, clen int64) (string, io.Reader, err
115 115
 
116 116
 	contentType = selectAcceptableMIME(contentType)
117 117
 	var cterr error
118
-	if len(contentType) == 0 {
118
+	if contentType == "" {
119 119
 		cterr = fmt.Errorf("unsupported Content-Type %q", ct)
120 120
 		contentType = ct
121 121
 	}
... ...
@@ -36,7 +36,7 @@ func TestSelectAcceptableMIME(t *testing.T) {
36 36
 	}
37 37
 
38 38
 	for _, m := range invalidMimeStrings {
39
-		if len(selectAcceptableMIME(m)) > 0 {
39
+		if selectAcceptableMIME(m) != "" {
40 40
 			t.Fatalf("Should not have accepted %q", m)
41 41
 		}
42 42
 	}
... ...
@@ -49,7 +49,7 @@ func TestHashFile(t *testing.T) {
49 49
 		t.Fatalf("Error when executing Stat: %s", err)
50 50
 	}
51 51
 
52
-	if len(sum) == 0 {
52
+	if sum == "" {
53 53
 		t.Fatalf("Hash returned empty sum")
54 54
 	}
55 55
 
... ...
@@ -83,7 +83,7 @@ func TestHashSubdir(t *testing.T) {
83 83
 		t.Fatalf("Error when executing Stat: %s", err)
84 84
 	}
85 85
 
86
-	if len(sum) == 0 {
86
+	if sum == "" {
87 87
 		t.Fatalf("Hash returned empty sum")
88 88
 	}
89 89
 
... ...
@@ -15,10 +15,10 @@ func (cli *Client) ContainerStart(ctx context.Context, containerID string, optio
15 15
 	}
16 16
 
17 17
 	query := url.Values{}
18
-	if len(options.CheckpointID) != 0 {
18
+	if options.CheckpointID != "" {
19 19
 		query.Set("checkpoint", options.CheckpointID)
20 20
 	}
21
-	if len(options.CheckpointDir) != 0 {
21
+	if options.CheckpointDir != "" {
22 22
 		query.Set("checkpoint-dir", options.CheckpointDir)
23 23
 	}
24 24
 
... ...
@@ -25,7 +25,7 @@ func (e emptyIDError) Error() string {
25 25
 // trimID trims the given object-ID / name, returning an error if it's empty.
26 26
 func trimID(objType, id string) (string, error) {
27 27
 	id = strings.TrimSpace(id)
28
-	if len(id) == 0 {
28
+	if id == "" {
29 29
 		return "", emptyIDError(objType)
30 30
 	}
31 31
 	return id, nil
... ...
@@ -380,7 +380,7 @@ func (container *Container) GetResourcePath(path string) (string, error) {
380 380
 // The returned path is always prefixed with a [filepath.Separator].
381 381
 func cleanScopedPath(path string) string {
382 382
 	if len(path) >= 2 {
383
-		if v := filepath.VolumeName(path); len(v) > 0 {
383
+		if v := filepath.VolumeName(path); v != "" {
384 384
 			path = path[len(v):]
385 385
 		}
386 386
 	}
... ...
@@ -36,7 +36,7 @@ import (
36 36
 //     unique enough to only return a single container object
37 37
 //     If none of these searches succeed, an error is returned
38 38
 func (daemon *Daemon) GetContainer(prefixOrName string) (*container.Container, error) {
39
-	if len(prefixOrName) == 0 {
39
+	if prefixOrName == "" {
40 40
 		return nil, errors.WithStack(invalidIdentifier(prefixOrName))
41 41
 	}
42 42
 
... ...
@@ -178,7 +178,7 @@ func getEntrypointAndArgs(configEntrypoint, configCmd []string) (string, []strin
178 178
 
179 179
 // GetByName returns a container given a name.
180 180
 func (daemon *Daemon) GetByName(name string) (*container.Container, error) {
181
-	if len(name) == 0 {
181
+	if name == "" {
182 182
 		return nil, fmt.Errorf("No container name supplied")
183 183
 	}
184 184
 	fullName := name
... ...
@@ -252,7 +252,7 @@ func validateContainerConfig(config *containertypes.Config) error {
252 252
 	if err := translateWorkingDir(config); err != nil {
253 253
 		return err
254 254
 	}
255
-	if len(config.StopSignal) > 0 {
255
+	if config.StopSignal != "" {
256 256
 		if _, err := signal.ParseSignal(config.StopSignal); err != nil {
257 257
 			return err
258 258
 		}
... ...
@@ -141,10 +141,10 @@ func (daemon *Daemon) ContainerExecCreate(name string, options *containertypes.E
141 141
 		return "", err
142 142
 	}
143 143
 	execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(options.Tty, linkedEnv), options.Env)
144
-	if len(execConfig.User) == 0 {
144
+	if execConfig.User == "" {
145 145
 		execConfig.User = cntr.Config.User
146 146
 	}
147
-	if len(execConfig.WorkingDir) == 0 {
147
+	if execConfig.WorkingDir == "" {
148 148
 		execConfig.WorkingDir = cntr.Config.WorkingDir
149 149
 	}
150 150
 
... ...
@@ -43,7 +43,7 @@ func getUserFromContainerd(ctx context.Context, containerdCli *containerd.Client
43 43
 }
44 44
 
45 45
 func (daemon *Daemon) execSetPlatformOpt(ctx context.Context, daemonCfg *config.Config, ec *container.ExecConfig, p *specs.Process) error {
46
-	if len(ec.User) > 0 {
46
+	if ec.User != "" {
47 47
 		var err error
48 48
 		if daemon.UsesSnapshotter() {
49 49
 			p.User, err = getUserFromContainerd(ctx, daemon.containerdClient, ec)
... ...
@@ -137,7 +137,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container
137 137
 		<-execErr
138 138
 
139 139
 		var msg string
140
-		if out := output.String(); len(out) > 0 {
140
+		if out := output.String(); out != "" {
141 141
 			msg = fmt.Sprintf("Health check exceeded timeout (%v): %s", probeTimeout, out)
142 142
 		} else {
143 143
 			msg = fmt.Sprintf("Health check exceeded timeout (%v)", probeTimeout)
... ...
@@ -39,7 +39,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
39 39
 	}
40 40
 
41 41
 	comment := img.Comment
42
-	if len(comment) == 0 && len(img.History) > 0 {
42
+	if comment == "" && len(img.History) > 0 {
43 43
 		comment = img.History[len(img.History)-1].Comment
44 44
 	}
45 45
 
... ...
@@ -25,7 +25,7 @@ func (i *ImageService) SquashImage(id, parent string) (string, error) {
25 25
 
26 26
 	var parentImg *image.Image
27 27
 	var parentChainID layer.ChainID
28
-	if len(parent) != 0 {
28
+	if parent != "" {
29 29
 		parentImg, err = i.imageStore.Get(image.ID(parent))
30 30
 		if err != nil {
31 31
 			return "", errors.Wrap(err, "error getting specified parent layer")
... ...
@@ -69,7 +69,7 @@ func (i *ImageService) SquashImage(id, parent string) (string, error) {
69 69
 
70 70
 	now := time.Now()
71 71
 	var historyComment string
72
-	if len(parent) > 0 {
72
+	if parent != "" {
73 73
 		historyComment = fmt.Sprintf("merge %s to %s", id, parent)
74 74
 	} else {
75 75
 		historyComment = fmt.Sprintf("create new from %s", id)
... ...
@@ -28,7 +28,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error {
28 28
 		buf.WriteString(`"log":`)
29 29
 		ffjsonWriteJSONBytesAsString(buf, mj.Log)
30 30
 	}
31
-	if len(mj.Stream) != 0 {
31
+	if mj.Stream != "" {
32 32
 		if first {
33 33
 			first = false
34 34
 		} else {
... ...
@@ -30,7 +30,7 @@ type Info struct {
30 30
 func (info *Info) ExtraAttributes(keyMod func(string) string) (map[string]string, error) {
31 31
 	extra := make(map[string]string)
32 32
 
33
-	if labels, ok := info.Config["labels"]; ok && len(labels) > 0 {
33
+	if labels, ok := info.Config["labels"]; ok && labels != "" {
34 34
 		for _, l := range strings.Split(labels, ",") {
35 35
 			if v, ok := info.ContainerLabels[l]; ok {
36 36
 				if keyMod != nil {
... ...
@@ -41,7 +41,7 @@ func (info *Info) ExtraAttributes(keyMod func(string) string) (map[string]string
41 41
 		}
42 42
 	}
43 43
 
44
-	if labelsRegex, ok := info.Config["labels-regex"]; ok && len(labelsRegex) > 0 {
44
+	if labelsRegex, ok := info.Config["labels-regex"]; ok && labelsRegex != "" {
45 45
 		re, err := regexp.Compile(labelsRegex)
46 46
 		if err != nil {
47 47
 			return nil, err
... ...
@@ -68,7 +68,7 @@ func (info *Info) ExtraAttributes(keyMod func(string) string) (map[string]string
68 68
 		return extra, nil
69 69
 	}
70 70
 
71
-	if env, ok := info.Config["env"]; ok && len(env) > 0 {
71
+	if env, ok := info.Config["env"]; ok && env != "" {
72 72
 		for _, l := range strings.Split(env, ",") {
73 73
 			if v, ok := envMapping[l]; ok {
74 74
 				if keyMod != nil {
... ...
@@ -79,7 +79,7 @@ func (info *Info) ExtraAttributes(keyMod func(string) string) (map[string]string
79 79
 		}
80 80
 	}
81 81
 
82
-	if envRegex, ok := info.Config["env-regex"]; ok && len(envRegex) > 0 {
82
+	if envRegex, ok := info.Config["env-regex"]; ok && envRegex != "" {
83 83
 		re, err := regexp.Compile(envRegex)
84 84
 		if err != nil {
85 85
 			return nil, err
... ...
@@ -715,7 +715,7 @@ func withCommonOptions(daemon *Daemon, daemonCfg *dconfig.Config, c *container.C
715 715
 			return err
716 716
 		}
717 717
 		cwd := c.Config.WorkingDir
718
-		if len(cwd) == 0 {
718
+		if cwd == "" {
719 719
 			cwd = "/"
720 720
 		}
721 721
 		if s.Process == nil {
... ...
@@ -87,7 +87,7 @@ func parsePSOutput(output []byte, procs []uint32) (*container.TopResponse, error
87 87
 	// in "docker top" client command
88 88
 	preContainedPidFlag := false
89 89
 	for _, line := range lines[1:] {
90
-		if len(line) == 0 {
90
+		if line == "" {
91 91
 			continue
92 92
 		}
93 93
 		fields := fieldsASCII(line)
... ...
@@ -124,7 +124,7 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
124 124
 				CopyData:    false,
125 125
 			}
126 126
 
127
-			if len(cp.Source) == 0 {
127
+			if cp.Source == "" {
128 128
 				v, err := daemon.volumes.Get(ctx, cp.Name, volumeopts.WithGetDriver(cp.Driver), volumeopts.WithGetReference(container.ID))
129 129
 				if err != nil {
130 130
 					return err
... ...
@@ -308,7 +308,7 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
308 308
 // lazyInitializeVolume initializes a mountpoint's volume if needed.
309 309
 // This happens after a daemon restart.
310 310
 func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volumemounts.MountPoint) error {
311
-	if len(m.Driver) > 0 && m.Volume == nil {
311
+	if m.Driver != "" && m.Volume == nil {
312 312
 		v, err := daemon.volumes.Get(context.TODO(), m.Name, volumeopts.WithGetDriver(m.Driver), volumeopts.WithGetReference(containerID))
313 313
 		if err != nil {
314 314
 			return err
... ...
@@ -40,8 +40,8 @@ type V2Metadata struct {
40 40
 
41 41
 // CheckV2MetadataHMAC returns true if the given "meta" is tagged with a hmac hashed by the given "key".
42 42
 func CheckV2MetadataHMAC(meta *V2Metadata, key []byte) bool {
43
-	if len(meta.HMAC) == 0 || len(key) == 0 {
44
-		return len(meta.HMAC) == 0 && len(key) == 0
43
+	if meta.HMAC == "" || len(key) == 0 {
44
+		return meta.HMAC == "" && len(key) == 0
45 45
 	}
46 46
 	mac := hmac.New(sha256.New, key)
47 47
 	mac.Write([]byte(meta.Digest))
... ...
@@ -294,7 +294,7 @@ func (pd *pushDescriptor) Upload(ctx context.Context, progressOutput progress.Ou
294 294
 		log.G(ctx).Debugf("attempting to mount layer %s (%s) from %s", diffID, mountCandidate.Digest, mountCandidate.SourceRepository)
295 295
 		createOpts := []distribution.BlobCreateOption{}
296 296
 
297
-		if len(mountCandidate.SourceRepository) > 0 {
297
+		if mountCandidate.SourceRepository != "" {
298 298
 			namedRef, err := reference.ParseNormalizedNamed(mountCandidate.SourceRepository)
299 299
 			if err != nil {
300 300
 				log.G(ctx).WithError(err).Errorf("failed to parse source repository reference %v", reference.FamiliarString(namedRef))
... ...
@@ -359,10 +359,10 @@ func (pd *pushDescriptor) Upload(ctx context.Context, progressOutput progress.Ou
359 359
 
360 360
 		// when error is unauthorizedError and user don't hasAuthInfo that's the case user don't has right to push layer to register
361 361
 		// and he hasn't login either, in this case candidate cache should be removed
362
-		if len(mountCandidate.SourceRepository) > 0 &&
362
+		if mountCandidate.SourceRepository != "" &&
363 363
 			(!isUnauthorizedError || pd.pushState.hasAuthInfo) &&
364 364
 			(metadata.CheckV2MetadataHMAC(&mountCandidate, pd.hmacKey) ||
365
-				len(mountCandidate.HMAC) == 0) {
365
+				mountCandidate.HMAC == "") {
366 366
 			cause := "blob mount failure"
367 367
 			if err != nil {
368 368
 				cause = fmt.Sprintf("an error: %v", err.Error())
... ...
@@ -488,7 +488,7 @@ func (pd *pushDescriptor) layerAlreadyExists(
488 488
 	// filter the metadata
489 489
 	candidates := []metadata.V2Metadata{}
490 490
 	for _, meta := range v2Metadata {
491
-		if len(meta.SourceRepository) > 0 && !checkOtherRepositories && meta.SourceRepository != pd.repoName.Name() {
491
+		if meta.SourceRepository != "" && !checkOtherRepositories && meta.SourceRepository != pd.repoName.Name() {
492 492
 			continue
493 493
 		}
494 494
 		candidates = append(candidates, meta)
... ...
@@ -85,7 +85,7 @@ func (d *Daemon) CheckActiveContainerCount(ctx context.Context) func(t *testing.
85 85
 		t.Helper()
86 86
 		out, err := d.Cmd("ps", "-q")
87 87
 		assert.NilError(t, err)
88
-		if len(strings.TrimSpace(out)) == 0 {
88
+		if strings.TrimSpace(out) == "" {
89 89
 			return 0, ""
90 90
 		}
91 91
 		return len(strings.Split(strings.TrimSpace(out), "\n")), fmt.Sprintf("output: %q", out)
... ...
@@ -1748,7 +1748,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsValidation(c *testing.T) {
1748 1748
 	for i, tc := range tests {
1749 1749
 		c.Run(fmt.Sprintf("case %d", i), func(c *testing.T) {
1750 1750
 			_, err = apiClient.ContainerCreate(testutil.GetContext(c), &tc.config, &tc.hostConfig, &network.NetworkingConfig{}, nil, "")
1751
-			if len(tc.msg) > 0 {
1751
+			if tc.msg != "" {
1752 1752
 				assert.ErrorContains(c, err, tc.msg, "%v", tests[i].config)
1753 1753
 			} else {
1754 1754
 				assert.NilError(c, err)
... ...
@@ -1958,7 +1958,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1958 1958
 
1959 1959
 			switch {
1960 1960
 			// Named volumes still exist after the container is removed
1961
-			case tc.spec.Type == "volume" && len(tc.spec.Source) > 0:
1961
+			case tc.spec.Type == "volume" && tc.spec.Source != "":
1962 1962
 				_, err := apiclient.VolumeInspect(ctx, mountPoint.Name)
1963 1963
 				assert.NilError(c, err)
1964 1964
 
... ...
@@ -103,7 +103,7 @@ func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) {
103 103
 	assert.NilError(c, err)
104 104
 
105 105
 	settings := inspectJSON.NetworkSettings
106
-	assert.Assert(c, len(settings.IPAddress) != 0)
106
+	assert.Assert(c, settings.IPAddress != "")
107 107
 	assert.Assert(c, settings.Networks["bridge"] != nil)
108 108
 	assert.Equal(c, settings.IPAddress, settings.Networks["bridge"].IPAddress)
109 109
 }
... ...
@@ -216,7 +216,7 @@ func (s *DockerCLILogsSuite) TestLogsSinceFutureFollow(c *testing.T) {
216 216
 
217 217
 	since := t.Unix() + 2
218 218
 	out := cli.DockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name).Combined()
219
-	assert.Assert(c, len(out) != 0, "cannot read from empty log")
219
+	assert.Assert(c, out != "", "cannot read from empty log")
220 220
 	lines := strings.Split(strings.TrimSpace(out), "\n")
221 221
 	for _, v := range lines {
222 222
 		ts, err := time.Parse(time.RFC3339Nano, strings.Split(v, " ")[0])
... ...
@@ -184,7 +184,7 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
184 184
 	assert.Assert(c, !strings.Contains(out1, "Mounted from"))
185 185
 
186 186
 	digest1 := reference.DigestRegexp.FindString(out1)
187
-	assert.Assert(c, len(digest1) > 0, "no digest found for pushed manifest")
187
+	assert.Assert(c, digest1 != "", "no digest found for pushed manifest")
188 188
 
189 189
 	const destRepoName = privateRegistryURL + "/crossrepopush/img"
190 190
 
... ...
@@ -198,7 +198,7 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
198 198
 	assert.Assert(c, is.Contains(out2, "Mounted from crossrepopush/busybox"))
199 199
 
200 200
 	digest2 := reference.DigestRegexp.FindString(out2)
201
-	assert.Assert(c, len(digest2) > 0, "no digest found for pushed manifest")
201
+	assert.Assert(c, digest2 != "", "no digest found for pushed manifest")
202 202
 	assert.Equal(c, digest1, digest2)
203 203
 
204 204
 	// ensure that pushing again produces the same digest
... ...
@@ -206,7 +206,7 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
206 206
 	assert.NilError(c, err, "pushing the image to the private registry has failed: %s", out3)
207 207
 
208 208
 	digest3 := reference.DigestRegexp.FindString(out3)
209
-	assert.Assert(c, len(digest3) > 0, "no digest found for pushed manifest")
209
+	assert.Assert(c, digest3 != "", "no digest found for pushed manifest")
210 210
 	assert.Equal(c, digest3, digest2)
211 211
 
212 212
 	// ensure that we can pull and run the cross-repo-pushed repository
... ...
@@ -1820,7 +1820,7 @@ func testRunWriteSpecialFilesAndNotCommit(t *testing.T, name, path string) {
1820 1820
 	}
1821 1821
 
1822 1822
 	out = cli.DockerCmd(t, "diff", name).Combined()
1823
-	if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, t) {
1823
+	if strings.Trim(out, "\r\n") != "" && !eqToBaseDiff(out, t) {
1824 1824
 		t.Fatal("diff should be empty")
1825 1825
 	}
1826 1826
 }
... ...
@@ -2258,7 +2258,7 @@ func (s *DockerCLIRunSuite) TestRunAllowPortRangeThroughExpose(c *testing.T) {
2258 2258
 		if portnum < 3000 || portnum > 3003 {
2259 2259
 			c.Fatalf("Port %d is out of range ", portnum)
2260 2260
 		}
2261
-		if len(binding) == 0 || len(binding[0].HostPort) == 0 {
2261
+		if len(binding) == 0 || binding[0].HostPort == "" {
2262 2262
 			c.Fatalf("Port is not mapped for the port %s", port)
2263 2263
 		}
2264 2264
 	}
... ...
@@ -2591,7 +2591,7 @@ func (s *DockerCLIRunSuite) TestRunAllowPortRangeThroughPublish(c *testing.T) {
2591 2591
 		if portnum < 3000 || portnum > 3003 {
2592 2592
 			c.Fatalf("Port %d is out of range ", portnum)
2593 2593
 		}
2594
-		if len(binding) == 0 || len(binding[0].HostPort) == 0 {
2594
+		if len(binding) == 0 || binding[0].HostPort == "" {
2595 2595
 			c.Fatal("Port is not mapped for the port "+port, id)
2596 2596
 		}
2597 2597
 	}
... ...
@@ -1810,7 +1810,7 @@ func waitForEvent(t *testing.T, d *daemon.Daemon, since string, filter string, e
1810 1810
 	for i := 0; i < retry; i++ {
1811 1811
 		until := daemonUnixTime(t)
1812 1812
 		var err error
1813
-		if len(filter) > 0 {
1813
+		if filter != "" {
1814 1814
 			out, err = d.Cmd("events", "--since", since, "--until", until, filter)
1815 1815
 		} else {
1816 1816
 			out, err = d.Cmd("events", "--since", since, "--until", until)
... ...
@@ -446,7 +446,7 @@ func reducedCheck(r reducer, funcs ...checkF) checkF {
446 446
 		for _, f := range funcs {
447 447
 			v, comment := f(t)
448 448
 			values = append(values, v)
449
-			if len(comment) > 0 {
449
+			if comment != "" {
450 450
 				comments = append(comments, comment)
451 451
 			}
452 452
 		}
... ...
@@ -159,7 +159,7 @@ func testIptabler(t *testing.T, tn string, config firewaller.Config, netConfig f
159 159
 
160 160
 	stripComments := func(text string) string {
161 161
 		lines := strings.Split(text, "\n")
162
-		lines = slices.DeleteFunc(lines, func(l string) bool { return len(l) > 0 && l[0] == '#' })
162
+		lines = slices.DeleteFunc(lines, func(l string) bool { return l != "" && l[0] == '#' })
163 163
 		return strings.Join(lines, "\n")
164 164
 	}
165 165
 
... ...
@@ -150,9 +150,9 @@ func dbusConnectionChanged(args []interface{}) {
150 150
 		return
151 151
 	}
152 152
 
153
-	if len(newOwner) > 0 {
153
+	if newOwner != "" {
154 154
 		connectionEstablished()
155
-	} else if len(oldOwner) > 0 {
155
+	} else if oldOwner != "" {
156 156
 		connectionLost()
157 157
 	}
158 158
 }
... ...
@@ -80,7 +80,7 @@ func ReverseIP(IP string) string {
80 80
 		// Reversed IPv6 is represented in dotted decimal instead of the typical
81 81
 		// colon hex notation
82 82
 		for key := range reverseIP {
83
-			if len(reverseIP[key]) == 0 { // expand the compressed 0s
83
+			if reverseIP[key] == "" { // expand the compressed 0s
84 84
 				reverseIP[key] = strings.Repeat("0000", 8-strings.Count(IP, ":"))
85 85
 			} else if len(reverseIP[key]) < 4 { // 0-padding needed
86 86
 				reverseIP[key] = strings.Repeat("0", 4-len(reverseIP[key])) + reverseIP[key]
... ...
@@ -421,7 +421,7 @@ func (n *Network) applyConfigurationTo(to *Network) error {
421 421
 			}
422 422
 		}
423 423
 	}
424
-	if len(n.ipamType) != 0 {
424
+	if n.ipamType != "" {
425 425
 		to.ipamType = n.ipamType
426 426
 	}
427 427
 	if len(n.ipamOptions) > 0 {
... ...
@@ -367,7 +367,7 @@ func (sb *Sandbox) ResolveIP(ctx context.Context, ip string) string {
367 367
 	for _, ep := range sb.Endpoints() {
368 368
 		n := ep.getNetwork()
369 369
 		svc = n.ResolveIP(ctx, ip)
370
-		if len(svc) != 0 {
370
+		if svc != "" {
371 371
 			return svc
372 372
 		}
373 373
 	}
... ...
@@ -151,7 +151,7 @@ func readPluginInfo(name, path string) (*Plugin, error) {
151 151
 		return nil, err
152 152
 	}
153 153
 
154
-	if len(u.Scheme) == 0 {
154
+	if u.Scheme == "" {
155 155
 		return nil, fmt.Errorf("Unknown protocol")
156 156
 	}
157 157
 
... ...
@@ -170,7 +170,7 @@ func readPluginJSONInfo(name, path string) (*Plugin, error) {
170 170
 		return nil, err
171 171
 	}
172 172
 	p.name = name
173
-	if p.TLSConfig != nil && len(p.TLSConfig.CAFile) == 0 {
173
+	if p.TLSConfig != nil && p.TLSConfig.CAFile == "" {
174 174
 		p.TLSConfig.InsecureSkipVerify = true
175 175
 	}
176 176
 	p.activateWait = sync.NewCond(&sync.Mutex{})
... ...
@@ -54,7 +54,7 @@ type importSpec struct {
54 54
 
55 55
 func (s *importSpec) String() string {
56 56
 	var ss string
57
-	if len(s.Name) != 0 {
57
+	if s.Name != "" {
58 58
 		ss += s.Name
59 59
 	}
60 60
 	ss += s.Path
... ...
@@ -96,7 +96,7 @@ func Parse(filePath string, objName string) (*ParsedPkg, error) {
96 96
 	for _, f := range p.Functions {
97 97
 		args := append(f.Args, f.Returns...)
98 98
 		for _, arg := range args {
99
-			if len(arg.PackageSelector) == 0 {
99
+			if arg.PackageSelector == "" {
100 100
 				continue
101 101
 			}
102 102
 
... ...
@@ -330,7 +330,7 @@ func TestTarSums(t *testing.T) {
330 330
 			fh  io.Reader
331 331
 			err error
332 332
 		)
333
-		if len(layer.filename) > 0 {
333
+		if layer.filename != "" {
334 334
 			fh, err = os.Open(layer.filename)
335 335
 			if err != nil {
336 336
 				t.Errorf("failed to open %s: %s", layer.filename, err)
... ...
@@ -380,7 +380,7 @@ func TestTarSums(t *testing.T) {
380 380
 			continue
381 381
 		}
382 382
 		var gotSum string
383
-		if len(layer.jsonfile) > 0 {
383
+		if layer.jsonfile != "" {
384 384
 			jfh, err := os.Open(layer.jsonfile)
385 385
 			if err != nil {
386 386
 				t.Errorf("failed to open %s: %s", layer.jsonfile, err)
... ...
@@ -16,10 +16,10 @@ func (vi *VersionInfo) isValid() bool {
16 16
 	const stopChars = " \t\r\n/"
17 17
 	name := vi.Name
18 18
 	vers := vi.Version
19
-	if len(name) == 0 || strings.ContainsAny(name, stopChars) {
19
+	if name == "" || strings.ContainsAny(name, stopChars) {
20 20
 		return false
21 21
 	}
22
-	if len(vers) == 0 || strings.ContainsAny(vers, stopChars) {
22
+	if vers == "" || strings.ContainsAny(vers, stopChars) {
23 23
 		return false
24 24
 	}
25 25
 	return true
... ...
@@ -41,7 +41,7 @@ func AppendVersions(base string, versions ...VersionInfo) string {
41 41
 	}
42 42
 
43 43
 	verstrs := make([]string, 0, 1+len(versions))
44
-	if len(base) > 0 {
44
+	if base != "" {
45 45
 		verstrs = append(verstrs, base)
46 46
 	}
47 47
 
... ...
@@ -124,7 +124,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) {
124 124
 
125 125
 	args := append(p.PluginObj.Config.Entrypoint, p.PluginObj.Settings.Args...)
126 126
 	cwd := p.PluginObj.Config.WorkDir
127
-	if len(cwd) == 0 {
127
+	if cwd == "" {
128 128
 		cwd = "/"
129 129
 	}
130 130
 	s.Process.Terminal = false
... ...
@@ -131,7 +131,7 @@ func (tr *authTransport) RoundTrip(orig *http.Request) (*http.Response, error) {
131 131
 
132 132
 	// Don't override
133 133
 	if req.Header.Get("Authorization") == "" {
134
-		if req.Header.Get("X-Docker-Token") == "true" && tr.authConfig != nil && len(tr.authConfig.Username) > 0 {
134
+		if req.Header.Get("X-Docker-Token") == "true" && tr.authConfig != nil && tr.authConfig.Username != "" {
135 135
 			req.SetBasicAuth(tr.authConfig.Username, tr.authConfig.Password)
136 136
 		} else if len(tr.token) > 0 {
137 137
 			req.Header.Set("Authorization", "Token "+strings.Join(tr.token, ","))
... ...
@@ -153,7 +153,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
153 153
 		op(d)
154 154
 	}
155 155
 
156
-	if len(d.resolvConfContent) > 0 {
156
+	if d.resolvConfContent != "" {
157 157
 		path := filepath.Join(d.Folder, "resolv.conf")
158 158
 		if err := os.WriteFile(path, []byte(d.resolvConfContent), 0644); err != nil {
159 159
 			return nil, fmt.Errorf("failed to write docker resolv.conf to %q: %v", path, err)
... ...
@@ -98,7 +98,7 @@ func (a *volumeDriverAdapter) getCapabilities() volume.Capability {
98 98
 	}
99 99
 
100 100
 	// don't spam the warn log below just because the plugin didn't provide a scope
101
-	if len(cap.Scope) == 0 {
101
+	if cap.Scope == "" {
102 102
 		cap.Scope = volume.LocalScope
103 103
 	}
104 104
 
... ...
@@ -138,7 +138,7 @@ func (a *volumeAdapter) DriverName() string {
138 138
 }
139 139
 
140 140
 func (a *volumeAdapter) Path() string {
141
-	if len(a.eMount) == 0 {
141
+	if a.eMount == "" {
142 142
 		mountpoint, _ := a.proxy.Path(a.name)
143 143
 		a.eMount = a.scopePath(mountpoint)
144 144
 	}
... ...
@@ -46,7 +46,7 @@ func (p *linuxParser) ValidateMountConfig(mnt *mount.Mount) error {
46 46
 }
47 47
 
48 48
 func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSourceExists bool) error {
49
-	if len(mnt.Target) == 0 {
49
+	if mnt.Target == "" {
50 50
 		return &errMountConfig{mnt, errMissingField("Target")}
51 51
 	}
52 52
 
... ...
@@ -60,7 +60,7 @@ func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSour
60 60
 
61 61
 	switch mnt.Type {
62 62
 	case mount.TypeBind:
63
-		if len(mnt.Source) == 0 {
63
+		if mnt.Source == "" {
64 64
 			return &errMountConfig{mnt, errMissingField("Source")}
65 65
 		}
66 66
 		// Don't error out just because the propagation mode is not supported on the platform
... ...
@@ -101,7 +101,7 @@ func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSour
101 101
 		if mnt.ImageOptions != nil {
102 102
 			return &errMountConfig{mnt, errExtraField("ImageOptions")}
103 103
 		}
104
-		anonymousVolume := len(mnt.Source) == 0
104
+		anonymousVolume := mnt.Source == ""
105 105
 
106 106
 		if mnt.VolumeOptions != nil && mnt.VolumeOptions.Subpath != "" {
107 107
 			if anonymousVolume {
... ...
@@ -122,7 +122,7 @@ func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSour
122 122
 		if mnt.ImageOptions != nil {
123 123
 			return &errMountConfig{mnt, errExtraField("ImageOptions")}
124 124
 		}
125
-		if len(mnt.Source) != 0 {
125
+		if mnt.Source != "" {
126 126
 			return &errMountConfig{mnt, errExtraField("Source")}
127 127
 		}
128 128
 		if _, err := p.ConvertTmpfsOptions(mnt.TmpfsOptions, mnt.ReadOnly); err != nil {
... ...
@@ -135,7 +135,7 @@ func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSour
135 135
 		if mnt.VolumeOptions != nil {
136 136
 			return &errMountConfig{mnt, errExtraField("VolumeOptions")}
137 137
 		}
138
-		if len(mnt.Source) == 0 {
138
+		if mnt.Source == "" {
139 139
 			return &errMountConfig{mnt, errMissingField("Source")}
140 140
 		}
141 141
 		if mnt.ImageOptions != nil && mnt.ImageOptions.Subpath != "" {
... ...
@@ -393,7 +393,7 @@ func (p *linuxParser) parseMountSpec(cfg mount.Mount, validateBindSourceExists b
393 393
 }
394 394
 
395 395
 func (p *linuxParser) ParseVolumesFrom(spec string) (string, string, error) {
396
-	if len(spec) == 0 {
396
+	if spec == "" {
397 397
 		return "", "", fmt.Errorf("volumes-from specification cannot be an empty string")
398 398
 	}
399 399
 
... ...
@@ -484,7 +484,7 @@ func (p *linuxParser) ValidateVolumeName(name string) error {
484 484
 }
485 485
 
486 486
 func (p *linuxParser) IsBackwardCompatible(m *MountPoint) bool {
487
-	return len(m.Source) > 0 || m.Driver == volume.DefaultDriverName
487
+	return m.Source != "" || m.Driver == volume.DefaultDriverName
488 488
 }
489 489
 
490 490
 func (p *linuxParser) ValidateTmpfsMountDestination(dest string) error {
... ...
@@ -233,7 +233,7 @@ func (m *MountPoint) Setup(ctx context.Context, mountLabel string, rootIDs idtoo
233 233
 		}
234 234
 	}
235 235
 
236
-	if len(m.Source) == 0 {
236
+	if m.Source == "" {
237 237
 		return "", noCleanup, fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
238 238
 	}
239 239
 
... ...
@@ -213,7 +213,7 @@ func (defaultFileInfoProvider) fileInfo(path string) (exist, isDir bool, _ error
213 213
 }
214 214
 
215 215
 func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValidators ...mountValidator) error {
216
-	if len(mnt.Target) == 0 {
216
+	if mnt.Target == "" {
217 217
 		return &errMountConfig{mnt, errMissingField("Target")}
218 218
 	}
219 219
 	for _, v := range additionalValidators {
... ...
@@ -224,7 +224,7 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid
224 224
 
225 225
 	switch mnt.Type {
226 226
 	case mount.TypeBind:
227
-		if len(mnt.Source) == 0 {
227
+		if mnt.Source == "" {
228 228
 			return &errMountConfig{mnt, errMissingField("Source")}
229 229
 		}
230 230
 		// Don't error out just because the propagation mode is not supported on the platform
... ...
@@ -257,7 +257,7 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid
257 257
 			return &errMountConfig{mnt, errExtraField("BindOptions")}
258 258
 		}
259 259
 
260
-		anonymousVolume := len(mnt.Source) == 0
260
+		anonymousVolume := mnt.Source == ""
261 261
 		if mnt.VolumeOptions != nil && mnt.VolumeOptions.Subpath != "" {
262 262
 			if anonymousVolume {
263 263
 				return errAnonymousVolumeWithSubpath
... ...
@@ -273,13 +273,13 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid
273 273
 			return &errMountConfig{mnt, fmt.Errorf("must not set ReadOnly mode when using anonymous volumes")}
274 274
 		}
275 275
 
276
-		if len(mnt.Source) != 0 {
276
+		if mnt.Source != "" {
277 277
 			if err := p.ValidateVolumeName(mnt.Source); err != nil {
278 278
 				return &errMountConfig{mnt, err}
279 279
 			}
280 280
 		}
281 281
 	case mount.TypeNamedPipe:
282
-		if len(mnt.Source) == 0 {
282
+		if mnt.Source == "" {
283 283
 			return &errMountConfig{mnt, errMissingField("Source")}
284 284
 		}
285 285
 
... ...
@@ -423,7 +423,7 @@ func (p *windowsParser) parseMountSpec(cfg mount.Mount, convertTargetToBackslash
423 423
 }
424 424
 
425 425
 func (p *windowsParser) ParseVolumesFrom(spec string) (string, string, error) {
426
-	if len(spec) == 0 {
426
+	if spec == "" {
427 427
 		return "", "", fmt.Errorf("volumes-from specification cannot be an empty string")
428 428
 	}
429 429
 
... ...
@@ -147,7 +147,7 @@ func (s *VolumeStore) setNamed(v volume.Volume, ref string) {
147 147
 
148 148
 	s.globalLock.Lock()
149 149
 	s.names[name] = v
150
-	if len(ref) > 0 {
150
+	if ref != "" {
151 151
 		if s.refs[name] == nil {
152 152
 			s.refs[name] = make(map[string]struct{})
153 153
 		}