1
0
mirror of https://github.com/moby/moby.git synced 2025-08-01 05:47:11 +03:00

integration-cli: remove unneeded fmt.Sprintf() in asserts

Replaced using a bit of grep-ing;

```
find . -name "*_test.go" -exec sed -E -i 's#assert.Assert\((.*), fmt.Sprintf\((.*)\)\)$#assert.Assert\(\1, \2\)#g' '{}' \;
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2019-09-11 12:57:29 +02:00
parent 09226c4442
commit 0fabf3e41e
30 changed files with 181 additions and 187 deletions

View File

@ -171,7 +171,7 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *testing.T) {
func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *testing.T) {
d := s.AddDaemon(c, true, true)
hostname, err := d.Cmd("node", "inspect", "--format", "{{.Description.Hostname}}", "self")
assert.Assert(c, err == nil, fmt.Sprintf("%s", hostname))
assert.Assert(c, err == nil, "%s", hostname)
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "test", "--hostname", "{{.Service.Name}}-{{.Task.Slot}}-{{.Node.Hostname}}", "busybox", "top")
assert.NilError(c, err, out)
@ -614,7 +614,7 @@ func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *testing.T) {
assert.NilError(c, err, out)
lines := strings.Split(strings.Trim(out, "\n "), "\n")
assert.Equal(c, len(lines), 1)
assert.Assert(c, lines[0] != bareID, fmt.Sprintf("Expected not %s, but got it for is-task label, output %q", bareID, out))
assert.Assert(c, lines[0] != bareID, "Expected not %s, but got it for is-task label, output %q", bareID, out)
}
const globalNetworkPlugin = "global-network-plugin"
@ -847,7 +847,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
// Remove service
out, err = d.Cmd("service", "rm", name)
assert.NilError(c, err, out)
@ -869,7 +869,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
}
func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *testing.T) {
@ -954,9 +954,9 @@ func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
expectedOutput3 := "options timeout:3"
out, err = d.Cmd("exec", id, "cat", "/etc/resolv.conf")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput1), fmt.Sprintf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, strings.Contains(out, expectedOutput2), fmt.Sprintf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, strings.Contains(out, expectedOutput3), fmt.Sprintf("Expected '%s', but got %q", expectedOutput3, out))
assert.Assert(c, strings.Contains(out, expectedOutput1), "Expected '%s', but got %q", expectedOutput1, out)
assert.Assert(c, strings.Contains(out, expectedOutput2), "Expected '%s', but got %q", expectedOutput2, out)
assert.Assert(c, strings.Contains(out, expectedOutput3), "Expected '%s', but got %q", expectedOutput3, out)
}
func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *testing.T) {
@ -1043,7 +1043,7 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *testing.T) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
unlockKey := getUnlockKey(d, c, outs)
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
@ -1068,15 +1068,15 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *testing.T) {
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
outs, err = d.Cmd("node", "ls")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
outs, err = d.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
checkSwarmLockedToUnlocked(c, d)
outs, err = d.Cmd("node", "ls")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
}
@ -1084,7 +1084,7 @@ func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *testing.T) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
// It starts off locked
d.RestartNode(c)
@ -1099,13 +1099,13 @@ func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *testing.T) {
assert.Assert(c, strings.Contains(outs, "Swarm is encrypted and locked."))
// It is OK for user to leave a locked swarm with --force
outs, err = d.Cmd("swarm", "leave", "--force")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
outs, err = d.Cmd("swarm", "init")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
@ -1125,7 +1125,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *testing.T) {
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
unlockKey := getUnlockKey(d1, c, outs)
// The ones that got the cluster update should be set to locked
@ -1147,7 +1147,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *testing.T) {
// leave it locked, and set the cluster to no longer autolock
outs, err = d1.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
// the ones that got the update are now set to unlocked
for _, d := range []*daemon.Daemon{d1, d3} {
@ -1177,7 +1177,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
unlockKey := getUnlockKey(d1, c, outs)
// joined workers start off unlocked
@ -1233,13 +1233,13 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *testing.T) {
d := s.AddDaemon(c, true, true)
outs, err := d.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
unlockKey := getUnlockKey(d, c, outs)
// Rotate multiple times
for i := 0; i != 3; i++ {
outs, err = d.Cmd("swarm", "unlock-key", "-q", "--rotate")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
// Strip \n
newUnlockKey := outs[:len(outs)-1]
assert.Assert(c, newUnlockKey != "")
@ -1320,13 +1320,13 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *testing.T) {
d3 := s.AddDaemon(c, true, true)
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
unlockKey := getUnlockKey(d1, c, outs)
// Rotate multiple times
for i := 0; i != 3; i++ {
outs, err = d1.Cmd("swarm", "unlock-key", "-q", "--rotate")
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
// Strip \n
newUnlockKey := outs[:len(outs)-1]
assert.Assert(c, newUnlockKey != "")
@ -1385,7 +1385,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *testing.T) {
continue
}
}
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, err == nil, "%s", outs)
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
break
}
@ -1401,7 +1401,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
for i := 0; i < 2; i++ {
// set to lock
outs, err := d.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
assert.Assert(c, strings.Contains(outs, "docker swarm unlock"))
unlockKey := getUnlockKey(d, c, outs)
@ -1414,7 +1414,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
outs, err = d.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, err == nil, "out: %v", outs)
checkSwarmLockedToUnlocked(c, d)
}
@ -1440,7 +1440,7 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *testing.T) {
expectedOutput := "1.2.3.4\texample.com"
out, err = d.Cmd("exec", id, "cat", "/etc/hosts")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
}
func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *testing.T) {
@ -1950,7 +1950,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
assert.Assert(c, id != "", "secrets: %s", id)
waitForEvent(c, d, "0", "-f scope=swarm", "secret create "+id, defaultRetryCount)
@ -1970,7 +1970,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
assert.Assert(c, id != "", "configs: %s", id)
waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount)
@ -1982,7 +1982,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) {
func getUnlockKey(d *daemon.Daemon, c *testing.T, autolockOutput string) string {
unlockKey, err := d.Cmd("swarm", "unlock-key", "-q")
assert.Assert(c, err == nil, fmt.Sprintf("%s", unlockKey))
assert.Assert(c, err == nil, "%s", unlockKey)
unlockKey = strings.TrimSuffix(unlockKey, "\n")
// Check that "docker swarm init --autolock" or "docker swarm update --autolock"