Browse code

integration-cli: remove some redundant fmt.Sprintf()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2021/07/20 02:47:58
Showing 1 changed files
... ...
@@ -1826,15 +1826,15 @@ func (s *DockerCLIRunSuite) TestRunBindMounts(c *testing.T) {
1826 1826
 
1827 1827
 	// test writing to bind mount
1828 1828
 	if testEnv.DaemonInfo.OSType == "windows" {
1829
-		cli.DockerCmd(c, "run", "-v", fmt.Sprintf(`%s:c:\tmp:rw`, tmpDir), "busybox", "touch", "c:/tmp/holla")
1829
+		cli.DockerCmd(c, "run", "-v", tmpDir+`:c:\tmp:rw`, "busybox", "touch", "c:/tmp/holla")
1830 1830
 	} else {
1831
-		cli.DockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "busybox", "touch", "/tmp/holla")
1831
+		cli.DockerCmd(c, "run", "-v", tmpDir+`:/tmp:rw`, "busybox", "touch", "/tmp/holla")
1832 1832
 	}
1833 1833
 
1834 1834
 	readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist
1835 1835
 
1836 1836
 	// test mounting to an illegal destination directory
1837
-	_, _, err = dockerCmdWithError("run", "-v", fmt.Sprintf("%s:.", tmpDir), "busybox", "ls", ".")
1837
+	_, _, err = dockerCmdWithError("run", "-v", tmpDir+":.", "busybox", "ls", ".")
1838 1838
 	if err == nil {
1839 1839
 		c.Fatal("Container bind mounted illegal directory")
1840 1840
 	}
