Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/engine/integration-cli/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type DockerSuite struct {
}

func (s *DockerSuite) OnTimeout(c *check.C) {
if !testEnv.IsLocalDaemon() {
if testEnv.IsRemoteDaemon() {
return
}
path := filepath.Join(os.Getenv("DEST"), "docker.pid")
Expand Down
103 changes: 0 additions & 103 deletions components/engine/integration-cli/docker_api_volumes_test.go

This file was deleted.

21 changes: 2 additions & 19 deletions components/engine/integration-cli/docker_cli_export_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@ import (
"github.com/gotestyourself/gotestyourself/icmd"
)

// export an image and try to import it into a new one
func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
testRequires(c, DaemonIsLinux)
containerID := "testexportcontainerandimportimage"

dockerCmd(c, "run", "--name", containerID, "busybox", "true")

out, _ := dockerCmd(c, "export", containerID)

result := icmd.RunCmd(icmd.Cmd{
Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
Stdin: strings.NewReader(out),
})
result.Assert(c, icmd.Success)

cleanedImageID := strings.TrimSpace(result.Combined())
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
}

// TODO: Move this test to docker/cli, as it is essentially the same test
// as TestExportContainerAndImportImage except output to a file.
// Used to test output flag in the export command
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
testRequires(c, DaemonIsLinux)
Expand Down
55 changes: 0 additions & 55 deletions components/engine/integration-cli/docker_cli_rm_test.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
package main

import (
"io/ioutil"
"os"

"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/go-check/check"
)

func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
testRequires(c, SameHostDaemon)

prefix, slash := getPrefixAndSlashFromDaemonPlatform()

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

dockerCmd(c, "run", "--name", "losemyvolumes", "-v", tempDir+":"+prefix+slash+"test", "busybox", "true")

err = os.RemoveAll(tempDir)
c.Assert(err, check.IsNil)

dockerCmd(c, "rm", "-v", "losemyvolumes")
}

func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
prefix, slash := getPrefixAndSlashFromDaemonPlatform()

dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true")

dockerCmd(c, "rm", "-v", "foo")
}

func (s *DockerSuite) TestRmContainerRunning(c *check.C) {
createRunningContainer(c, "foo")

res, _, err := dockerCmdWithError("rm", "foo")
c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
c.Assert(res, checker.Contains, "cannot remove a running container")
}

func (s *DockerSuite) TestRmContainerForceRemoveRunning(c *check.C) {
createRunningContainer(c, "foo")

// Stop then remove with -f
dockerCmd(c, "rm", "-f", "foo")
}

func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
dockerfile1 := `FROM busybox:latest
ENTRYPOINT ["true"]`
Expand All @@ -75,13 +30,3 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))

}

func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
out, _, err := dockerCmdWithError("rm", "unknown")
c.Assert(err, checker.NotNil, check.Commentf("Expected error on rm unknown container, got none"))
c.Assert(out, checker.Contains, "No such container")
}

func createRunningContainer(c *check.C, name string) {
runSleepingContainer(c, "-dt", "--name", name)
}
26 changes: 10 additions & 16 deletions components/engine/integration/container/daemon_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/integration/internal/container"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"
)
Expand All @@ -26,6 +27,7 @@ import (
// the container process, then start dockerd back up and attempt to start the
// container again.
func TestContainerStartOnDaemonRestart(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon(), "cannot start daemon on remote test run")
t.Parallel()

d := daemon.New(t, "", "dockerd", daemon.Config{})
Expand All @@ -36,22 +38,14 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
assert.NoError(t, err, "error creating client")

ctx := context.Background()
c, err := client.ContainerCreate(ctx,
&container.Config{
Image: "busybox",
Cmd: []string{"top"},
},
nil,
nil,
"",
)
assert.NoError(t, err, "error creating test container")
defer client.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true})

err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})

cID := container.Create(t, ctx, client)
defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})

err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
assert.NoError(t, err, "error starting test container")

inspect, err := client.ContainerInspect(ctx, c.ID)
inspect, err := client.ContainerInspect(ctx, cID)
assert.NoError(t, err, "error getting inspect data")

ppid := getContainerdShimPid(t, inspect)
Expand All @@ -67,7 +61,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {

d.Start(t, "--iptables=false")

err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
assert.NoError(t, err, "failed to start test container")
}

Expand Down
2 changes: 1 addition & 1 deletion components/engine/integration/container/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestDiffFilenameShownInOutput(t *testing.T) {
// a "Files/" prefix.
lookingFor := containertypes.ContainerChangeResponseItem{Kind: archive.ChangeAdd, Path: "/foo/bar"}
if testEnv.OSType == "windows" {
poll.WaitOn(t, containerIsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
lookingFor = containertypes.ContainerChangeResponseItem{Kind: archive.ChangeModify, Path: "Files/foo/bar"}
}

Expand Down
53 changes: 53 additions & 0 deletions components/engine/integration/container/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package container // import "github.com/docker/docker/integration/container"

import (
"context"
"encoding/json"
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/request"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/gotestyourself/gotestyourself/poll"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// export an image and try to import it into a new one
func TestExportContainerAndImportImage(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")

defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

cID := container.Run(t, ctx, client, container.WithCmd("true"))
poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond))

reference := "repo/testexp:v1"
exportResp, err := client.ContainerExport(ctx, cID)
require.NoError(t, err)
importResp, err := client.ImageImport(ctx, types.ImageImportSource{
Source: exportResp,
SourceName: "-",
}, reference, types.ImageImportOptions{})
require.NoError(t, err)

// If the import is successfully, then the message output should contain
// the image ID and match with the output from `docker images`.

dec := json.NewDecoder(importResp)
var jm jsonmessage.JSONMessage
err = dec.Decode(&jm)
require.NoError(t, err)

images, err := client.ImageList(ctx, types.ImageListOptions{
Filters: filters.NewArgs(filters.Arg("reference", reference)),
})
require.NoError(t, err)
assert.Equal(t, jm.Status, images[0].ID)
}
2 changes: 1 addition & 1 deletion components/engine/integration/container/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestInspectCpusetInConfigPre120(t *testing.T) {
c.HostConfig.Resources.CpusetCpus = "0"
},
)
poll.WaitOn(t, containerIsInState(ctx, client, name, "exited"), poll.WithDelay(100*time.Millisecond))
poll.WaitOn(t, container.IsInState(ctx, client, name, "exited"), poll.WithDelay(100*time.Millisecond))

_, body, err := client.ContainerInspectWithRaw(ctx, name, false)
require.NoError(t, err)
Expand Down
Loading