Skip to content

Commit

Permalink
Merge pull request #37422 from thaJeztah/fix-linting-errors
Browse files Browse the repository at this point in the history
Fix some golint and ineffassign issues
  • Loading branch information
thaJeztah committed Jul 12, 2018
2 parents 460297b + 35f7e7c commit f9470d8
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 78 deletions.
18 changes: 4 additions & 14 deletions builder/builder-next/adapters/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,13 @@ func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s
if err := s.opt.GraphDriver.Create(key, parent, nil); err != nil {
return err
}
if err := s.db.Update(func(tx *bolt.Tx) error {
return s.db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(key))
if err != nil {
return err
}

if err := b.Put(keyParent, []byte(origParent)); err != nil {
return err
}
return nil
}); err != nil {
return err
}
return nil
return b.Put(keyParent, []byte(origParent))
})
}

func (s *snapshotter) chainID(key string) (layer.ChainID, bool) {
Expand Down Expand Up @@ -332,10 +325,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
if err != nil {
return err
}
if err := b.Put(keyCommitted, []byte(key)); err != nil {
return err
}
return nil
return b.Put(keyCommitted, []byte(key))
})
}

Expand Down
2 changes: 2 additions & 0 deletions integration-cli/docker_api_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
c.Assert(waitRun(id), checker.IsNil)

source, err := inspectMountSourceField(id, vol)
c.Assert(err, checker.IsNil)
_, err = os.Stat(source)
c.Assert(err, checker.IsNil)