... ...
@@ -1842,7 +1842,7 @@ func (s *DockerCLIRunSuite) TestRunBindMounts(c *testing.T) {
1842 1842
 	// Windows does not (and likely never will) support mounting a single file
1843 1843
 	if testEnv.DaemonInfo.OSType != "windows" {
1844 1844
 		// test mount a file
1845
-		cli.DockerCmd(c, "run", "-v", fmt.Sprintf("%s/holla:/tmp/holla:rw", tmpDir), "busybox", "sh", "-c", "echo -n 'yotta' > /tmp/holla")
1845
+		cli.DockerCmd(c, "run", "-v", tmpDir+"/holla:/tmp/holla:rw", "busybox", "sh", "-c", "echo -n 'yotta' > /tmp/holla")
1846 1846
 		content := readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist
1847 1847
 		expected := "yotta"
1848 1848
 		if content != expected {
... ...
@@ -1910,10 +1910,10 @@ func (s *DockerCLIRunSuite) TestRunSetMacAddress(c *testing.T) {
1910 1910
 	mac := "12:34:56:78:9a:bc"
1911 1911
 	var out string
1912 1912
 	if testEnv.DaemonInfo.OSType == "windows" {
1913
-		out = cli.DockerCmd(c, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "sh", "-c", "ipconfig /all | grep 'Physical Address' | awk '{print $12}'").Combined()
1913
+		out = cli.DockerCmd(c, "run", "-i", "--rm", "--mac-address="+mac, "busybox", "sh", "-c", "ipconfig /all | grep 'Physical Address' | awk '{print $12}'").Combined()
1914 1914
 		mac = strings.ReplaceAll(strings.ToUpper(mac), ":", "-") // To Windows-style MACs
1915 1915
 	} else {
1916
-		out = cli.DockerCmd(c, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "/bin/sh", "-c", "ip link show eth0 | tail -1 | awk '{print $2}'").Combined()
1916
+		out = cli.DockerCmd(c, "run", "-i", "--rm", "--mac-address="+mac, "busybox", "/bin/sh", "-c", "ip link show eth0 | tail -1 | awk '{print $2}'").Combined()
1917 1917
 	}
1918 1918
 
1919 1919
 	actualMac := strings.TrimSpace(out)
... ...
@@ -2005,23 +2005,23 @@ func (s *DockerCLIRunSuite) TestRunMountOrdering(c *testing.T) {
2005 2005
 		c.Fatalf("failed to mkdir at %s - %s", fooDir, err)
2006 2006
 	}
2007 2007
 
2008
-	if err := os.WriteFile(fmt.Sprintf("%s/touch-me", fooDir), []byte{}, 0o644); err != nil {
2008
+	if err := os.WriteFile(filepath.Join(fooDir, "touch-me"), []byte{}, 0o644); err != nil {
2009 2009
 		c.Fatal(err)
2010 2010
 	}
2011 2011
 
2012
-	if err := os.WriteFile(fmt.Sprintf("%s/touch-me", tmpDir), []byte{}, 0o644); err != nil {
2012
+	if err := os.WriteFile(filepath.Join(tmpDir, "touch-me"), []byte{}, 0o644); err != nil {
2013 2013
 		c.Fatal(err)
2014 2014
 	}
2015 2015
 
2016
-	if err := os.WriteFile(fmt.Sprintf("%s/touch-me", tmpDir2), []byte{}, 0o644); err != nil {
2016
+	if err := os.WriteFile(filepath.Join(tmpDir2, "touch-me"), []byte{}, 0o644); err != nil {
2017 2017
 		c.Fatal(err)
2018 2018
 	}
2019 2019
 
2020 2020
 	cli.DockerCmd(c, "run",
2021
-		"-v", fmt.Sprintf("%s:"+dPath("/tmp"), tmpDir),
2022
-		"-v", fmt.Sprintf("%s:"+dPath("/tmp/foo"), fooDir),
2023
-		"-v", fmt.Sprintf("%s:"+dPath("/tmp/tmp2"), tmpDir2),
2024
-		"-v", fmt.Sprintf("%s:"+dPath("/tmp/tmp2/foo"), fooDir),
2021
+		"-v", tmpDir+":"+dPath("/tmp"),
2022
+		"-v", fooDir+":"+dPath("/tmp/foo"),
2023
+		"-v", tmpDir2+":"+dPath("/tmp/tmp2"),
2024
+		"-v", fooDir+":"+dPath("/tmp/tmp2/foo"),
2025 2025
 		"busybox:latest", "sh", "-c",
2026 2026
 		"ls "+dPath("/tmp/touch-me")+" "+dPath("/tmp/foo/touch-me")+" "+dPath("/tmp/tmp2/touch-me")+" "+dPath("/tmp/tmp2/foo/touch-me"),
2027 2027
 	)
... ...
@@ -2045,11 +2045,11 @@ func (s *DockerCLIRunSuite) TestRunReuseBindVolumeThatIsSymlink(c *testing.T) {
2045 2045
 	defer os.RemoveAll(linkPath)
2046 2046
 
2047 2047
 	// Create first container
2048
-	cli.DockerCmd(c, "run", "-v", fmt.Sprintf("%s:"+dPath("/tmp/test"), linkPath), "busybox", "ls", dPath("/tmp/test"))
2048
+	cli.DockerCmd(c, "run", "-v", linkPath+":"+dPath("/tmp/test"), "busybox", "ls", dPath("/tmp/test"))
2049 2049
 
2050 2050
 	// Create second container with same symlinked path
2051 2051
 	// This will fail if the referenced issue is hit with a "Volume exists" error
2052
-	cli.DockerCmd(c, "run", "-v", fmt.Sprintf("%s:"+dPath("/tmp/test"), linkPath), "busybox", "ls", dPath("/tmp/test"))
2052
+	cli.DockerCmd(c, "run", "-v", linkPath+":"+dPath("/tmp/test"), "busybox", "ls", dPath("/tmp/test"))
2053 2053
 }
2054 2054
 
2055 2055
 // GH#10604: Test an "/etc" volume doesn't overlay special bind mounts in container
... ...
@@ -2237,7 +2237,7 @@ func (s *DockerCLIRunSuite) TestRunModeIpcContainerNotRunning(c *testing.T) {
2237 2237
 	id := cli.DockerCmd(c, "create", "busybox").Stdout()
2238 2238
 	id = strings.TrimSpace(id)
2239 2239
 
2240
-	out, _, err := dockerCmdWithError("run", fmt.Sprintf("--ipc=container:%s", id), "busybox")
2240
+	out, _, err := dockerCmdWithError("run", "--ipc=container:"+id, "busybox")
2241 2241
 	if err == nil {
2242 2242
 		c.Fatalf("Run container with ipc mode container should fail with non running container: %s\n%s", out, err)
2243 2243
 	}
... ...
@@ -2256,12 +2256,12 @@ func (s *DockerCLIRunSuite) TestRunModePIDContainer(c *testing.T) {
2256 2256
 	}
2257 2257
 	pid1 := inspectField(c, id, "State.Pid")
2258 2258
 
2259
-	parentContainerPid, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/pid", pid1))
2259
+	parentContainerPid, err := os.Readlink(path.Join("/proc", pid1, "ns/pid"))
2260 2260
 	if err != nil {
2261 2261
 		c.Fatal(err)
2262 2262
 	}
2263 2263
 
2264
-	out := cli.DockerCmd(c, "run", fmt.Sprintf("--pid=container:%s", id), "busybox", "readlink", "/proc/self/ns/pid").Combined()
2264
+	out := cli.DockerCmd(c, "run", "--pid=container:"+id, "busybox", "readlink", "/proc/self/ns/pid").Combined()
2265 2265
 	out = strings.Trim(out, "\n")
2266 2266
 	if parentContainerPid != out {
2267 2267
 		c.Fatalf("PID different with --pid=container:%s %s != %s\n", id, parentContainerPid, out)
... ...
@@ -2284,7 +2284,7 @@ func (s *DockerCLIRunSuite) TestRunModePIDContainerNotRunning(c *testing.T) {
2284 2284
 	id := cli.DockerCmd(c, "create", "busybox").Stdout()
2285 2285
 	id = strings.TrimSpace(id)
2286 2286
 
2287
-	out, _, err := dockerCmdWithError("run", fmt.Sprintf("--pid=container:%s", id), "busybox")
2287
+	out, _, err := dockerCmdWithError("run", "--pid=container:"+id, "busybox")
2288 2288
 	if err == nil {
2289 2289
 		c.Fatalf("Run container with pid mode container should fail with non running container: %s\n%s", out, err)
2290 2290
 	}
... ...
@@ -2322,12 +2322,12 @@ func (s *DockerCLIRunSuite) TestContainerNetworkMode(c *testing.T) {
2322 2322
 	cli.WaitRun(c, id)
2323 2323
 	pid1 := inspectField(c, id, "State.Pid")
2324 2324
 
2325
-	parentContainerNet, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1))
2325
+	parentContainerNet, err := os.Readlink(path.Join("/proc", pid1, "ns/net"))
2326 2326
 	if err != nil {
2327 2327
 		c.Fatal(err)
2328 2328
 	}
2329 2329
 
2330
-	out := cli.DockerCmd(c, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net").Combined()
2330
+	out := cli.DockerCmd(c, "run", "--net=container:"+id, "busybox", "readlink", "/proc/self/ns/net").Combined()
2331 2331
 	out = strings.Trim(out, "\n")
2332 2332
 	if parentContainerNet != out {
2333 2333
 		c.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out)
... ...
@@ -2787,7 +2787,7 @@ func (s *DockerCLIRunSuite) TestRunReadFilteredProc(c *testing.T) {
2787 2787
 	}
2788 2788
 	for i, filePath := range testReadPaths {
2789 2789
 		name := fmt.Sprintf("procsieve-%d", i)
2790
-		shellCmd := fmt.Sprintf("exec 3<%s", filePath)
2790
+		shellCmd := "exec 3<" + filePath
2791 2791
 
2792 2792
 		out, exitCode, err := dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor=docker-default", "--name", name, "busybox", "sh", "-c", shellCmd)
2793 2793
 		if exitCode != 0 {
... ...
@@ -2942,7 +2942,7 @@ func (s *DockerCLIRunSuite) TestRunWriteFilteredProc(c *testing.T) {
2942 2942
 	for i, filePath := range testWritePaths {
2943 2943
 		name := fmt.Sprintf("writeprocsieve-%d", i)
2944 2944
 
2945
-		shellCmd := fmt.Sprintf("exec 3>%s", filePath)
2945
+		shellCmd := "exec 3>" + filePath
2946 2946
 		out, code, err := dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor=docker-default", "--name", name, "busybox", "sh", "-c", shellCmd)
2947 2947
 		if code != 0 {
2948 2948
 			return
... ...
@@ -3040,7 +3040,7 @@ func (s *DockerCLIRunSuite) TestPtraceContainerProcsFromHost(c *testing.T) {
3040 3040
 	cli.WaitRun(c, id)
3041 3041
 	pid1 := inspectField(c, id, "State.Pid")
3042 3042
 
3043
-	_, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1))
3043
+	_, err := os.Readlink(path.Join("/proc", pid1, "ns/net"))
3044 3044
 	if err != nil {
3045 3045
 		c.Fatal(err)
3046 3046
 	}
... ...
@@ -3098,7 +3098,7 @@ func (s *DockerCLIRunSuite) TestRunCreateContainerFailedCleanUp(c *testing.T) {
3098 3098
 
3099 3099
 	containerID, err := inspectFilter(name, ".Id")
3100 3100
 	assert.Assert(c, err != nil, "Expected not to have this container: %s!", containerID)
3101
-	assert.Equal(c, containerID, "", fmt.Sprintf("Expected not to have this container: %s!", containerID))
3101
+	assert.Equal(c, containerID, "", "Expected not to have this container: %s!", containerID)
3102 3102
 }
3103 3103
 
3104 3104
 func (s *DockerCLIRunSuite) TestRunNamedVolume(c *testing.T) {
... ...
@@ -3761,7 +3761,7 @@ func (s *DockerCLIRunSuite) TestRunAttachFailedNoLeak(c *testing.T) {
3761 3761
 		strings.Contains(outLowerCase, "were not connected because a duplicate name exists") ||
3762 3762
 		strings.Contains(outLowerCase, "the specified port already exists") ||
3763 3763
 		strings.Contains(outLowerCase, "hns failed with error : failed to create endpoint") ||
3764
-		strings.Contains(outLowerCase, "hns failed with error : the object already exists"), fmt.Sprintf("Output: %s", out))
3764
+		strings.Contains(outLowerCase, "hns failed with error : the object already exists"), "Output: "+out)
3765 3765
 
3766 3766
 	out, err = d.Cmd("rm", "-f", "test")
3767 3767
 	assert.NilError(c, err, out)
... ...
@@ -4143,7 +4143,7 @@ func (s *DockerCLIRunSuite) TestRunMountReadOnlyDevShm(c *testing.T) {
4143 4143
 	assert.NilError(c, err)
4144 4144
 	defer os.RemoveAll(emptyDir)
4145 4145
 	out, _, err := dockerCmdWithError("run", "--rm", "--read-only",
4146
-		"-v", fmt.Sprintf("%s:/dev/shm:ro", emptyDir),
4146
+		"-v", emptyDir+":/dev/shm:ro",
4147 4147
 		"busybox", "touch", "/dev/shm/foo")
4148 4148
 	assert.ErrorContains(c, err, "", out)
4149 4149
 	assert.Assert(c, is.Contains(out, "Read-only file system"))
... ...
@@ -4257,7 +4257,7 @@ func (s *DockerCLIRunSuite) TestRunMount(c *testing.T) {
4257 4257
 				},
4258 4258
 				{
4259 4259
 					"--read-only",
4260
-					"--volume", fmt.Sprintf("%s:/foo", mnt1),
4260
+					"--volume", mnt1 + ":/foo",
4261 4261
 					"--mount", "type=volume,dst=/bar",
4262 4262
 				},
4263 4263
 			},
... ...
@@ -4282,7 +4282,7 @@ func (s *DockerCLIRunSuite) TestRunMount(c *testing.T) {
4282 4282
 					"--mount", fmt.Sprintf("type=bind,src=%s,target=/foo", mnt2),
4283 4283
 				},
4284 4284
 				{
4285
-					"--volume", fmt.Sprintf("%s:/foo", mnt1),
4285
+					"--volume", mnt1 + ":/foo",
4286 4286
 					"--mount", fmt.Sprintf("type=bind,src=%s,target=/foo", mnt2),
4287 4287
 				},
4288 4288
 			},
... ...
@@ -4291,7 +4291,7 @@ func (s *DockerCLIRunSuite) TestRunMount(c *testing.T) {
4291 4291
 		{
4292 4292
 			equivalents: [][]string{
4293 4293
 				{
4294
-					"--volume", fmt.Sprintf("%s:/foo", mnt1),
4294
+					"--volume", mnt1 + ":/foo",
4295 4295
 					"--mount", fmt.Sprintf("type=volume,src=%s,target=/foo", mnt2),
4296 4296
 				},
4297 4297
 			},
... ...
@@ -4358,7 +4358,7 @@ func (s *DockerCLIRunSuite) TestRunAddDeviceCgroupRule(c *testing.T) {
4358 4358
 		c.Fatalf("%s shouldn't been in the device.list", deviceRule)
4359 4359
 	}
4360 4360
 
4361
-	out = cli.DockerCmd(c, "run", "--rm", fmt.Sprintf("--device-cgroup-rule=%s", deviceRule), "busybox", "grep", deviceRule, "/sys/fs/cgroup/devices/devices.list").Combined()
4361
+	out = cli.DockerCmd(c, "run", "--rm", "--device-cgroup-rule="+deviceRule, "busybox", "grep", deviceRule, "/sys/fs/cgroup/devices/devices.list").Combined()
4362 4362
 	assert.Equal(c, strings.TrimSpace(out), deviceRule)
4363 4363
 }
4364 4364