Expand Down Expand Up @@ -2201,6 +2202,7 @@ func (s *DockerSuite) TestContainerKillCustomStopSignal(c *check.C) {
defer res.Body.Close()

b, err := ioutil.ReadAll(res.Body)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent, check.Commentf(string(b)))
err = waitInspect(id, "{{.State.Running}} {{.State.Restarting}}", "false false", 30*time.Second)
c.Assert(err, checker.IsNil)
Expand Down
8 changes: 2 additions & 6 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,18 +1012,14 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) {
ADD foo.txt /x/`
targetFile = "foo.txt"
)
var (
name = "test-link-absolute-volume"
dockerfile = ""
)

tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-")
if err != nil {
c.Fatalf("failed to create temporary directory: %s", tempDir)
}
defer os.RemoveAll(tempDir)

dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir)
dockerfile := fmt.Sprintf(dockerfileTemplate, tempDir)
nonExistingFile := filepath.Join(tempDir, targetFile)

ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile))
Expand All @@ -1040,7 +1036,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) {
c.Fatal(err)
}

buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx))
buildImageSuccessfully(c, "test-link-absolute-volume", build.WithExternalBuildContext(ctx))
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
}
Expand Down
3 changes: 1 addition & 2 deletions integration-cli/docker_cli_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
cleanedContainerID := strings.TrimSpace(out)

dockerCmd(c, "pause", cleanedContainerID)

out, _ = dockerCmd(c, "commit", cleanedContainerID)
dockerCmd(c, "commit", cleanedContainerID)

out = inspectField(c, cleanedContainerID, "State.Paused")
// commit should not unpause a paused container
Expand Down
3 changes: 3 additions & 0 deletions integration-cli/docker_cli_config_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) {
c.Assert(out, checker.Contains, fake)

out, err = d.Cmd("config", "rm", id)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, id)

// Fake one will remain
Expand All @@ -93,6 +94,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) {
// - Full Name
// - Partial ID (prefix)
out, err = d.Cmd("config", "rm", id[:5])
c.Assert(err, checker.Not(checker.IsNil))
c.Assert(out, checker.Not(checker.Contains), id)
out, err = d.Cmd("config", "ls")
c.Assert(err, checker.IsNil)
Expand All @@ -101,6 +103,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) {

// Remove based on ID prefix of the fake one should succeed
out, err = d.Cmd("config", "rm", fake[:5])
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, fake[:5])
out, err = d.Cmd("config", "ls")
c.Assert(err, checker.IsNil)
Expand Down
3 changes: 3 additions & 0 deletions integration-cli/docker_cli_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {

expected := readContainerFile(c, containerID, "resolv.conf")
actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
c.Assert(err, checker.IsNil)

// Expected copied file to be duplicate of the container resolvconf
c.Assert(bytes.Equal(actual, expected), checker.True)
Expand All @@ -432,6 +433,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {

expected = readContainerFile(c, containerID, "hosts")
actual, err = ioutil.ReadFile(outDir + "/hosts")
c.Assert(err, checker.IsNil)

// Expected copied file to be duplicate of the container hosts
c.Assert(bytes.Equal(actual, expected), checker.True)
Expand Down Expand Up @@ -639,6 +641,7 @@ func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) {

expected := []byte(cpContainerContents)
actual, err := ioutil.ReadFile(expectedPath)
c.Assert(err, checker.IsNil)

if !bytes.Equal(actual, expected) {
c.Fatalf("Expected copied file to be duplicate of the container symbol link target")
Expand Down
13 changes: 8 additions & 5 deletions integration-cli/docker_cli_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDRAndMac(c *check.C) {

s.d.StartWithBusybox(c, "--ipv6", "--fixed-cidr-v6=2001:db8:1::/64")

out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox")
_, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox")
c.Assert(err, checker.IsNil)

out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test")
out, err := s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test")
c.Assert(err, checker.IsNil)
c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff")
}
Expand Down Expand Up @@ -742,6 +742,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr2(c *check.C) {
defer d.Cmd("stop", "bb")

out, err = d.Cmd("exec", "bb", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'")
c.Assert(err, check.IsNil)
c.Assert(out, checker.Equals, "10.2.2.0\n")

out, err = d.Cmd("run", "--rm", "busybox", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'")
Expand Down Expand Up @@ -1944,11 +1945,12 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) {
test2ID := strings.TrimSpace(out)

out, err = s.d.Cmd("run", "-d", "--name=test3", "--link", "test2:abc", "busybox", "top")
c.Assert(err, check.IsNil)
test3ID := strings.TrimSpace(out)

s.d.Restart(c)

out, err = s.d.Cmd("create", "--name=test", "busybox")
_, err = s.d.Cmd("create", "--name=test", "busybox")
c.Assert(err, check.NotNil, check.Commentf("expected error trying to create container with duplicate name"))
// this one is no longer needed, removing simplifies the remainder of the test
out, err = s.d.Cmd("rm", "-f", "test")
Expand Down Expand Up @@ -2615,6 +2617,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithAutoRemoveContainer(c *check.C)
c.Assert(err, checker.IsNil, check.Commentf("run top2: %v", out))

out, err = s.d.Cmd("ps")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should be running"))
c.Assert(out, checker.Contains, "top2", check.Commentf("top2 should be running"))

Expand All @@ -2639,11 +2642,11 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
// captured, so `.State.Error` is empty.
// See the discussion on https://github.com/docker/docker/pull/30227#issuecomment-274161426,
// and https://github.com/docker/docker/pull/26061#r78054578 for more information.
out, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto")
_, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto")
c.Assert(err, checker.NotNil)

// Check that those values were saved on disk
out, err = s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName)
out, err := s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName)
out = strings.TrimSpace(out)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Equals, "127")
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
dockerCmd(c, "rm", "-f", name)

// Disable the check from the CLI
out, _ = dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName)
dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName)
out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "noh")
c.Check(out, checker.Equals, "[NONE]\n")
dockerCmd(c, "rm", "noh")
Expand Down
6 changes: 3 additions & 3 deletions integration-cli/docker_cli_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
// TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now.
testRequires(c, DaemonIsLinux)
name := "testlogssincefuturefollow"
out, _ := dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`)
dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`)

// Extract one timestamp from the log file to give us a starting point for
// our `--since` argument. Because the log producer runs in the background,
// we need to check repeatedly for some output to be produced.
var timestamp string
for i := 0; i != 100 && timestamp == ""; i++ {
if out, _ = dockerCmd(c, "logs", "-t", name); out == "" {
if out, _ := dockerCmd(c, "logs", "-t", name); out == "" {
time.Sleep(time.Millisecond * 100) // Retry
} else {
timestamp = strings.Split(strings.Split(out, "\n")[0], " ")[0]
Expand All @@ -200,7 +200,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
c.Assert(err, check.IsNil)

since := t.Unix() + 2
out, _ = dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name)
out, _ := dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name)
c.Assert(out, checker.Not(checker.HasLen), 0, check.Commentf("cannot read from empty log"))
lines := strings.Split(strings.TrimSpace(out), "\n")
for _, v := range lines {
Expand Down
6 changes: 2 additions & 4 deletions integration-cli/docker_cli_network_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkLsFilter(c *check.C) {
out, _ = dockerCmd(c, "network", "ls", "-f", "type=custom", "-f", "type=builtin")
assertNwList(c, out, []string{"bridge", "dev", "host", "none"})

out, _ = dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet)
dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet)
assertNwIsAvailable(c, testNet)

out, _ = dockerCmd(c, "network", "ls", "-f", "label="+testLabel)
Expand Down Expand Up @@ -880,8 +880,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top")
cid2 := strings.TrimSpace(out)

hosts2 := readContainerFileWithExec(c, cid2, hostsFile)

// verify first container etc/hosts file has not changed
hosts1post := readContainerFileWithExec(c, cid1, hostsFile)
c.Assert(string(hosts1), checker.Equals, string(hosts1post),
Expand All @@ -894,7 +892,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {

dockerCmd(c, "network", "connect", cstmBridgeNw1, cid2)

hosts2 = readContainerFileWithExec(c, cid2, hostsFile)
hosts2 := readContainerFileWithExec(c, cid2, hostsFile)
hosts1post = readContainerFileWithExec(c, cid1, hostsFile)
c.Assert(string(hosts1), checker.Equals, string(hosts1post),
check.Commentf("Unexpected %s change on container connect", hostsFile))
Expand Down
16 changes: 8 additions & 8 deletions integration-cli/docker_cli_plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
pNameWithTag := ps.getPluginRepoWithTag()

out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
c.Assert(err, checker.IsNil)

out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag)
c.Assert(out, checker.Contains, "is enabled")

out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
Expand All @@ -82,7 +82,7 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {
_, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1")
c.Assert(err, checker.IsNil)

out, _, err := dockerCmdWithError("plugin", "disable", pNameWithTag)
out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag)
c.Assert(out, checker.Contains, "in use")

_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
Expand All @@ -98,21 +98,21 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {

func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
testRequires(c, DaemonIsLinux, IsAmd64, Network)
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
c.Assert(err, checker.IsNil)

out, _, err = dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
out, _, err := dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
c.Assert(err, checker.IsNil)

nID := strings.TrimSpace(out)

out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
c.Assert(out, checker.Contains, "is in use")

_, _, err = dockerCmdWithError("network", "rm", nID)
c.Assert(err, checker.IsNil)

out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
c.Assert(out, checker.Contains, "is enabled")

_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
Expand Down Expand Up @@ -400,7 +400,7 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
c.Assert(out, checker.Contains, "false")

// Remove
out, _, err = dockerCmdWithError("plugin", "remove", id[:5])
_, _, err = dockerCmdWithError("plugin", "remove", id[:5])
c.Assert(err, checker.IsNil)
// List returns none
out, _, err = dockerCmdWithError("plugin", "ls")
Expand Down
13 changes: 4 additions & 9 deletions integration-cli/docker_cli_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,19 +792,14 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
}

func (s *DockerSuite) TestPsByOrder(c *check.C) {
name1 := "xyz-abc"
out := runSleepingContainer(c, "--name", name1)
out := runSleepingContainer(c, "--name", "xyz-abc")
container1 := strings.TrimSpace(out)

name2 := "xyz-123"
out = runSleepingContainer(c, "--name", name2)
out = runSleepingContainer(c, "--name", "xyz-123")
container2 := strings.TrimSpace(out)

name3 := "789-abc"
out = runSleepingContainer(c, "--name", name3)

name4 := "789-123"
out = runSleepingContainer(c, "--name", name4)
runSleepingContainer(c, "--name", "789-abc")
runSleepingContainer(c, "--name", "789-123")

// Run multiple time should have the same result
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz").Combined()
Expand Down
1 change: 1 addition & 0 deletions integration-cli/docker_cli_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) {
c.Assert(err, check.IsNil)

err = waitInspect("second", "{{.State.Status}}", "running", 5*time.Second)
c.Assert(err, check.IsNil)

// ping to first and its alias foo must still succeed
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
Expand Down
1 change: 1 addition & 0 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) {
// Cannot run on Windows as relies on Linux-specific functionality (sh -c mount...)
testRequires(c, DaemonIsLinux)
workingDirectory, err := ioutil.TempDir("", "TestRunCreateVolumeWithSymlink")
c.Assert(err, checker.IsNil)
image := "docker-test-createvolumewithsymlink"

buildCmd := exec.Command(dockerBinary, "build", "-t", image, "-")
Expand Down
3 changes: 3 additions & 0 deletions integration-cli/docker_cli_secret_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
c.Assert(out, checker.Contains, fake)

out, err = d.Cmd("secret", "rm", id)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, id)

// Fake one will remain
Expand All @@ -54,6 +55,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
// - Full Name
// - Partial ID (prefix)
out, err = d.Cmd("secret", "rm", id[:5])
c.Assert(err, checker.Not(checker.IsNil))
c.Assert(out, checker.Not(checker.Contains), id)
out, err = d.Cmd("secret", "ls")
c.Assert(err, checker.IsNil)
Expand All @@ -62,6 +64,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {

// Remove based on ID prefix of the fake one should succeed
out, err = d.Cmd("secret", "rm", fake[:5])
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, fake[:5])
out, err = d.Cmd("secret", "ls")
c.Assert(err, checker.IsNil)
Expand Down
8 changes: 4 additions & 4 deletions integration-cli/docker_cli_service_scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func (s *DockerSwarmSuite) TestServiceScale(c *check.C) {
service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", defaultSleepImage}, sleepCommandForDaemonPlatform()...)

// Create services
out, err := d.Cmd(service1Args...)
_, err := d.Cmd(service1Args...)
c.Assert(err, checker.IsNil)

out, err = d.Cmd(service2Args...)
_, err = d.Cmd(service2Args...)
c.Assert(err, checker.IsNil)

out, err = d.Cmd("service", "scale", "TestService1=2")
_, err = d.Cmd("service", "scale", "TestService1=2")
c.Assert(err, checker.IsNil)

out, err = d.Cmd("service", "scale", "TestService1=foobar")
out, err := d.Cmd("service", "scale", "TestService1=foobar")
c.Assert(err, checker.NotNil)

str := fmt.Sprintf("%s: invalid replicas value %s", service1Name, "foobar")
Expand Down

0 comments on commit f9470d8

Please sign in to comment.