integration-cli: split DockerSuite into subsequent build suites

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-06-16 23:32:10 +02:00
parent 7ed823ead9
commit 0e6a1b9596
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
67 changed files with 1844 additions and 1147 deletions

View file

@ -7,11 +7,24 @@ import (
"strings" "strings"
"sync" "sync"
"testing" "testing"
"time"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *testing.B) { type DockerBenchmarkSuite struct {
ds *DockerSuite
}
func (s *DockerBenchmarkSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerBenchmarkSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
maxConcurrency := runtime.GOMAXPROCS(0) maxConcurrency := runtime.GOMAXPROCS(0)
numIterations := c.N numIterations := c.N
outerGroup := &sync.WaitGroup{} outerGroup := &sync.WaitGroup{}
@ -92,3 +105,26 @@ func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
assert.NilError(c, err) assert.NilError(c, err)
} }
} }
func (s *DockerBenchmarkSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) {
out, _ := dockerCmd(c, "run", "-d", "--log-opt", "max-size=1b", "--log-opt", "max-file=10", "busybox", "sh", "-c", "while true; do usleep 50000; echo hello; done")
id := strings.TrimSpace(out)
ch := make(chan error, 1)
go func() {
ch <- nil
out, _, _ := dockerCmdWithError("logs", "-f", id)
// if this returns at all, it's an error
ch <- fmt.Errorf(out)
}()
<-ch
select {
case <-time.After(30 * time.Second):
// ran for 30 seconds with no problem
return
case err := <-ch:
if err != nil {
c.Fatal(err)
}
}
}

View file

@ -83,7 +83,240 @@ func ensureTestEnvSetup(t *testing.T) {
func TestDockerSuite(t *testing.T) { func TestDockerSuite(t *testing.T) {
ensureTestEnvSetup(t) ensureTestEnvSetup(t)
suite.Run(t, &DockerSuite{}) suite.Run(t, &DockerAPISuite{ds: &DockerSuite{}})
suite.Run(t, &DockerBenchmarkSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIAttachSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIBuildSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLICommitSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLICpSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLICreateSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIEventSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIExecSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIHealthSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIHistorySuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIImagesSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIImportSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIInfoSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIInspectSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLILinksSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLILoginSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLILogsSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLINetmodeSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLINetworkSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPluginLogDriverSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPluginsSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPortSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIProxySuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPruneSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPsSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPullSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIPushSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIRestartSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIRmiSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIRunSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLISaveLoadSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLISearchSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLISNISuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIStartSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIStatsSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLITopSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIUpdateSuite{ds: &DockerSuite{}})
suite.Run(t, &DockerCLIVolumeSuite{ds: &DockerSuite{}})
}
func TestDockerAPISuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerAPISuite{ds: &DockerSuite{}})
}
func TestDockerBenchmarkSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerBenchmarkSuite{ds: &DockerSuite{}})
}
func TestDockerCLIAttachSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIAttachSuite{ds: &DockerSuite{}})
}
func TestDockerCLIBuildSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIBuildSuite{ds: &DockerSuite{}})
}
func TestDockerCLICommitSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLICommitSuite{ds: &DockerSuite{}})
}
func TestDockerCLICpSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLICpSuite{ds: &DockerSuite{}})
}
func TestDockerCLICreateSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLICreateSuite{ds: &DockerSuite{}})
}
func TestDockerCLIEventSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIEventSuite{ds: &DockerSuite{}})
}
func TestDockerCLIExecSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIExecSuite{ds: &DockerSuite{}})
}
func TestDockerCLIHealthSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIHealthSuite{ds: &DockerSuite{}})
}
func TestDockerCLIHistorySuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIHistorySuite{ds: &DockerSuite{}})
}
func TestDockerCLIImagesSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIImagesSuite{ds: &DockerSuite{}})
}
func TestDockerCLIImportSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIImportSuite{ds: &DockerSuite{}})
}
func TestDockerCLIInfoSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIInfoSuite{ds: &DockerSuite{}})
}
func TestDockerCLIInspectSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIInspectSuite{ds: &DockerSuite{}})
}
func TestDockerCLILinksSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLILinksSuite{ds: &DockerSuite{}})
}
func TestDockerCLILoginSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLILoginSuite{ds: &DockerSuite{}})
}
func TestDockerCLILogsSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLILogsSuite{ds: &DockerSuite{}})
}
func TestDockerCLINetmodeSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLINetmodeSuite{ds: &DockerSuite{}})
}
func TestDockerCLINetworkSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLINetworkSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPluginLogDriverSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPluginLogDriverSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPluginsSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPluginsSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPortSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPortSuite{ds: &DockerSuite{}})
}
func TestDockerCLIProxySuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIProxySuite{ds: &DockerSuite{}})
}
func TestDockerCLIPruneSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPruneSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPsSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPsSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPullSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPullSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPushSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIPushSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRestartSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIRestartSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRmiSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIRmiSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRunSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIRunSuite{ds: &DockerSuite{}})
}
func TestDockerCLISaveLoadSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLISaveLoadSuite{ds: &DockerSuite{}})
}
func TestDockerCLISearchSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLISearchSuite{ds: &DockerSuite{}})
}
func TestDockerCLISNISuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLISNISuite{ds: &DockerSuite{}})
}
func TestDockerCLIStartSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIStartSuite{ds: &DockerSuite{}})
}
func TestDockerCLIStatsSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIStatsSuite{ds: &DockerSuite{}})
}
func TestDockerCLITopSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLITopSuite{ds: &DockerSuite{}})
}
func TestDockerCLIUpdateSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIUpdateSuite{ds: &DockerSuite{}})
}
func TestDockerCLIVolumeSuite(t *testing.T) {
ensureTestEnvSetup(t)
suite.Run(t, &DockerCLIVolumeSuite{ds: &DockerSuite{}})
} }
func TestDockerRegistrySuite(t *testing.T) { func TestDockerRegistrySuite(t *testing.T) {

View file

@ -22,7 +22,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestGetContainersAttachWebsocket(c *testing.T) { func (s *DockerAPISuite) TestGetContainersAttachWebsocket(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat") out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
@ -75,7 +75,7 @@ func (s *DockerSuite) TestGetContainersAttachWebsocket(c *testing.T) {
} }
// regression gh14320 // regression gh14320
func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *testing.T) { func (s *DockerAPISuite) TestPostContainersAttachContainerNotFound(c *testing.T) {
resp, _, err := request.Post("/containers/doesnotexist/attach") resp, _, err := request.Post("/containers/doesnotexist/attach")
assert.NilError(c, err) assert.NilError(c, err)
// connection will shutdown, err should be "persistent connection closed" // connection will shutdown, err should be "persistent connection closed"
@ -86,7 +86,7 @@ func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *testing.T) {
assert.Equal(c, string(content), expected) assert.Equal(c, string(content), expected)
} }
func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *testing.T) { func (s *DockerAPISuite) TestGetContainersWsAttachContainerNotFound(c *testing.T) {
res, body, err := request.Get("/containers/doesnotexist/attach/ws") res, body, err := request.Get("/containers/doesnotexist/attach/ws")
assert.Equal(c, res.StatusCode, http.StatusNotFound) assert.Equal(c, res.StatusCode, http.StatusNotFound)
assert.NilError(c, err) assert.NilError(c, err)
@ -96,7 +96,7 @@ func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *testing.T) {
assert.Assert(c, strings.Contains(getErrorMessage(c, b), expected)) assert.Assert(c, strings.Contains(getErrorMessage(c, b), expected))
} }
func (s *DockerSuite) TestPostContainersAttach(c *testing.T) { func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
expectSuccess := func(wc io.WriteCloser, br *bufio.Reader, stream string, tty bool) { expectSuccess := func(wc io.WriteCloser, br *bufio.Reader, stream string, tty bool) {

View file

@ -21,7 +21,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIDockerFileRemote(c *testing.T) {
testRequires(c, NotUserNamespace) testRequires(c, NotUserNamespace)
var testD string var testD string
@ -52,7 +52,7 @@ RUN find /tmp/`
assert.Assert(c, !strings.Contains(out, "baz")) assert.Assert(c, !strings.Contains(out, "baz"))
} }
func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIRemoteTarballContext(c *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
tw := tar.NewWriter(buffer) tw := tar.NewWriter(buffer)
defer tw.Close() defer tw.Close()
@ -79,7 +79,7 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *testing.T) {
b.Close() b.Close()
} }
func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
tw := tar.NewWriter(buffer) tw := tar.NewWriter(buffer)
defer tw.Close() defer tw.Close()
@ -133,7 +133,7 @@ RUN echo 'right'
assert.Assert(c, !strings.Contains(string(content), "wrong")) assert.Assert(c, !strings.Contains(string(content), "wrong"))
} }
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *testing.T) { func (s *DockerAPISuite) TestBuildAPILowerDockerfile(c *testing.T) {
git := fakegit.New(c, "repo", map[string]string{ git := fakegit.New(c, "repo", map[string]string{
"dockerfile": `FROM busybox "dockerfile": `FROM busybox
RUN echo from dockerfile`, RUN echo from dockerfile`,
@ -151,7 +151,7 @@ RUN echo from dockerfile`,
assert.Assert(c, is.Contains(out, "from dockerfile")) assert.Assert(c, is.Contains(out, "from dockerfile"))
} }
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIBuildGitWithF(c *testing.T) {
git := fakegit.New(c, "repo", map[string]string{ git := fakegit.New(c, "repo", map[string]string{
"baz": `FROM busybox "baz": `FROM busybox
RUN echo from baz`, RUN echo from baz`,
@ -172,7 +172,7 @@ RUN echo from Dockerfile`,
assert.Assert(c, is.Contains(out, "from baz")) assert.Assert(c, is.Contains(out, "from baz"))
} }
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIDoubleDockerfile(c *testing.T) {
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
git := fakegit.New(c, "repo", map[string]string{ git := fakegit.New(c, "repo", map[string]string{
"Dockerfile": `FROM busybox "Dockerfile": `FROM busybox
@ -194,7 +194,7 @@ RUN echo from dockerfile`,
assert.Assert(c, is.Contains(out, "from Dockerfile")) assert.Assert(c, is.Contains(out, "from Dockerfile"))
} }
func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *testing.T) { func (s *DockerAPISuite) TestBuildAPIUnnormalizedTarPaths(c *testing.T) {
// Make sure that build context tars with entries of the form // Make sure that build context tars with entries of the form
// x/./y don't cause caching false positives. // x/./y don't cause caching false positives.
@ -248,7 +248,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *testing.T) {
assert.Assert(c, imageA != imageB) assert.Assert(c, imageA != imageB)
} }
func (s *DockerSuite) TestBuildOnBuildWithCopy(c *testing.T) { func (s *DockerAPISuite) TestBuildOnBuildWithCopy(c *testing.T) {
dockerfile := ` dockerfile := `
FROM ` + minimalBaseImage() + ` as onbuildbase FROM ` + minimalBaseImage() + ` as onbuildbase
ONBUILD COPY file /file ONBUILD COPY file /file
@ -273,7 +273,7 @@ func (s *DockerSuite) TestBuildOnBuildWithCopy(c *testing.T) {
assert.Assert(c, is.Contains(string(out), "Successfully built")) assert.Assert(c, is.Contains(string(out), "Successfully built"))
} }
func (s *DockerSuite) TestBuildOnBuildCache(c *testing.T) { func (s *DockerAPISuite) TestBuildOnBuildCache(c *testing.T) {
build := func(dockerfile string) []byte { build := func(dockerfile string) []byte {
ctx := fakecontext.New(c, "", ctx := fakecontext.New(c, "",
fakecontext.WithDockerfile(dockerfile), fakecontext.WithDockerfile(dockerfile),
@ -352,7 +352,7 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *testing.T) {
assert.Check(c, is.Contains(string(out), "Successfully built")) assert.Check(c, is.Contains(string(out), "Successfully built"))
} }
func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *testing.T) { func (s *DockerAPISuite) TestBuildAddRemoteNoDecompress(c *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
tw := tar.NewWriter(buffer) tw := tar.NewWriter(buffer)
dt := []byte("contents") dt := []byte("contents")
@ -396,7 +396,7 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *testing.T) {
assert.Check(c, is.Contains(string(out), "Successfully built")) assert.Check(c, is.Contains(string(out), "Successfully built"))
} }
func (s *DockerSuite) TestBuildChownOnCopy(c *testing.T) { func (s *DockerAPISuite) TestBuildChownOnCopy(c *testing.T) {
// new feature added in 1.31 - https://github.com/moby/moby/pull/34263 // new feature added in 1.31 - https://github.com/moby/moby/pull/34263
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31")) testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31"))
dockerfile := `FROM busybox dockerfile := `FROM busybox
@ -426,7 +426,7 @@ func (s *DockerSuite) TestBuildChownOnCopy(c *testing.T) {
assert.Check(c, is.Contains(string(out), "Successfully built")) assert.Check(c, is.Contains(string(out), "Successfully built"))
} }
func (s *DockerSuite) TestBuildCopyCacheOnFileChange(c *testing.T) { func (s *DockerAPISuite) TestBuildCopyCacheOnFileChange(c *testing.T) {
dockerfile := `FROM busybox dockerfile := `FROM busybox
COPY file /file` COPY file /file`
@ -467,7 +467,7 @@ COPY file /file`
} }
} }
func (s *DockerSuite) TestBuildAddCacheOnFileChange(c *testing.T) { func (s *DockerAPISuite) TestBuildAddCacheOnFileChange(c *testing.T) {
dockerfile := `FROM busybox dockerfile := `FROM busybox
ADD file /file` ADD file /file`
@ -508,7 +508,7 @@ ADD file /file`
} }
} }
func (s *DockerSuite) TestBuildScratchCopy(c *testing.T) { func (s *DockerAPISuite) TestBuildScratchCopy(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerfile := `FROM scratch dockerfile := `FROM scratch
ADD Dockerfile / ADD Dockerfile /

View file

@ -13,7 +13,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestBuildWithRecycleBin(c *testing.T) { func (s *DockerAPISuite) TestBuildWithRecycleBin(c *testing.T) {
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
dockerfile := "" + dockerfile := "" +

View file

@ -36,7 +36,7 @@ import (
"gotest.tools/v3/poll" "gotest.tools/v3/poll"
) )
func (s *DockerSuite) TestContainerAPIGetAll(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) {
startCount := getContainerCount(c) startCount := getContainerCount(c)
name := "getall" name := "getall"
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
@ -56,7 +56,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *testing.T) {
} }
// regression test for empty json field being omitted #13691 // regression test for empty json field being omitted #13691
func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
startCount := getContainerCount(c) startCount := getContainerCount(c)
dockerCmd(c, "run", "busybox", "true") dockerCmd(c, "run", "busybox", "true")
@ -96,7 +96,7 @@ func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
} }
} }
func (s *DockerSuite) TestContainerAPIGetExport(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
// Not supported on Windows as Windows does not support docker export // Not supported on Windows as Windows does not support docker export
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "exportcontainer" name := "exportcontainer"
@ -123,7 +123,7 @@ func (s *DockerSuite) TestContainerAPIGetExport(c *testing.T) {
assert.Assert(c, found, "The created test file has not been found in the exported image") assert.Assert(c, found, "The created test file has not been found in the exported image")
} }
func (s *DockerSuite) TestContainerAPIGetChanges(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetChanges(c *testing.T) {
// Not supported on Windows as Windows does not support docker diff (/containers/name/changes) // Not supported on Windows as Windows does not support docker diff (/containers/name/changes)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "changescontainer" name := "changescontainer"
@ -146,7 +146,7 @@ func (s *DockerSuite) TestContainerAPIGetChanges(c *testing.T) {
assert.Assert(c, success, "/etc/passwd has been removed but is not present in the diff") assert.Assert(c, success, "/etc/passwd has been removed but is not present in the diff")
} }
func (s *DockerSuite) TestGetContainerStats(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
var ( var (
name = "statscontainer" name = "statscontainer"
) )
@ -186,7 +186,7 @@ func (s *DockerSuite) TestGetContainerStats(c *testing.T) {
} }
} }
func (s *DockerSuite) TestGetContainerStatsRmRunning(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -253,7 +253,7 @@ func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
// regression test for gh13421 // regression test for gh13421
// previous test was just checking one stat entry so it didn't fail (stats with // previous test was just checking one stat entry so it didn't fail (stats with
// stream false always return one stat) // stream false always return one stat)
func (s *DockerSuite) TestGetContainerStatsStream(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
name := "statscontainer" name := "statscontainer"
runSleepingContainer(c, "--name", name) runSleepingContainer(c, "--name", name)
@ -294,7 +294,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *testing.T) {
} }
} }
func (s *DockerSuite) TestGetContainerStatsNoStream(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
name := "statscontainer" name := "statscontainer"
runSleepingContainer(c, "--name", name) runSleepingContainer(c, "--name", name)
@ -334,7 +334,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *testing.T) {
} }
} }
func (s *DockerSuite) TestGetStoppedContainerStats(c *testing.T) { func (s *DockerAPISuite) TestGetStoppedContainerStats(c *testing.T) {
name := "statscontainer" name := "statscontainer"
dockerCmd(c, "create", "--name", name, "busybox", "ps") dockerCmd(c, "create", "--name", name, "busybox", "ps")
@ -361,7 +361,7 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *testing.T) {
} }
} }
func (s *DockerSuite) TestContainerAPIPause(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIPause(c *testing.T) {
// Problematic on Windows as Windows does not support pause // Problematic on Windows as Windows does not support pause
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -392,7 +392,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *testing.T) {
assert.Equal(c, len(pausedContainers), 0, "There should be no paused container.") assert.Equal(c, len(pausedContainers), 0, "There should be no paused container.")
} }
func (s *DockerSuite) TestContainerAPITop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -415,7 +415,7 @@ func (s *DockerSuite) TestContainerAPITop(c *testing.T) {
assert.Equal(c, top.Processes[1][10], "top") assert.Equal(c, top.Processes[1][10], "top")
} }
func (s *DockerSuite) TestContainerAPITopWindows(c *testing.T) { func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) {
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -446,7 +446,7 @@ func (s *DockerSuite) TestContainerAPITopWindows(c *testing.T) {
assert.Assert(c, foundProcess, "expected to find %s: %v", expectedProcess, top.Processes) assert.Assert(c, foundProcess, "expected to find %s: %v", expectedProcess, top.Processes)
} }
func (s *DockerSuite) TestContainerAPICommit(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
cName := "testapicommit" cName := "testapicommit"
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
@ -468,7 +468,7 @@ func (s *DockerSuite) TestContainerAPICommit(c *testing.T) {
dockerCmd(c, "run", img.ID, "ls", "/test") dockerCmd(c, "run", img.ID, "ls", "/test")
} }
func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
cName := "testapicommitwithconfig" cName := "testapicommitwithconfig"
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
@ -500,7 +500,7 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
dockerCmd(c, "run", img.ID, "ls", "/test") dockerCmd(c, "run", img.ID, "ls", "/test")
} }
func (s *DockerSuite) TestContainerAPIBadPort(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIBadPort(c *testing.T) {
// TODO Windows to Windows CI - Port this test // TODO Windows to Windows CI - Port this test
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -527,7 +527,7 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *testing.T) {
assert.ErrorContains(c, err, `invalid port specification: "aa80"`) assert.ErrorContains(c, err, `invalid port specification: "aa80"`)
} }
func (s *DockerSuite) TestContainerAPICreate(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreate(c *testing.T) {
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
Cmd: []string{"/bin/sh", "-c", "touch /test && ls /test"}, Cmd: []string{"/bin/sh", "-c", "touch /test && ls /test"},
@ -544,7 +544,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "/test") assert.Equal(c, strings.TrimSpace(out), "/test")
} }
func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateEmptyConfig(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -556,7 +556,7 @@ func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *testing.T) {
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
} }
func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T) {
// Container creation must fail if client specified configurations for more than one network // Container creation must fail if client specified configurations for more than one network
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
@ -583,13 +583,13 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T)
assert.Assert(c, strings.Contains(msg, "net3")) assert.Assert(c, strings.Contains(msg, "net3"))
} }
func (s *DockerSuite) TestContainerAPICreateBridgeNetworkMode(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateBridgeNetworkMode(c *testing.T) {
// Windows does not support bridge // Windows does not support bridge
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
UtilCreateNetworkMode(c, "bridge") UtilCreateNetworkMode(c, "bridge")
} }
func (s *DockerSuite) TestContainerAPICreateOtherNetworkModes(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateOtherNetworkModes(c *testing.T) {
// Windows does not support these network modes // Windows does not support these network modes
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
UtilCreateNetworkMode(c, "host") UtilCreateNetworkMode(c, "host")
@ -618,7 +618,7 @@ func UtilCreateNetworkMode(c *testing.T, networkMode container.NetworkMode) {
assert.Equal(c, containerJSON.HostConfig.NetworkMode, networkMode, "Mismatched NetworkMode") assert.Equal(c, containerJSON.HostConfig.NetworkMode, networkMode, "Mismatched NetworkMode")
} }
func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) {
// TODO Windows to Windows CI. The CpuShares part could be ported. // TODO Windows to Windows CI. The CpuShares part could be ported.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := container.Config{ config := container.Config{
@ -649,7 +649,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) {
assert.Equal(c, outCpuset, "0") assert.Equal(c, outCpuset, "0")
} }
func (s *DockerSuite) TestContainerAPIVerifyHeader(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIVerifyHeader(c *testing.T) {
config := map[string]interface{}{ config := map[string]interface{}{
"Image": "busybox", "Image": "busybox",
} }
@ -690,7 +690,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *testing.T) {
} }
// Issue 14230. daemon should return 500 for invalid port syntax // Issue 14230. daemon should return 500 for invalid port syntax
func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIInvalidPortSyntax(c *testing.T) {
config := `{ config := `{
"Image": "busybox", "Image": "busybox",
"HostConfig": { "HostConfig": {
@ -716,7 +716,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *testing.T) {
assert.Assert(c, strings.Contains(string(b[:]), "invalid port")) assert.Assert(c, strings.Contains(string(b[:]), "invalid port"))
} }
func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *testing.T) {
config := `{ config := `{
"Image": "busybox", "Image": "busybox",
"HostConfig": { "HostConfig": {
@ -740,7 +740,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *testing.
assert.Assert(c, strings.Contains(string(b[:]), "invalid restart policy")) assert.Assert(c, strings.Contains(string(b[:]), "invalid restart policy"))
} }
func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartPolicyRetryMismatch(c *testing.T) {
config := `{ config := `{
"Image": "busybox", "Image": "busybox",
"HostConfig": { "HostConfig": {
@ -764,7 +764,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *testing.T) {
assert.Assert(c, strings.Contains(string(b[:]), "maximum retry count cannot be used with restart policy")) assert.Assert(c, strings.Contains(string(b[:]), "maximum retry count cannot be used with restart policy"))
} }
func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *testing.T) {
config := `{ config := `{
"Image": "busybox", "Image": "busybox",
"HostConfig": { "HostConfig": {
@ -788,7 +788,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *testing
assert.Assert(c, strings.Contains(string(b[:]), "maximum retry count cannot be negative")) assert.Assert(c, strings.Contains(string(b[:]), "maximum retry count cannot be negative"))
} }
func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *testing.T) {
config := `{ config := `{
"Image": "busybox", "Image": "busybox",
"HostConfig": { "HostConfig": {
@ -806,7 +806,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *testing.
// Issue 7941 - test to make sure a "null" in JSON is just ignored. // Issue 7941 - test to make sure a "null" in JSON is just ignored.
// W/o this fix a null in JSON would be parsed into a string var as "null" // W/o this fix a null in JSON would be parsed into a string var as "null"
func (s *DockerSuite) TestContainerAPIPostCreateNull(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIPostCreateNull(c *testing.T) {
config := `{ config := `{
"Hostname":"", "Hostname":"",
"Domainname":"", "Domainname":"",
@ -850,7 +850,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *testing.T) {
assert.Equal(c, outMemorySwap, "0") assert.Equal(c, outMemorySwap, "0")
} }
func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *testing.T) { func (s *DockerAPISuite) TestCreateWithTooLowMemoryLimit(c *testing.T) {
// TODO Windows: Port once memory is supported // TODO Windows: Port once memory is supported
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := `{ config := `{
@ -874,7 +874,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *testing.T) {
assert.Assert(c, strings.Contains(string(b), "Minimum memory limit allowed is 6MB")) assert.Assert(c, strings.Contains(string(b), "Minimum memory limit allowed is 6MB"))
} }
func (s *DockerSuite) TestContainerAPIRename(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) {
out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh") out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -891,7 +891,7 @@ func (s *DockerSuite) TestContainerAPIRename(c *testing.T) {
assert.Equal(c, name, "/"+newName, "Failed to rename container") assert.Equal(c, name, "/"+newName, "Failed to rename container")
} }
func (s *DockerSuite) TestContainerAPIKill(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) {
name := "test-api-kill" name := "test-api-kill"
runSleepingContainer(c, "-i", "--name", name) runSleepingContainer(c, "-i", "--name", name)
@ -906,7 +906,7 @@ func (s *DockerSuite) TestContainerAPIKill(c *testing.T) {
assert.Equal(c, state, "false", fmt.Sprintf("got wrong State from container %s: %q", name, state)) assert.Equal(c, state, "false", fmt.Sprintf("got wrong State from container %s: %q", name, state))
} }
func (s *DockerSuite) TestContainerAPIRestart(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) {
name := "test-api-restart" name := "test-api-restart"
runSleepingContainer(c, "-di", "--name", name) runSleepingContainer(c, "-di", "--name", name)
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
@ -920,7 +920,7 @@ func (s *DockerSuite) TestContainerAPIRestart(c *testing.T) {
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil) assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
} }
func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
name := "test-api-restart-no-timeout-param" name := "test-api-restart-no-timeout-param"
out := runSleepingContainer(c, "-di", "--name", name) out := runSleepingContainer(c, "-di", "--name", name)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -936,7 +936,7 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil) assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
} }
func (s *DockerSuite) TestContainerAPIStart(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
name := "testing-start" name := "testing-start"
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
@ -962,7 +962,7 @@ func (s *DockerSuite) TestContainerAPIStart(c *testing.T) {
// TODO(tibor): figure out why this doesn't work on windows // TODO(tibor): figure out why this doesn't work on windows
} }
func (s *DockerSuite) TestContainerAPIStop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) {
name := "test-api-stop" name := "test-api-stop"
runSleepingContainer(c, "-i", "--name", name) runSleepingContainer(c, "-i", "--name", name)
timeout := 30 timeout := 30
@ -985,7 +985,7 @@ func (s *DockerSuite) TestContainerAPIStop(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestContainerAPIWait(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) {
name := "test-api-wait" name := "test-api-wait"
sleepCmd := "/bin/sleep" sleepCmd := "/bin/sleep"
@ -1008,7 +1008,7 @@ func (s *DockerSuite) TestContainerAPIWait(c *testing.T) {
} }
} }
func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
name := "test-container-api-copy" name := "test-container-api-copy"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
@ -1021,7 +1021,7 @@ func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
assert.Equal(c, res.StatusCode, http.StatusNotFound) assert.Equal(c, res.StatusCode, http.StatusNotFound)
} }
func (s *DockerSuite) TestContainerAPICopyPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy" name := "test-container-api-copy"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
@ -1051,7 +1051,7 @@ func (s *DockerSuite) TestContainerAPICopyPre124(c *testing.T) {
assert.Assert(c, found) assert.Assert(c, found)
} }
func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy-resource-empty" name := "test-container-api-copy-resource-empty"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
@ -1073,7 +1073,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T)
} }
func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy-resource-not-found" name := "test-container-api-copy-resource-not-found"
dockerCmd(c, "run", "--name", name, "busybox") dockerCmd(c, "run", "--name", name, "busybox")
@ -1095,7 +1095,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.
} }
func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/something", Resource: "/something",
@ -1106,7 +1106,7 @@ func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T) {
assert.Equal(c, res.StatusCode, http.StatusNotFound) assert.Equal(c, res.StatusCode, http.StatusNotFound)
} }
func (s *DockerSuite) TestContainerAPIDelete(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -1122,7 +1122,7 @@ func (s *DockerSuite) TestContainerAPIDelete(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteNotExist(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer cli.Close() defer cli.Close()
@ -1131,7 +1131,7 @@ func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *testing.T) {
assert.ErrorContains(c, err, "No such container: doesnotexist") assert.ErrorContains(c, err, "No such container: doesnotexist")
} }
func (s *DockerSuite) TestContainerAPIDeleteForce(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
@ -1148,7 +1148,7 @@ func (s *DockerSuite) TestContainerAPIDeleteForce(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
// Windows does not support links // Windows does not support links
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
@ -1179,7 +1179,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
assert.Equal(c, linksPostRm, "null", "call to api deleteContainer links should have removed the specified links") assert.Equal(c, linksPostRm, "null", "call to api deleteContainer links should have removed the specified links")
} }
func (s *DockerSuite) TestContainerAPIDeleteConflict(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteConflict(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -1194,7 +1194,7 @@ func (s *DockerSuite) TestContainerAPIDeleteConflict(c *testing.T) {
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
} }
func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
vol := "/testvolume" vol := "/testvolume"
@ -1229,7 +1229,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
} }
// Regression test for https://github.com/docker/docker/issues/6231 // Regression test for https://github.com/docker/docker/issues/6231
func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIChunkedEncoding(c *testing.T) {
config := map[string]interface{}{ config := map[string]interface{}{
"Image": "busybox", "Image": "busybox",
@ -1249,7 +1249,7 @@ func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *testing.T) {
assert.Equal(c, resp.StatusCode, http.StatusCreated) assert.Equal(c, resp.StatusCode, http.StatusCreated)
} }
func (s *DockerSuite) TestContainerAPIPostContainerStop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -1265,7 +1265,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *testing.T) {
} }
// #14170 // #14170
func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *testing.T) { func (s *DockerAPISuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *testing.T) {
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
Entrypoint: []string{"echo"}, Entrypoint: []string{"echo"},
@ -1293,7 +1293,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *t
} }
// #14170 // #14170
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T) {
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
Cmd: []string{"echo", "hello", "world"}, Cmd: []string{"echo", "hello", "world"},
@ -1322,7 +1322,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T)
// regression #14318 // regression #14318
// for backward compatibility testing with and without CAP_ prefix // for backward compatibility testing with and without CAP_ prefix
// and with upper and lowercase // and with upper and lowercase
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *testing.T) {
// Windows doesn't support CapAdd/CapDrop // Windows doesn't support CapAdd/CapDrop
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := struct { config := struct {
@ -1351,7 +1351,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *tes
} }
// #14915 // #14915
func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateNoHostConfig118(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only support 1.25 or later testRequires(c, DaemonIsLinux) // Windows only support 1.25 or later
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
@ -1367,7 +1367,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *testing.T) {
// Ensure an error occurs when you have a container read-only rootfs but you // Ensure an error occurs when you have a container read-only rootfs but you
// extract an archive to a symlink in a writable volume which points to a // extract an archive to a symlink in a writable volume which points to a
// directory outside of the volume. // directory outside of the volume.
func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(c *testing.T) { func (s *DockerAPISuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(c *testing.T) {
// Windows does not support read-only rootfs // Windows does not support read-only rootfs
// Requires local volume mount bind. // Requires local volume mount bind.
// --read-only + userns has remount issues // --read-only + userns has remount issues
@ -1393,7 +1393,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
assert.ErrorContains(c, err, "container rootfs is marked read-only") assert.ErrorContains(c, err, "container rootfs is marked read-only")
} }
func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T) {
// Not supported on Windows // Not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -1426,7 +1426,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
} }
func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateShmSizeNegative(c *testing.T) {
// ShmSize is not supported on Windows // ShmSize is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := container.Config{ config := container.Config{
@ -1444,7 +1444,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) {
assert.ErrorContains(c, err, "SHM size can not be less than 0") assert.ErrorContains(c, err, "SHM size can not be less than 0")
} }
func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testing.T) {
// ShmSize is not supported on Windows // ShmSize is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -1472,7 +1472,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testin
} }
} }
func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) {
// ShmSize is not supported on Windows // ShmSize is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := container.Config{ config := container.Config{
@ -1499,7 +1499,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) {
} }
} }
func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateWithShmSize(c *testing.T) {
// ShmSize is not supported on Windows // ShmSize is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := container.Config{ config := container.Config{
@ -1530,7 +1530,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) {
} }
} }
func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *testing.T) {
// Swappiness is not supported on Windows // Swappiness is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
config := container.Config{ config := container.Config{
@ -1555,7 +1555,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
} }
// check validation is done daemon side and not only in cli // check validation is done daemon side and not only in cli
func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *testing.T) { func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *testing.T) {
// OomScoreAdj is not supported on Windows // OomScoreAdj is not supported on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -1589,7 +1589,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *tes
} }
// test case for #22210 where an empty container name caused panic. // test case for #22210 where an empty container name caused panic.
func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer cli.Close() defer cli.Close()
@ -1598,7 +1598,7 @@ func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) {
assert.Check(c, errdefs.IsNotFound(err)) assert.Check(c, errdefs.IsNotFound(err))
} }
func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) {
// Problematic on Windows as Windows does not support stats // Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -1647,7 +1647,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) {
} }
} }
func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { func (s *DockerAPISuite) TestContainersAPICreateMountsValidation(c *testing.T) {
type testCase struct { type testCase struct {
config container.Config config container.Config
hostConfig container.HostConfig hostConfig container.HostConfig
@ -1940,7 +1940,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) {
} }
} }
func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon) testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon)
// also with data in the host side // also with data in the host side
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
@ -1971,7 +1971,7 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
} }
// Test Mounts comes out as expected for the MountPoint // Test Mounts comes out as expected for the MountPoint
func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
destPath := prefix + slash + "foo" destPath := prefix + slash + "foo"
@ -2180,7 +2180,7 @@ func containerExit(apiclient client.APIClient, name string) func(poll.LogT) poll
} }
} }
func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *testing.T) { func (s *DockerAPISuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
type testCase struct { type testCase struct {
cfg mount.Mount cfg mount.Mount
@ -2230,7 +2230,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
// Regression test for #33334 // Regression test for #33334
// Makes sure that when a container which has a custom stop signal + restart=always // Makes sure that when a container which has a custom stop signal + restart=always
// gets killed (with SIGKILL) by the kill API, that the restart policy is cancelled. // gets killed (with SIGKILL) by the kill API, that the restart policy is cancelled.
func (s *DockerSuite) TestContainerKillCustomStopSignal(c *testing.T) { func (s *DockerAPISuite) TestContainerKillCustomStopSignal(c *testing.T) {
id := strings.TrimSpace(runSleepingContainer(c, "--stop-signal=SIGTERM", "--restart=always")) id := strings.TrimSpace(runSleepingContainer(c, "--stop-signal=SIGTERM", "--restart=always"))
res, _, err := request.Post("/containers/" + id + "/kill") res, _, err := request.Post("/containers/" + id + "/kill")
assert.NilError(c, err) assert.NilError(c, err)

View file

@ -20,7 +20,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T) { func (s *DockerAPISuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T) {
// Create a host pipe to map into the container // Create a host pipe to map into the container
hostPipeName := fmt.Sprintf(`\\.\pipe\docker-cli-test-pipe-%x`, rand.Uint64()) hostPipeName := fmt.Sprintf(`\\.\pipe\docker-cli-test-pipe-%x`, rand.Uint64())
pc := &winio.PipeConfig{ pc := &winio.PipeConfig{

View file

@ -16,7 +16,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) { func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -32,7 +32,7 @@ func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
} }
// Part of #14845 // Part of #14845
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) { func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
name := "exec_resize_test" name := "exec_resize_test"
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")

View file

@ -23,7 +23,7 @@ import (
) )
// Regression test for #9414 // Regression test for #9414
func (s *DockerSuite) TestExecAPICreateNoCmd(c *testing.T) { func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
@ -39,7 +39,7 @@ func (s *DockerSuite) TestExecAPICreateNoCmd(c *testing.T) {
assert.Assert(c, strings.Contains(getErrorMessage(c, b), "No exec command specified"), "Expected message when creating exec command with no Cmd specified") assert.Assert(c, strings.Contains(getErrorMessage(c, b), "No exec command specified"), "Expected message when creating exec command with no Cmd specified")
} }
func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *testing.T) { func (s *DockerAPISuite) TestExecAPICreateNoValidContentType(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
@ -60,7 +60,7 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *testing.T) {
assert.Assert(c, is.Contains(getErrorMessage(c, b), "unsupported Content-Type header (test/plain): must be 'application/json'")) assert.Assert(c, is.Contains(getErrorMessage(c, b), "unsupported Content-Type header (test/plain): must be 'application/json'"))
} }
func (s *DockerSuite) TestExecAPICreateContainerPaused(c *testing.T) { func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
// Not relevant on Windows as Windows containers cannot be paused // Not relevant on Windows as Windows containers cannot be paused
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "exec_create_test" name := "exec_create_test"
@ -79,7 +79,7 @@ func (s *DockerSuite) TestExecAPICreateContainerPaused(c *testing.T) {
assert.ErrorContains(c, err, "Container "+name+" is paused, unpause the container before exec", "Expected message when creating exec command with Container %s is paused", name) assert.ErrorContains(c, err, "Container "+name+" is paused, unpause the container before exec", "Expected message when creating exec command with Container %s is paused", name)
} }
func (s *DockerSuite) TestExecAPIStart(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) {
testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
@ -106,7 +106,7 @@ func (s *DockerSuite) TestExecAPIStart(c *testing.T) {
startExec(c, id, http.StatusOK) startExec(c, id, http.StatusOK)
} }
func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartEnsureHeaders(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
@ -116,7 +116,7 @@ func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *testing.T) {
assert.Assert(c, resp.Header.Get("Server") != "") assert.Assert(c, resp.Header.Get("Server") != "")
} }
func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartBackwardsCompatible(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
runSleepingContainer(c, "-d", "--name", "test") runSleepingContainer(c, "-d", "--name", "test")
id := createExec(c, "test") id := createExec(c, "test")
@ -131,7 +131,7 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *testing.T) {
} }
// #19362 // #19362
func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartMultipleTimesError(c *testing.T) {
runSleepingContainer(c, "-d", "--name", "test") runSleepingContainer(c, "-d", "--name", "test")
execID := createExec(c, "test") execID := createExec(c, "test")
startExec(c, execID, http.StatusOK) startExec(c, execID, http.StatusOK)
@ -141,7 +141,7 @@ func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *testing.T) {
} }
// #20638 // #20638
func (s *DockerSuite) TestExecAPIStartWithDetach(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartWithDetach(c *testing.T) {
name := "foo" name := "foo"
runSleepingContainer(c, "-d", "-t", "--name", name) runSleepingContainer(c, "-d", "-t", "--name", name)
@ -172,7 +172,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *testing.T) {
} }
// #30311 // #30311
func (s *DockerSuite) TestExecAPIStartValidCommand(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
@ -188,7 +188,7 @@ func (s *DockerSuite) TestExecAPIStartValidCommand(c *testing.T) {
} }
// #30311 // #30311
func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartInvalidCommand(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
@ -206,7 +206,7 @@ func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *testing.T) {
assert.Assert(c, inspectJSON.ExecIDs == nil) assert.Assert(c, inspectJSON.ExecIDs == nil)
} }
func (s *DockerSuite) TestExecStateCleanup(c *testing.T) { func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
// This test checks accidental regressions. Not part of stable API. // This test checks accidental regressions. Not part of stable API.

View file

@ -16,7 +16,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestAPIImagesFilter(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesFilter(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer cli.Close() defer cli.Close()
@ -54,7 +54,7 @@ func (s *DockerSuite) TestAPIImagesFilter(c *testing.T) {
assert.Equal(c, len(images[0].RepoTags), 1) assert.Equal(c, len(images[0].RepoTags), 1)
} }
func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesSaveAndLoad(c *testing.T) {
testRequires(c, Network) testRequires(c, Network)
buildImageSuccessfully(c, "saveandload", build.WithDockerfile("FROM busybox\nENV FOO bar")) buildImageSuccessfully(c, "saveandload", build.WithDockerfile("FROM busybox\nENV FOO bar"))
id := getIDByName(c, "saveandload") id := getIDByName(c, "saveandload")
@ -75,7 +75,7 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *testing.T) {
assert.Equal(c, strings.TrimSpace(inspectOut), id, "load did not work properly") assert.Equal(c, strings.TrimSpace(inspectOut), id, "load did not work properly")
} }
func (s *DockerSuite) TestAPIImagesDelete(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesDelete(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer cli.Close() defer cli.Close()
@ -99,7 +99,7 @@ func (s *DockerSuite) TestAPIImagesDelete(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestAPIImagesHistory(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesHistory(c *testing.T) {
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer cli.Close() defer cli.Close()
@ -125,7 +125,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *testing.T) {
assert.Assert(c, found) assert.Assert(c, found)
} }
func (s *DockerSuite) TestAPIImagesImportBadSrc(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesImportBadSrc(c *testing.T) {
testRequires(c, Network, testEnv.IsLocalDaemon) testRequires(c, Network, testEnv.IsLocalDaemon)
server := httptest.NewServer(http.NewServeMux()) server := httptest.NewServer(http.NewServeMux())
@ -151,7 +151,7 @@ func (s *DockerSuite) TestAPIImagesImportBadSrc(c *testing.T) {
} }
// #14846 // #14846
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesSearchJSONContentType(c *testing.T) {
testRequires(c, Network) testRequires(c, Network)
res, b, err := request.Get("/images/search?term=test", request.JSON) res, b, err := request.Get("/images/search?term=test", request.JSON)
@ -163,7 +163,7 @@ func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *testing.T) {
// Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon. // Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon.
// This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix. // This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix.
func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *testing.T) { func (s *DockerAPISuite) TestAPIImagesSizeCompatibility(c *testing.T) {
apiclient := testEnv.APIClient() apiclient := testEnv.APIClient()
defer apiclient.Close() defer apiclient.Close()

View file

@ -13,7 +13,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestInspectAPIContainerResponse(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -57,7 +57,7 @@ func (s *DockerSuite) TestInspectAPIContainerResponse(c *testing.T) {
} }
} }
func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
// No legacy implications for Windows // No legacy implications for Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
@ -80,7 +80,7 @@ func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
} }
} }
func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -104,7 +104,7 @@ func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
assert.Assert(c, ok, "API version 1.25 expected to include VolumeDriver in 'HostConfig'") assert.Assert(c, ok, "API version 1.25 expected to include VolumeDriver in 'HostConfig'")
} }
func (s *DockerSuite) TestInspectAPIImageResponse(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
dockerCmd(c, "tag", "busybox:latest", "busybox:mytag") dockerCmd(c, "tag", "busybox:latest", "busybox:mytag")
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -119,7 +119,7 @@ func (s *DockerSuite) TestInspectAPIImageResponse(c *testing.T) {
} }
// #17131, #17139, #17173 // #17131, #17139, #17173
func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
// Not relevant on Windows // Not relevant on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
@ -143,7 +143,7 @@ func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
} }
} }
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
// Not relevant on Windows, and besides it doesn't have any bridge network settings // Not relevant on Windows, and besides it doesn't have any bridge network settings
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
@ -160,7 +160,7 @@ func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
assert.Assert(c, len(settings.IPAddress) != 0) assert.Assert(c, len(settings.IPAddress) != 0)
} }
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) {
// Windows doesn't have any bridge network settings // Windows doesn't have any bridge network settings
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")

View file

@ -19,7 +19,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestLogsAPIWithStdout(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
@ -55,7 +55,7 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *testing.T) { func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
name := "logs_test" name := "logs_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
@ -67,7 +67,7 @@ func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
} }
// Regression test for #12704 // Regression test for #12704
func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIFollowEmptyOutput(c *testing.T) {
name := "logs_test" name := "logs_test"
t0 := time.Now() t0 := time.Now()
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
@ -82,14 +82,14 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIContainerNotFound(c *testing.T) {
name := "nonExistentContainer" name := "nonExistentContainer"
resp, _, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name)) resp, _, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, resp.StatusCode, http.StatusNotFound) assert.Equal(c, resp.StatusCode, http.StatusNotFound)
} }
func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "logsuntilfuturefollow" name := "logsuntilfuturefollow"
dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done") dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done")
@ -157,7 +157,7 @@ func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsAPIUntil(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) {
testRequires(c, MinimumAPIVersion("1.34")) testRequires(c, MinimumAPIVersion("1.34"))
name := "logsuntil" name := "logsuntil"
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done") dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")
@ -195,7 +195,7 @@ func (s *DockerSuite) TestLogsAPIUntil(c *testing.T) {
assert.Assert(c, !strings.Contains(logsString, "log3"), "unexpected log message returned, until=%v", until) assert.Assert(c, !strings.Contains(logsString, "log3"), "unexpected log message returned, until=%v", until)
} }
func (s *DockerSuite) TestLogsAPIUntilDefaultValue(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntilDefaultValue(c *testing.T) {
name := "logsuntildefaultval" name := "logsuntildefaultval"
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done") dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done")

View file

@ -17,7 +17,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestAPINetworkGetDefaults(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkGetDefaults(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// By default docker daemon creates 3 networks. check if they are present // By default docker daemon creates 3 networks. check if they are present
defaults := []string{"bridge", "host", "none"} defaults := []string{"bridge", "host", "none"}
@ -26,7 +26,7 @@ func (s *DockerSuite) TestAPINetworkGetDefaults(c *testing.T) {
} }
} }
func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkCreateCheckDuplicate(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testcheckduplicate" name := "testcheckduplicate"
configOnCheck := types.NetworkCreateRequest{ configOnCheck := types.NetworkCreateRequest{
@ -64,13 +64,13 @@ func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *testing.T) {
createNetwork(c, configNotCheck, http.StatusCreated) createNetwork(c, configNotCheck, http.StatusCreated)
} }
func (s *DockerSuite) TestAPINetworkFilter(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkFilter(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
nr := getNetworkResource(c, getNetworkIDByName(c, "bridge")) nr := getNetworkResource(c, getNetworkIDByName(c, "bridge"))
assert.Equal(c, nr.Name, "bridge") assert.Equal(c, nr.Name, "bridge")
} }
func (s *DockerSuite) TestAPINetworkInspectBridge(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkInspectBridge(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Inspect default bridge network // Inspect default bridge network
nr := getNetworkResource(c, "bridge") nr := getNetworkResource(c, "bridge")
@ -96,7 +96,7 @@ func (s *DockerSuite) TestAPINetworkInspectBridge(c *testing.T) {
assert.Equal(c, ip.String(), containerIP) assert.Equal(c, ip.String(), containerIP)
} }
func (s *DockerSuite) TestAPINetworkInspectUserDefinedNetwork(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkInspectUserDefinedNetwork(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// IPAM configuration inspect // IPAM configuration inspect
ipam := &network.IPAM{ ipam := &network.IPAM{
@ -127,7 +127,7 @@ func (s *DockerSuite) TestAPINetworkInspectUserDefinedNetwork(c *testing.T) {
assert.Assert(c, !isNetworkAvailable(c, "br0")) assert.Assert(c, !isNetworkAvailable(c, "br0"))
} }
func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkConnectDisconnect(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Create test network // Create test network
name := "testnetwork" name := "testnetwork"
@ -169,7 +169,7 @@ func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *testing.T) {
deleteNetwork(c, nr.ID, true) deleteNetwork(c, nr.ID, true)
} }
func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) { func (s *DockerAPISuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// test0 bridge network // test0 bridge network
ipam0 := &network.IPAM{ ipam0 := &network.IPAM{
@ -238,7 +238,7 @@ func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) {
} }
} }
func (s *DockerSuite) TestAPICreateDeletePredefinedNetworks(c *testing.T) { func (s *DockerAPISuite) TestAPICreateDeletePredefinedNetworks(c *testing.T) {
testRequires(c, DaemonIsLinux, SwarmInactive) testRequires(c, DaemonIsLinux, SwarmInactive)
createDeletePredefinedNetwork(c, "bridge") createDeletePredefinedNetwork(c, "bridge")
createDeletePredefinedNetwork(c, "none") createDeletePredefinedNetwork(c, "none")

View file

@ -23,7 +23,7 @@ import (
var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors rx_packets tx_bytes tx_dropped tx_errors tx_packets", " ") var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors rx_packets tx_bytes tx_dropped tx_errors tx_packets", " ")
func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done")
@ -64,7 +64,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
assert.Assert(c, cpuPercent != 0.0, "docker stats with no-stream get cpu usage failed: was %v", cpuPercent) assert.Assert(c, cpuPercent != 0.0, "docker stats with no-stream get cpu usage failed: was %v", cpuPercent)
} }
func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -99,7 +99,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) {
} }
} }
func (s *DockerSuite) TestAPIStatsNetworkStats(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNetworkStats(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
@ -165,7 +165,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStats(c *testing.T) {
assert.Assert(c, postRxPackets >= expRxPkts, "Reported less RxPackets than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts) assert.Assert(c, postRxPackets >= expRxPkts, "Reported less RxPackets than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts)
} }
func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) {
// Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21 // Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
@ -260,7 +260,7 @@ func jsonBlobHasGTE121NetworkStats(blob map[string]interface{}) bool {
return true return true
} }
func (s *DockerSuite) TestAPIStatsContainerNotFound(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsContainerNotFound(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
cli, err := client.NewClientWithOpts(client.FromEnv) cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -274,7 +274,7 @@ func (s *DockerSuite) TestAPIStatsContainerNotFound(c *testing.T) {
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
} }
func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out1 := runSleepingContainer(c) out1 := runSleepingContainer(c)

View file

@ -15,13 +15,25 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestAPIOptionsRoute(c *testing.T) { type DockerAPISuite struct {
ds *DockerSuite
}
func (s *DockerAPISuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerAPISuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerAPISuite) TestAPIOptionsRoute(c *testing.T) {
resp, _, err := request.Do("/", request.Method(http.MethodOptions)) resp, _, err := request.Do("/", request.Method(http.MethodOptions))
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, resp.StatusCode, http.StatusOK) assert.Equal(c, resp.StatusCode, http.StatusOK)
} }
func (s *DockerSuite) TestAPIGetEnabledCORS(c *testing.T) { func (s *DockerAPISuite) TestAPIGetEnabledCORS(c *testing.T) {
res, body, err := request.Get("/version") res, body, err := request.Get("/version")
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, res.StatusCode, http.StatusOK) assert.Equal(c, res.StatusCode, http.StatusOK)
@ -33,7 +45,7 @@ func (s *DockerSuite) TestAPIGetEnabledCORS(c *testing.T) {
//assert.Equal(c, res.Header.Get("Access-Control-Allow-Headers"), "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth") //assert.Equal(c, res.Header.Get("Access-Control-Allow-Headers"), "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
} }
func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *testing.T) { func (s *DockerAPISuite) TestAPIClientVersionOldNotSupported(c *testing.T) {
if testEnv.OSType != runtime.GOOS { if testEnv.OSType != runtime.GOOS {
c.Skip("Daemon platform doesn't match test platform") c.Skip("Daemon platform doesn't match test platform")
} }
@ -57,7 +69,7 @@ func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *testing.T) {
assert.Equal(c, strings.TrimSpace(string(content)), expected) assert.Equal(c, strings.TrimSpace(string(content)), expected)
} }
func (s *DockerSuite) TestAPIErrorJSON(c *testing.T) { func (s *DockerAPISuite) TestAPIErrorJSON(c *testing.T) {
httpResp, body, err := request.Post("/containers/create", request.JSONBody(struct{}{})) httpResp, body, err := request.Post("/containers/create", request.JSONBody(struct{}{}))
assert.NilError(c, err) assert.NilError(c, err)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") { if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
@ -71,7 +83,7 @@ func (s *DockerSuite) TestAPIErrorJSON(c *testing.T) {
assert.Equal(c, getErrorMessage(c, b), "Config cannot be empty in order to create a container") assert.Equal(c, getErrorMessage(c, b), "Config cannot be empty in order to create a container")
} }
func (s *DockerSuite) TestAPIErrorPlainText(c *testing.T) { func (s *DockerAPISuite) TestAPIErrorPlainText(c *testing.T) {
// Windows requires API 1.25 or later. This test is validating a behaviour which was present // Windows requires API 1.25 or later. This test is validating a behaviour which was present
// in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors // in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -88,7 +100,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *testing.T) {
assert.Equal(c, strings.TrimSpace(string(b)), "Config cannot be empty in order to create a container") assert.Equal(c, strings.TrimSpace(string(b)), "Config cannot be empty in order to create a container")
} }
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *testing.T) { func (s *DockerAPISuite) TestAPIErrorNotFoundJSON(c *testing.T) {
// 404 is a different code path to normal errors, so test separately // 404 is a different code path to normal errors, so test separately
httpResp, body, err := request.Get("/notfound", request.JSON) httpResp, body, err := request.Get("/notfound", request.JSON)
assert.NilError(c, err) assert.NilError(c, err)
@ -99,7 +111,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *testing.T) {
assert.Equal(c, getErrorMessage(c, b), "page not found") assert.Equal(c, getErrorMessage(c, b), "page not found")
} }
func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *testing.T) { func (s *DockerAPISuite) TestAPIErrorNotFoundPlainText(c *testing.T) {
httpResp, body, err := request.Get("/v1.23/notfound", request.JSON) httpResp, body, err := request.Get("/v1.23/notfound", request.JSON)
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, httpResp.StatusCode, http.StatusNotFound) assert.Equal(c, httpResp.StatusCode, http.StatusNotFound)

View file

@ -18,7 +18,19 @@ import (
const attachWait = 5 * time.Second const attachWait = 5 * time.Second
func (s *DockerSuite) TestAttachMultipleAndRestart(c *testing.T) { type DockerCLIAttachSuite struct {
ds *DockerSuite
}
func (s *DockerCLIAttachSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIAttachSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIAttachSuite) TestAttachMultipleAndRestart(c *testing.T) {
endGroup := &sync.WaitGroup{} endGroup := &sync.WaitGroup{}
startGroup := &sync.WaitGroup{} startGroup := &sync.WaitGroup{}
endGroup.Add(3) endGroup.Add(3)
@ -88,7 +100,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *testing.T) {
} }
} }
func (s *DockerSuite) TestAttachTTYWithoutStdin(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
// TODO: Figure out how to get this running again reliable on Windows. // TODO: Figure out how to get this running again reliable on Windows.
// It works by accident at the moment. Sometimes. I've gone back to v1.13.0 and see the same. // It works by accident at the moment. Sometimes. I've gone back to v1.13.0 and see the same.
// On Windows, docker run -d -ti busybox causes the container to exit immediately. // On Windows, docker run -d -ti busybox causes the container to exit immediately.
@ -133,7 +145,7 @@ func (s *DockerSuite) TestAttachTTYWithoutStdin(c *testing.T) {
} }
} }
func (s *DockerSuite) TestAttachDisconnect(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat") out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -166,7 +178,7 @@ func (s *DockerSuite) TestAttachDisconnect(c *testing.T) {
assert.Equal(c, running, "true") assert.Equal(c, running, "true")
} }
func (s *DockerSuite) TestAttachPausedContainer(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachPausedContainer(c *testing.T) {
testRequires(c, IsPausable) testRequires(c, IsPausable)
runSleepingContainer(c, "-d", "--name=test") runSleepingContainer(c, "-d", "--name=test")
dockerCmd(c, "pause", "test") dockerCmd(c, "pause", "test")

View file

@ -16,7 +16,7 @@ import (
) )
// #9860 Make sure attach ends when container ends (with no errors) // #9860 Make sure attach ends when container ends (with no errors)
func (s *DockerSuite) TestAttachClosedOnContainerStop(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`) out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`)
@ -59,7 +59,7 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *testing.T) {
} }
func (s *DockerSuite) TestAttachAfterDetach(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
name := "detachtest" name := "detachtest"
cpty, tty, err := pty.Open() cpty, tty, err := pty.Open()
@ -124,7 +124,7 @@ func (s *DockerSuite) TestAttachAfterDetach(c *testing.T) {
} }
// TestAttachDetach checks that attach in tty mode can be detached using the long container ID // TestAttachDetach checks that attach in tty mode can be detached using the long container ID
func (s *DockerSuite) TestAttachDetach(c *testing.T) { func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))

File diff suppressed because it is too large Load diff

View file

@ -24,10 +24,10 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *testing.T) { func (s *DockerCLIBuildSuite) TestBuildResourceConstraintsAreUsed(c *testing.T) {
testRequires(c, cpuCfsQuota) testRequires(c, cpuCfsQuota)
name := "testbuildresourceconstraints" name := "testbuildresourceconstraints"
buildLabel := "DockerSuite.TestBuildResourceConstraintsAreUsed" buildLabel := "DockerCLIBuildSuite.TestBuildResourceConstraintsAreUsed"
ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(` ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`
FROM hello-world:frozen FROM hello-world:frozen
@ -84,7 +84,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *testing.T) {
assert.Assert(c, c2.Ulimits == nil, "resource leaked from build for Ulimits") assert.Assert(c, c2.Ulimits == nil, "resource leaked from build for Ulimits")
} }
func (s *DockerSuite) TestBuildAddChangeOwnership(c *testing.T) { func (s *DockerCLIBuildSuite) TestBuildAddChangeOwnership(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testbuildaddown" name := "testbuildaddown"
@ -130,7 +130,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *testing.T) {
// TODO(buildkit): this test needs to be rewritten for buildkit. // TODO(buildkit): this test needs to be rewritten for buildkit.
// It has been manually tested positive. Confirmed issue: docker build output parsing. // It has been manually tested positive. Confirmed issue: docker build output parsing.
// Potential issue: newEventObserver uses docker events, which is not hooked up to buildkit. // Potential issue: newEventObserver uses docker events, which is not hooked up to buildkit.
func (s *DockerSuite) TestBuildCancellationKillsSleep(c *testing.T) { func (s *DockerCLIBuildSuite) TestBuildCancellationKillsSleep(c *testing.T) {
testRequires(c, DaemonIsLinux, TODOBuildkit) testRequires(c, DaemonIsLinux, TODOBuildkit)
name := "testbuildcancellation" name := "testbuildcancellation"

View file

@ -10,7 +10,19 @@ import (
"gotest.tools/v3/skip" "gotest.tools/v3/skip"
) )
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *testing.T) { type DockerCLICommitSuite struct {
ds *DockerSuite
}
func (s *DockerCLICommitSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLICommitSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLICommitSuite) TestCommitAfterContainerIsDone(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
out := cli.DockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo").Combined() out := cli.DockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo").Combined()
@ -25,7 +37,7 @@ func (s *DockerSuite) TestCommitAfterContainerIsDone(c *testing.T) {
cli.DockerCmd(c, "inspect", cleanedImageID) cli.DockerCmd(c, "inspect", cleanedImageID)
} }
func (s *DockerSuite) TestCommitWithoutPause(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitWithoutPause(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
@ -41,7 +53,7 @@ func (s *DockerSuite) TestCommitWithoutPause(c *testing.T) {
} }
// TestCommitPausedContainer tests that a paused container is not unpaused after being committed // TestCommitPausedContainer tests that a paused container is not unpaused after being committed
func (s *DockerSuite) TestCommitPausedContainer(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitPausedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox") out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
@ -55,7 +67,7 @@ func (s *DockerSuite) TestCommitPausedContainer(c *testing.T) {
assert.Assert(c, strings.Contains(out, "true")) assert.Assert(c, strings.Contains(out, "true"))
} }
func (s *DockerSuite) TestCommitNewFile(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitNewFile(c *testing.T) {
dockerCmd(c, "run", "--name", "committer", "busybox", "/bin/sh", "-c", "echo koye > /foo") dockerCmd(c, "run", "--name", "committer", "busybox", "/bin/sh", "-c", "echo koye > /foo")
imageID, _ := dockerCmd(c, "commit", "committer") imageID, _ := dockerCmd(c, "commit", "committer")
@ -66,7 +78,7 @@ func (s *DockerSuite) TestCommitNewFile(c *testing.T) {
assert.Equal(c, actual, "koye") assert.Equal(c, actual, "koye")
} }
func (s *DockerSuite) TestCommitHardlink(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitHardlink(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2") firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
@ -85,7 +97,7 @@ func (s *DockerSuite) TestCommitHardlink(c *testing.T) {
assert.Assert(c, strings.Contains(chunks[1], chunks[0]), "Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]) assert.Assert(c, strings.Contains(chunks[1], chunks[0]), "Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
} }
func (s *DockerSuite) TestCommitTTY(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitTTY(c *testing.T) {
dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls") dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest") imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
@ -94,7 +106,7 @@ func (s *DockerSuite) TestCommitTTY(c *testing.T) {
dockerCmd(c, "run", imageID, "/bin/ls") dockerCmd(c, "run", imageID, "/bin/ls")
} }
func (s *DockerSuite) TestCommitWithHostBindMount(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitWithHostBindMount(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true") dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
@ -104,7 +116,7 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *testing.T) {
dockerCmd(c, "run", imageID, "true") dockerCmd(c, "run", imageID, "true")
} }
func (s *DockerSuite) TestCommitChange(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitChange(c *testing.T) {
dockerCmd(c, "run", "--name", "test", "busybox", "true") dockerCmd(c, "run", "--name", "test", "busybox", "true")
imageID, _ := dockerCmd(c, "commit", imageID, _ := dockerCmd(c, "commit",
@ -154,7 +166,7 @@ func (s *DockerSuite) TestCommitChange(c *testing.T) {
} }
} }
func (s *DockerSuite) TestCommitChangeLabels(c *testing.T) { func (s *DockerCLICommitSuite) TestCommitChangeLabels(c *testing.T) {
dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true") dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true")
imageID, _ := dockerCmd(c, "commit", imageID, _ := dockerCmd(c, "commit",

View file

@ -21,7 +21,7 @@ import (
// Check that copying from a container to a local symlink copies to the symlink // Check that copying from a container to a local symlink copies to the symlink
// target and does not overwrite the local symlink itself. // target and does not overwrite the local symlink itself.
// TODO: move to docker/cli and/or integration/container/copy_test.go // TODO: move to docker/cli and/or integration/container/copy_test.go
func (s *DockerSuite) TestCpFromSymlinkDestination(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromSymlinkDestination(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true}) containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -96,7 +96,7 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *testing.T) {
// A. SRC specifies a file and DST (no trailing path separator) doesn't // A. SRC specifies a file and DST (no trailing path separator) doesn't
// exist. This should create a file with the name DST and copy the // exist. This should create a file with the name DST and copy the
// contents of the source file into it. // contents of the source file into it.
func (s *DockerSuite) TestCpFromCaseA(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseA(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -115,7 +115,7 @@ func (s *DockerSuite) TestCpFromCaseA(c *testing.T) {
// B. SRC specifies a file and DST (with trailing path separator) doesn't // B. SRC specifies a file and DST (with trailing path separator) doesn't
// exist. This should cause an error because the copy operation cannot // exist. This should cause an error because the copy operation cannot
// create a directory when copying a single file. // create a directory when copying a single file.
func (s *DockerSuite) TestCpFromCaseB(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseB(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true}) containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -132,7 +132,7 @@ func (s *DockerSuite) TestCpFromCaseB(c *testing.T) {
// C. SRC specifies a file and DST exists as a file. This should overwrite // C. SRC specifies a file and DST exists as a file. This should overwrite
// the file at DST with the contents of the source file. // the file at DST with the contents of the source file.
func (s *DockerSuite) TestCpFromCaseC(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseC(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -155,7 +155,7 @@ func (s *DockerSuite) TestCpFromCaseC(c *testing.T) {
// D. SRC specifies a file and DST exists as a directory. This should place // D. SRC specifies a file and DST exists as a directory. This should place
// a copy of the source file inside it using the basename from SRC. Ensure // a copy of the source file inside it using the basename from SRC. Ensure
// this works whether DST has a trailing path separator or not. // this works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpFromCaseD(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseD(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true}) containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -190,7 +190,7 @@ func (s *DockerSuite) TestCpFromCaseD(c *testing.T) {
// directory at DST and copy the contents of the SRC directory into the DST // directory at DST and copy the contents of the SRC directory into the DST
// directory. Ensure this works whether DST has a trailing path separator or // directory. Ensure this works whether DST has a trailing path separator or
// not. // not.
func (s *DockerSuite) TestCpFromCaseE(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseE(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true}) containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -216,7 +216,7 @@ func (s *DockerSuite) TestCpFromCaseE(c *testing.T) {
// F. SRC specifies a directory and DST exists as a file. This should cause an // F. SRC specifies a directory and DST exists as a file. This should cause an
// error as it is not possible to overwrite a file with a directory. // error as it is not possible to overwrite a file with a directory.
func (s *DockerSuite) TestCpFromCaseF(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseF(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -238,7 +238,7 @@ func (s *DockerSuite) TestCpFromCaseF(c *testing.T) {
// G. SRC specifies a directory and DST exists as a directory. This should copy // G. SRC specifies a directory and DST exists as a directory. This should copy
// the SRC directory and all its contents to the DST directory. Ensure this // the SRC directory and all its contents to the DST directory. Ensure this
// works whether DST has a trailing path separator or not. // works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpFromCaseG(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseG(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -272,7 +272,7 @@ func (s *DockerSuite) TestCpFromCaseG(c *testing.T) {
// should create a directory at DST and copy the contents of the SRC // should create a directory at DST and copy the contents of the SRC
// directory (but not the directory itself) into the DST directory. Ensure // directory (but not the directory itself) into the DST directory. Ensure
// this works whether DST has a trailing path separator or not. // this works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpFromCaseH(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseH(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true}) containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -299,7 +299,7 @@ func (s *DockerSuite) TestCpFromCaseH(c *testing.T) {
// I. SRC specifies a directory's contents only and DST exists as a file. This // I. SRC specifies a directory's contents only and DST exists as a file. This
// should cause an error as it is not possible to overwrite a file with a // should cause an error as it is not possible to overwrite a file with a
// directory. // directory.
func (s *DockerSuite) TestCpFromCaseI(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseI(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -322,7 +322,7 @@ func (s *DockerSuite) TestCpFromCaseI(c *testing.T) {
// This should copy the contents of the SRC directory (but not the directory // This should copy the contents of the SRC directory (but not the directory
// itself) into the DST directory. Ensure this works whether DST has a // itself) into the DST directory. Ensure this works whether DST has a
// trailing path separator or not. // trailing path separator or not.
func (s *DockerSuite) TestCpFromCaseJ(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromCaseJ(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",

View file

@ -26,15 +26,27 @@ const (
cpHostContents = "hello, i am the host" cpHostContents = "hello, i am the host"
) )
type DockerCLICpSuite struct {
ds *DockerSuite
}
func (s *DockerCLICpSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLICpSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// Ensure that an all-local path case returns an error. // Ensure that an all-local path case returns an error.
func (s *DockerSuite) TestCpLocalOnly(c *testing.T) { func (s *DockerCLICpSuite) TestCpLocalOnly(c *testing.T) {
err := runDockerCp(c, "foo", "bar") err := runDockerCp(c, "foo", "bar")
assert.ErrorContains(c, err, "must specify at least one container source") assert.ErrorContains(c, err, "must specify at least one container source")
} }
// Test for #5656 // Test for #5656
// Check that garbage paths don't escape the container's rootfs // Check that garbage paths don't escape the container's rootfs
func (s *DockerSuite) TestCpGarbagePath(c *testing.T) { func (s *DockerCLICpSuite) TestCpGarbagePath(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -70,7 +82,7 @@ func (s *DockerSuite) TestCpGarbagePath(c *testing.T) {
} }
// Check that relative paths are relative to the container's rootfs // Check that relative paths are relative to the container's rootfs
func (s *DockerSuite) TestCpRelativePath(c *testing.T) { func (s *DockerCLICpSuite) TestCpRelativePath(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -112,7 +124,7 @@ func (s *DockerSuite) TestCpRelativePath(c *testing.T) {
} }
// Check that absolute paths are relative to the container's rootfs // Check that absolute paths are relative to the container's rootfs
func (s *DockerSuite) TestCpAbsolutePath(c *testing.T) { func (s *DockerCLICpSuite) TestCpAbsolutePath(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -149,7 +161,7 @@ func (s *DockerSuite) TestCpAbsolutePath(c *testing.T) {
// Test for #5619 // Test for #5619
// Check that absolute symlinks are still relative to the container's rootfs // Check that absolute symlinks are still relative to the container's rootfs
func (s *DockerSuite) TestCpAbsoluteSymlink(c *testing.T) { func (s *DockerCLICpSuite) TestCpAbsoluteSymlink(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
@ -185,7 +197,7 @@ func (s *DockerSuite) TestCpAbsoluteSymlink(c *testing.T) {
// Check that symlinks to a directory behave as expected when copying one from // Check that symlinks to a directory behave as expected when copying one from
// a container. // a container.
func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *testing.T) { func (s *DockerCLICpSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link")
@ -231,7 +243,7 @@ func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
// Check that symlinks to a directory behave as expected when copying one to a // Check that symlinks to a directory behave as expected when copying one to a
// container. // container.
func (s *DockerSuite) TestCpToSymlinkToDirectory(c *testing.T) { func (s *DockerCLICpSuite) TestCpToSymlinkToDirectory(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, testEnv.IsLocalDaemon) // Requires local volume mount bind. testRequires(c, testEnv.IsLocalDaemon) // Requires local volume mount bind.
@ -308,7 +320,7 @@ func (s *DockerSuite) TestCpToSymlinkToDirectory(c *testing.T) {
// Test for #5619 // Test for #5619
// Check that symlinks which are part of the resource path are still relative to the container's rootfs // Check that symlinks which are part of the resource path are still relative to the container's rootfs
func (s *DockerSuite) TestCpSymlinkComponent(c *testing.T) { func (s *DockerCLICpSuite) TestCpSymlinkComponent(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
@ -347,7 +359,7 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *testing.T) {
} }
// Check that cp with unprivileged user doesn't return any error // Check that cp with unprivileged user doesn't return any error
func (s *DockerSuite) TestCpUnprivilegedUser(c *testing.T) { func (s *DockerCLICpSuite) TestCpUnprivilegedUser(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
testRequires(c, UnixCli) // uses chmod/su: not available on windows testRequires(c, UnixCli) // uses chmod/su: not available on windows
@ -371,7 +383,7 @@ func (s *DockerSuite) TestCpUnprivilegedUser(c *testing.T) {
result.Assert(c, icmd.Expected{}) result.Assert(c, icmd.Expected{})
} }
func (s *DockerSuite) TestCpSpecialFiles(c *testing.T) { func (s *DockerCLICpSuite) TestCpSpecialFiles(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
@ -411,7 +423,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *testing.T) {
assert.Assert(c, bytes.Equal(actual, expected), "Expected copied file to be duplicate of the container hostname") assert.Assert(c, bytes.Equal(actual, expected), "Expected copied file to be duplicate of the container hostname")
} }
func (s *DockerSuite) TestCpVolumePath(c *testing.T) { func (s *DockerCLICpSuite) TestCpVolumePath(c *testing.T) {
// stat /tmp/cp-test-volumepath851508420/test gets permission denied for the user // stat /tmp/cp-test-volumepath851508420/test gets permission denied for the user
testRequires(c, NotUserNamespace) testRequires(c, NotUserNamespace)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -474,7 +486,7 @@ func (s *DockerSuite) TestCpVolumePath(c *testing.T) {
assert.Assert(c, bytes.Equal(fb, fb2), "Expected copied file to be duplicate of bind-mounted file") assert.Assert(c, bytes.Equal(fb, fb2), "Expected copied file to be duplicate of bind-mounted file")
} }
func (s *DockerSuite) TestCpToDot(c *testing.T) { func (s *DockerCLICpSuite) TestCpToDot(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -497,7 +509,7 @@ func (s *DockerSuite) TestCpToDot(c *testing.T) {
assert.Equal(c, string(content), "lololol\n") assert.Equal(c, string(content), "lololol\n")
} }
func (s *DockerSuite) TestCpToStdout(c *testing.T) { func (s *DockerCLICpSuite) TestCpToStdout(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -514,7 +526,7 @@ func (s *DockerSuite) TestCpToStdout(c *testing.T) {
assert.Check(c, is.Contains(out, "-rw")) assert.Check(c, is.Contains(out, "-rw"))
} }
func (s *DockerSuite) TestCpNameHasColon(c *testing.T) { func (s *DockerCLICpSuite) TestCpNameHasColon(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
@ -533,7 +545,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *testing.T) {
assert.Equal(c, string(content), "lololol\n") assert.Equal(c, string(content), "lololol\n")
} }
func (s *DockerSuite) TestCopyAndRestart(c *testing.T) { func (s *DockerCLICpSuite) TestCopyAndRestart(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
expectedMsg := "hello" expectedMsg := "hello"
out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg) out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
@ -552,7 +564,7 @@ func (s *DockerSuite) TestCopyAndRestart(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), expectedMsg) assert.Equal(c, strings.TrimSpace(out), expectedMsg)
} }
func (s *DockerSuite) TestCopyCreatedContainer(c *testing.T) { func (s *DockerCLICpSuite) TestCopyCreatedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox") dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
@ -565,7 +577,7 @@ func (s *DockerSuite) TestCopyCreatedContainer(c *testing.T) {
// test copy with option `-L`: following symbol link // test copy with option `-L`: following symbol link
// Check that symlinks to a file behave as expected when copying one from // Check that symlinks to a file behave as expected when copying one from
// a container to host following symbol link // a container to host following symbol link
func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T) { func (s *DockerCLICpSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link") out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link")
assert.Equal(c, exitCode, 0, "failed to set up container: %s", out) assert.Equal(c, exitCode, 0, "failed to set up container: %s", out)

View file

@ -19,7 +19,7 @@ import (
// Check that copying from a local path to a symlink in a container copies to // Check that copying from a local path to a symlink in a container copies to
// the symlink target and does not overwrite the container symlink itself. // the symlink target and does not overwrite the container symlink itself.
func (s *DockerSuite) TestCpToSymlinkDestination(c *testing.T) { func (s *DockerCLICpSuite) TestCpToSymlinkDestination(c *testing.T) {
// stat /tmp/test-cp-to-symlink-destination-262430901/vol3 gets permission denied for the user // stat /tmp/test-cp-to-symlink-destination-262430901/vol3 gets permission denied for the user
testRequires(c, NotUserNamespace) testRequires(c, NotUserNamespace)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -100,7 +100,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *testing.T) {
// A. SRC specifies a file and DST (no trailing path separator) doesn't // A. SRC specifies a file and DST (no trailing path separator) doesn't
// exist. This should create a file with the name DST and copy the // exist. This should create a file with the name DST and copy the
// contents of the source file into it. // contents of the source file into it.
func (s *DockerSuite) TestCpToCaseA(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseA(c *testing.T) {
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
workDir: "/root", command: makeCatFileCommand("itWorks.txt"), workDir: "/root", command: makeCatFileCommand("itWorks.txt"),
}) })
@ -120,7 +120,7 @@ func (s *DockerSuite) TestCpToCaseA(c *testing.T) {
// B. SRC specifies a file and DST (with trailing path separator) doesn't // B. SRC specifies a file and DST (with trailing path separator) doesn't
// exist. This should cause an error because the copy operation cannot // exist. This should cause an error because the copy operation cannot
// create a directory when copying a single file. // create a directory when copying a single file.
func (s *DockerSuite) TestCpToCaseB(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseB(c *testing.T) {
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
command: makeCatFileCommand("testDir/file1"), command: makeCatFileCommand("testDir/file1"),
}) })
@ -140,7 +140,7 @@ func (s *DockerSuite) TestCpToCaseB(c *testing.T) {
// C. SRC specifies a file and DST exists as a file. This should overwrite // C. SRC specifies a file and DST exists as a file. This should overwrite
// the file at DST with the contents of the source file. // the file at DST with the contents of the source file.
func (s *DockerSuite) TestCpToCaseC(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseC(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -164,7 +164,7 @@ func (s *DockerSuite) TestCpToCaseC(c *testing.T) {
// D. SRC specifies a file and DST exists as a directory. This should place // D. SRC specifies a file and DST exists as a directory. This should place
// a copy of the source file inside it using the basename from SRC. Ensure // a copy of the source file inside it using the basename from SRC. Ensure
// this works whether DST has a trailing path separator or not. // this works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpToCaseD(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseD(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, addContent: true,
@ -202,7 +202,7 @@ func (s *DockerSuite) TestCpToCaseD(c *testing.T) {
// directory at DST and copy the contents of the SRC directory into the DST // directory at DST and copy the contents of the SRC directory into the DST
// directory. Ensure this works whether DST has a trailing path separator or // directory. Ensure this works whether DST has a trailing path separator or
// not. // not.
func (s *DockerSuite) TestCpToCaseE(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseE(c *testing.T) {
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
command: makeCatFileCommand("/testDir/file1-1"), command: makeCatFileCommand("/testDir/file1-1"),
}) })
@ -233,7 +233,7 @@ func (s *DockerSuite) TestCpToCaseE(c *testing.T) {
// F. SRC specifies a directory and DST exists as a file. This should cause an // F. SRC specifies a directory and DST exists as a file. This should cause an
// error as it is not possible to overwrite a file with a directory. // error as it is not possible to overwrite a file with a directory.
func (s *DockerSuite) TestCpToCaseF(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseF(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -255,7 +255,7 @@ func (s *DockerSuite) TestCpToCaseF(c *testing.T) {
// G. SRC specifies a directory and DST exists as a directory. This should copy // G. SRC specifies a directory and DST exists as a directory. This should copy
// the SRC directory and all its contents to the DST directory. Ensure this // the SRC directory and all its contents to the DST directory. Ensure this
// works whether DST has a trailing path separator or not. // works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpToCaseG(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseG(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -293,7 +293,7 @@ func (s *DockerSuite) TestCpToCaseG(c *testing.T) {
// should create a directory at DST and copy the contents of the SRC // should create a directory at DST and copy the contents of the SRC
// directory (but not the directory itself) into the DST directory. Ensure // directory (but not the directory itself) into the DST directory. Ensure
// this works whether DST has a trailing path separator or not. // this works whether DST has a trailing path separator or not.
func (s *DockerSuite) TestCpToCaseH(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseH(c *testing.T) {
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
command: makeCatFileCommand("/testDir/file1-1"), command: makeCatFileCommand("/testDir/file1-1"),
}) })
@ -325,7 +325,7 @@ func (s *DockerSuite) TestCpToCaseH(c *testing.T) {
// I. SRC specifies a directory's contents only and DST exists as a file. This // I. SRC specifies a directory's contents only and DST exists as a file. This
// should cause an error as it is not possible to overwrite a file with a // should cause an error as it is not possible to overwrite a file with a
// directory. // directory.
func (s *DockerSuite) TestCpToCaseI(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseI(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -348,7 +348,7 @@ func (s *DockerSuite) TestCpToCaseI(c *testing.T) {
// This should copy the contents of the SRC directory (but not the directory // This should copy the contents of the SRC directory (but not the directory
// itself) into the DST directory. Ensure this works whether DST has a // itself) into the DST directory. Ensure this works whether DST has a
// trailing path separator or not. // trailing path separator or not.
func (s *DockerSuite) TestCpToCaseJ(c *testing.T) { func (s *DockerCLICpSuite) TestCpToCaseJ(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{ containerID := makeTestContainer(c, testContainerOptions{
addContent: true, workDir: "/root", addContent: true, workDir: "/root",
@ -383,7 +383,7 @@ func (s *DockerSuite) TestCpToCaseJ(c *testing.T) {
// The `docker cp` command should also ensure that you cannot // The `docker cp` command should also ensure that you cannot
// write to a container rootfs that is marked as read-only. // write to a container rootfs that is marked as read-only.
func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *testing.T) { func (s *DockerCLICpSuite) TestCpToErrReadOnlyRootfs(c *testing.T) {
// --read-only + userns has remount issues // --read-only + userns has remount issues
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
tmpDir := getTestDir(c, "test-cp-to-err-read-only-rootfs") tmpDir := getTestDir(c, "test-cp-to-err-read-only-rootfs")
@ -408,7 +408,7 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *testing.T) {
// The `docker cp` command should also ensure that you // The `docker cp` command should also ensure that you
// cannot write to a volume that is mounted as read-only. // cannot write to a volume that is mounted as read-only.
func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *testing.T) { func (s *DockerCLICpSuite) TestCpToErrReadOnlyVolume(c *testing.T) {
// --read-only + userns has remount issues // --read-only + userns has remount issues
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
tmpDir := getTestDir(c, "test-cp-to-err-read-only-volume") tmpDir := getTestDir(c, "test-cp-to-err-read-only-volume")

View file

@ -16,7 +16,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestCpToContainerWithPermissions(c *testing.T) { func (s *DockerCLICpSuite) TestCpToContainerWithPermissions(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
tmpDir := getTestDir(c, "test-cp-to-host-with-permissions") tmpDir := getTestDir(c, "test-cp-to-host-with-permissions")
@ -43,7 +43,7 @@ func (s *DockerSuite) TestCpToContainerWithPermissions(c *testing.T) {
} }
// Check ownership is root, both in non-userns and userns enabled modes // Check ownership is root, both in non-userns and userns enabled modes
func (s *DockerSuite) TestCpCheckDestOwnership(c *testing.T) { func (s *DockerCLICpSuite) TestCpCheckDestOwnership(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
tmpVolDir := getTestDir(c, "test-cp-tmpvol") tmpVolDir := getTestDir(c, "test-cp-tmpvol")
containerID := makeTestContainer(c, containerID := makeTestContainer(c,

View file

@ -17,8 +17,20 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
type DockerCLICreateSuite struct {
ds *DockerSuite
}
func (s *DockerCLICreateSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLICreateSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// Make sure we can create a simple container with some args // Make sure we can create a simple container with some args
func (s *DockerSuite) TestCreateArgs(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateArgs(c *testing.T) {
// Intentionally clear entrypoint, as the Windows busybox image needs an entrypoint, which breaks this test // Intentionally clear entrypoint, as the Windows busybox image needs an entrypoint, which breaks this test
out, _ := dockerCmd(c, "create", "--entrypoint=", "busybox", "command", "arg1", "arg2", "arg with space", "-c", "flags") out, _ := dockerCmd(c, "create", "--entrypoint=", "busybox", "command", "arg1", "arg2", "arg with space", "-c", "flags")
@ -53,7 +65,7 @@ func (s *DockerSuite) TestCreateArgs(c *testing.T) {
} }
// Make sure we can grow the container's rootfs at creation time. // Make sure we can grow the container's rootfs at creation time.
func (s *DockerSuite) TestCreateGrowRootfs(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateGrowRootfs(c *testing.T) {
// Windows and Devicemapper support growing the rootfs // Windows and Devicemapper support growing the rootfs
if testEnv.OSType != "windows" { if testEnv.OSType != "windows" {
testRequires(c, Devicemapper) testRequires(c, Devicemapper)
@ -67,7 +79,7 @@ func (s *DockerSuite) TestCreateGrowRootfs(c *testing.T) {
} }
// Make sure we cannot shrink the container's rootfs at creation time. // Make sure we cannot shrink the container's rootfs at creation time.
func (s *DockerSuite) TestCreateShrinkRootfs(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateShrinkRootfs(c *testing.T) {
testRequires(c, Devicemapper) testRequires(c, Devicemapper)
// Ensure this fails because of the defaultBaseFsSize is 10G // Ensure this fails because of the defaultBaseFsSize is 10G
@ -77,7 +89,7 @@ func (s *DockerSuite) TestCreateShrinkRootfs(c *testing.T) {
} }
// Make sure we can set hostconfig options too // Make sure we can set hostconfig options too
func (s *DockerSuite) TestCreateHostConfig(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateHostConfig(c *testing.T) {
out, _ := dockerCmd(c, "create", "-P", "busybox", "echo") out, _ := dockerCmd(c, "create", "-P", "busybox", "echo")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -99,7 +111,7 @@ func (s *DockerSuite) TestCreateHostConfig(c *testing.T) {
assert.Assert(c, cont.HostConfig.PublishAllPorts, "Expected PublishAllPorts, got false") assert.Assert(c, cont.HostConfig.PublishAllPorts, "Expected PublishAllPorts, got false")
} }
func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateWithPortRange(c *testing.T) {
out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo") out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -128,7 +140,7 @@ func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) {
} }
func (s *DockerSuite) TestCreateWithLargePortRange(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateWithLargePortRange(c *testing.T) {
out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo") out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -157,7 +169,7 @@ func (s *DockerSuite) TestCreateWithLargePortRange(c *testing.T) {
} }
// "test123" should be printed by docker create + start // "test123" should be printed by docker create + start
func (s *DockerSuite) TestCreateEchoStdout(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateEchoStdout(c *testing.T) {
out, _ := dockerCmd(c, "create", "busybox", "echo", "test123") out, _ := dockerCmd(c, "create", "busybox", "echo", "test123")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -166,7 +178,7 @@ func (s *DockerSuite) TestCreateEchoStdout(c *testing.T) {
assert.Equal(c, out, "test123\n", "container should've printed 'test123', got %q", out) assert.Equal(c, out, "test123\n", "container should've printed 'test123', got %q", out)
} }
func (s *DockerSuite) TestCreateVolumesCreated(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateVolumesCreated(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
@ -185,7 +197,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *testing.T) {
} }
func (s *DockerSuite) TestCreateLabels(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateLabels(c *testing.T) {
name := "test_create_labels" name := "test_create_labels"
expected := map[string]string{"k1": "v1", "k2": "v2"} expected := map[string]string{"k1": "v1", "k2": "v2"}
dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox") dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
@ -198,7 +210,7 @@ func (s *DockerSuite) TestCreateLabels(c *testing.T) {
} }
} }
func (s *DockerSuite) TestCreateLabelFromImage(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateLabelFromImage(c *testing.T) {
imageName := "testcreatebuildlabel" imageName := "testcreatebuildlabel"
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
LABEL k1=v1 k2=v2`)) LABEL k1=v1 k2=v2`))
@ -215,7 +227,7 @@ func (s *DockerSuite) TestCreateLabelFromImage(c *testing.T) {
} }
} }
func (s *DockerSuite) TestCreateHostnameWithNumber(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateHostnameWithNumber(c *testing.T) {
image := "busybox" image := "busybox"
// Busybox on Windows does not implement hostname command // Busybox on Windows does not implement hostname command
if testEnv.OSType == "windows" { if testEnv.OSType == "windows" {
@ -225,7 +237,7 @@ func (s *DockerSuite) TestCreateHostnameWithNumber(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "web.0", "hostname not set, expected `web.0`, got: %s", out) assert.Equal(c, strings.TrimSpace(out), "web.0", "hostname not set, expected `web.0`, got: %s", out)
} }
func (s *DockerSuite) TestCreateRM(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateRM(c *testing.T) {
// Test to make sure we can 'rm' a new container that is in // Test to make sure we can 'rm' a new container that is in
// "Created" state, and has ever been run. Test "rm -f" too. // "Created" state, and has ever been run. Test "rm -f" too.
@ -242,7 +254,7 @@ func (s *DockerSuite) TestCreateRM(c *testing.T) {
dockerCmd(c, "rm", "-f", cID) dockerCmd(c, "rm", "-f", cID)
} }
func (s *DockerSuite) TestCreateModeIpcContainer(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateModeIpcContainer(c *testing.T) {
// Uses Linux specific functionality (--ipc) // Uses Linux specific functionality (--ipc)
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
@ -252,7 +264,7 @@ func (s *DockerSuite) TestCreateModeIpcContainer(c *testing.T) {
dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox") dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
} }
func (s *DockerSuite) TestCreateByImageID(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateByImageID(c *testing.T) {
imageName := "testcreatebyimageid" imageName := "testcreatebyimageid"
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
MAINTAINER dockerio`)) MAINTAINER dockerio`))
@ -285,7 +297,7 @@ func (s *DockerSuite) TestCreateByImageID(c *testing.T) {
} }
} }
func (s *DockerSuite) TestCreateStopSignal(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateStopSignal(c *testing.T) {
name := "test_create_stop_signal" name := "test_create_stop_signal"
dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox") dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox")
@ -293,7 +305,7 @@ func (s *DockerSuite) TestCreateStopSignal(c *testing.T) {
assert.Assert(c, strings.Contains(res, "9")) assert.Assert(c, strings.Contains(res, "9"))
} }
func (s *DockerSuite) TestCreateWithWorkdir(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateWithWorkdir(c *testing.T) {
name := "foo" name := "foo"
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
@ -315,7 +327,7 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *testing.T) {
dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp") dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp")
} }
func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateWithInvalidLogOpts(c *testing.T) {
name := "test-invalidate-log-opts" name := "test-invalidate-log-opts"
out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox") out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
@ -327,7 +339,7 @@ func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *testing.T) {
} }
// #20972 // #20972
func (s *DockerSuite) TestCreate64ByteHexID(c *testing.T) { func (s *DockerCLICreateSuite) TestCreate64ByteHexID(c *testing.T) {
out := inspectField(c, "busybox", "Id") out := inspectField(c, "busybox", "Id")
imageID := strings.TrimPrefix(strings.TrimSpace(out), "sha256:") imageID := strings.TrimPrefix(strings.TrimSpace(out), "sha256:")
@ -335,7 +347,7 @@ func (s *DockerSuite) TestCreate64ByteHexID(c *testing.T) {
} }
// Test case for #23498 // Test case for #23498
func (s *DockerSuite) TestCreateUnsetEntrypoint(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateUnsetEntrypoint(c *testing.T) {
name := "test-entrypoint" name := "test-entrypoint"
dockerfile := `FROM busybox dockerfile := `FROM busybox
ADD entrypoint.sh /entrypoint.sh ADD entrypoint.sh /entrypoint.sh
@ -362,7 +374,7 @@ exec "$@"`,
} }
// #22471 // #22471
func (s *DockerSuite) TestCreateStopTimeout(c *testing.T) { func (s *DockerCLICreateSuite) TestCreateStopTimeout(c *testing.T) {
name1 := "test_create_stop_timeout_1" name1 := "test_create_stop_timeout_1"
dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox") dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox")

View file

@ -24,7 +24,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestEventsTimestampFormats(c *testing.T) { type DockerCLIEventSuite struct {
ds *DockerSuite
}
func (s *DockerCLIEventSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIEventSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) {
name := "events-time-format-test" name := "events-time-format-test"
// Start stopwatch, generate an event // Start stopwatch, generate an event
@ -53,7 +65,7 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsUntag(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) {
image := "busybox" image := "busybox"
dockerCmd(c, "tag", image, "utest:tag1") dockerCmd(c, "tag", image, "utest:tag1")
dockerCmd(c, "tag", image, "utest:tag2") dockerCmd(c, "tag", image, "utest:tag2")
@ -76,7 +88,7 @@ func (s *DockerSuite) TestEventsUntag(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsContainerEvents(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerEvents(c *testing.T) {
dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true")
out, _ := dockerCmd(c, "events", "--until", daemonUnixTime(c)) out, _ := dockerCmd(c, "events", "--until", daemonUnixTime(c))
@ -90,7 +102,7 @@ func (s *DockerSuite) TestEventsContainerEvents(c *testing.T) {
assert.Assert(c, is.DeepEqual(containerEvents, []string{"create", "attach", "start", "die", "destroy"}), out) assert.Assert(c, is.DeepEqual(containerEvents, []string{"create", "attach", "start", "die", "destroy"}), out)
} }
func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true")
@ -114,7 +126,7 @@ func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
assert.Equal(c, matchedEvents, 2, "missing events for container container-events-test:\n%s", out) assert.Equal(c, matchedEvents, 2, "missing events for container container-events-test:\n%s", out)
} }
func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing.T) {
dockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true") dockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true")
timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano) timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
timeBeginning = strings.ReplaceAll(timeBeginning, "Z", ".000000000Z") timeBeginning = strings.ReplaceAll(timeBeginning, "Z", ".000000000Z")
@ -128,7 +140,7 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing.T) {
assert.Assert(c, is.DeepEqual(containerEvents, []string{"create", "attach", "start", "die", "destroy"}), out) assert.Assert(c, is.DeepEqual(containerEvents, []string{"create", "attach", "start", "die", "destroy"}), out)
} }
func (s *DockerSuite) TestEventsImageTag(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImageTag(c *testing.T) {
time.Sleep(1 * time.Second) // because API has seconds granularity time.Sleep(1 * time.Second) // because API has seconds granularity
since := daemonUnixTime(c) since := daemonUnixTime(c)
image := "testimageevents:tag" image := "testimageevents:tag"
@ -146,7 +158,7 @@ func (s *DockerSuite) TestEventsImageTag(c *testing.T) {
assert.Equal(c, matches["action"], "tag") assert.Equal(c, matches["action"], "tag")
} }
func (s *DockerSuite) TestEventsImagePull(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImagePull(c *testing.T) {
// TODO Windows: Enable this test once pull and reliable image names are available // TODO Windows: Enable this test once pull and reliable image names are available
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -164,7 +176,7 @@ func (s *DockerSuite) TestEventsImagePull(c *testing.T) {
assert.Equal(c, matches["action"], "pull") assert.Equal(c, matches["action"], "pull")
} }
func (s *DockerSuite) TestEventsImageImport(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) {
// TODO Windows CI. This should be portable once export/import are // TODO Windows CI. This should be portable once export/import are
// more reliable (@swernli) // more reliable (@swernli)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -188,7 +200,7 @@ func (s *DockerSuite) TestEventsImageImport(c *testing.T) {
assert.Equal(c, matches["action"], "import", "matches: %v\nout:\n%s\n", matches, out) assert.Equal(c, matches["action"], "import", "matches: %v\nout:\n%s\n", matches, out)
} }
func (s *DockerSuite) TestEventsImageLoad(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImageLoad(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
myImageName := "footest:v1" myImageName := "footest:v1"
dockerCmd(c, "tag", "busybox", myImageName) dockerCmd(c, "tag", "busybox", myImageName)
@ -227,7 +239,7 @@ func (s *DockerSuite) TestEventsImageLoad(c *testing.T) {
assert.Equal(c, matches["action"], "save", "matches: %v\nout:\n%s\n", matches, out) assert.Equal(c, matches["action"], "save", "matches: %v\nout:\n%s\n", matches, out)
} }
func (s *DockerSuite) TestEventsPluginOps(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsPluginOps(c *testing.T) {
testRequires(c, DaemonIsLinux, IsAmd64, Network) testRequires(c, DaemonIsLinux, IsAmd64, Network)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -246,7 +258,7 @@ func (s *DockerSuite) TestEventsPluginOps(c *testing.T) {
assert.Assert(c, is.DeepEqual(pluginEvents, []string{"pull", "enable", "disable", "remove"}), out) assert.Assert(c, is.DeepEqual(pluginEvents, []string{"pull", "enable", "disable", "remove"}), out)
} }
func (s *DockerSuite) TestEventsFilters(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilters(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "--rm", "busybox", "true") dockerCmd(c, "run", "--rm", "busybox", "true")
dockerCmd(c, "run", "--rm", "busybox", "true") dockerCmd(c, "run", "--rm", "busybox", "true")
@ -261,7 +273,7 @@ func (s *DockerSuite) TestEventsFilters(c *testing.T) {
assert.Assert(c, count >= 2, "should have had 2 start events but had %d, out: %s", count, out) assert.Assert(c, count >= 2, "should have had 2 start events but had %d, out: %s", count, out)
} }
func (s *DockerSuite) TestEventsFilterImageName(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterImageName(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true") out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
@ -289,7 +301,7 @@ func (s *DockerSuite) TestEventsFilterImageName(c *testing.T) {
assert.Assert(c, count2 != 0, "Expected event from container but got %d from %s", count2, container2) assert.Assert(c, count2 != 0, "Expected event from container but got %d from %s", count2, container2)
} }
func (s *DockerSuite) TestEventsFilterLabels(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterLabels(c *testing.T) {
since := strconv.FormatUint(uint64(daemonTime(c).Unix()), 10) since := strconv.FormatUint(uint64(daemonTime(c).Unix()), 10)
label := "io.docker.testing=foo" label := "io.docker.testing=foo"
@ -324,7 +336,7 @@ func (s *DockerSuite) TestEventsFilterLabels(c *testing.T) {
assert.Assert(c, found) assert.Assert(c, found)
} }
func (s *DockerSuite) TestEventsFilterImageLabels(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterImageLabels(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
name := "labelfiltertest" name := "labelfiltertest"
label := "io.docker.testing=image" label := "io.docker.testing=image"
@ -354,7 +366,7 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsFilterContainer(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterContainer(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
nameID := make(map[string]string) nameID := make(map[string]string)
@ -392,7 +404,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsCommit(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsCommit(c *testing.T) {
// Problematic on Windows as cannot commit a running container // Problematic on Windows as cannot commit a running container
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -409,7 +421,7 @@ func (s *DockerSuite) TestEventsCommit(c *testing.T) {
assert.Assert(c, strings.Contains(out, "commit"), "Missing 'commit' log event") assert.Assert(c, strings.Contains(out, "commit"), "Missing 'commit' log event")
} }
func (s *DockerSuite) TestEventsCopy(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsCopy(c *testing.T) {
// Build a test image. // Build a test image.
buildImageSuccessfully(c, "cpimg", build.WithDockerfile(` buildImageSuccessfully(c, "cpimg", build.WithDockerfile(`
FROM busybox FROM busybox
@ -438,7 +450,7 @@ func (s *DockerSuite) TestEventsCopy(c *testing.T) {
assert.Assert(c, strings.Contains(out, "extract-to-dir"), "Missing 'extract-to-dir' log event") assert.Assert(c, strings.Contains(out, "extract-to-dir"), "Missing 'extract-to-dir' log event")
} }
func (s *DockerSuite) TestEventsResize(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) {
out := runSleepingContainer(c, "-d", "-t") out := runSleepingContainer(c, "-d", "-t")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
assert.NilError(c, waitRun(cID)) assert.NilError(c, waitRun(cID))
@ -461,7 +473,7 @@ func (s *DockerSuite) TestEventsResize(c *testing.T) {
assert.Assert(c, strings.Contains(out, "resize"), "Missing 'resize' log event") assert.Assert(c, strings.Contains(out, "resize"), "Missing 'resize' log event")
} }
func (s *DockerSuite) TestEventsAttach(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsAttach(c *testing.T) {
// TODO Windows CI: Figure out why this test fails intermittently (TP5). // TODO Windows CI: Figure out why this test fails intermittently (TP5).
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -499,7 +511,7 @@ func (s *DockerSuite) TestEventsAttach(c *testing.T) {
assert.Assert(c, strings.Contains(out, "attach"), "Missing 'attach' log event") assert.Assert(c, strings.Contains(out, "attach"), "Missing 'attach' log event")
} }
func (s *DockerSuite) TestEventsRename(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsRename(c *testing.T) {
out, _ := dockerCmd(c, "run", "--name", "oldName", "busybox", "true") out, _ := dockerCmd(c, "run", "--name", "oldName", "busybox", "true")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
dockerCmd(c, "rename", "oldName", "newName") dockerCmd(c, "rename", "oldName", "newName")
@ -510,7 +522,7 @@ func (s *DockerSuite) TestEventsRename(c *testing.T) {
assert.Assert(c, strings.Contains(out, "rename"), "Missing 'rename' log event") assert.Assert(c, strings.Contains(out, "rename"), "Missing 'rename' log event")
} }
func (s *DockerSuite) TestEventsTop(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsTop(c *testing.T) {
// Problematic on Windows as Windows does not support top // Problematic on Windows as Windows does not support top
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -547,7 +559,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *testing.T) {
assert.Assert(c, strings.Contains(out, repoName), "Missing 'push' log event for %s", repoName) assert.Assert(c, strings.Contains(out, repoName), "Missing 'push' log event for %s", repoName)
} }
func (s *DockerSuite) TestEventsFilterType(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) {
// FIXME(vdemeester) fails on e2e run // FIXME(vdemeester) fails on e2e run
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -601,7 +613,7 @@ func (s *DockerSuite) TestEventsFilterType(c *testing.T) {
} }
// #25798 // #25798
func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
runSleepingContainer(c, "--name", "test-container", "-d") runSleepingContainer(c, "--name", "test-container", "-d")
waitRun("test-container") waitRun("test-container")
@ -631,7 +643,7 @@ func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) {
assert.Equal(c, len(events), 1, out) assert.Equal(c, len(events), 1, out)
} }
func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterImageInContainerAction(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
waitRun("test-container") waitRun("test-container")
@ -641,7 +653,7 @@ func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *testing.T) {
assert.Assert(c, len(events) > 1, out) assert.Assert(c, len(events) > 1, out)
} }
func (s *DockerSuite) TestEventsContainerRestart(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) {
dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false") dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false")
// wait until test2 is auto removed. // wait until test2 is auto removed.
@ -681,7 +693,7 @@ func (s *DockerSuite) TestEventsContainerRestart(c *testing.T) {
assert.Equal(c, dieCount, 4, "testEvent should die 4 times: %v", actions) assert.Equal(c, dieCount, 4, "testEvent should die 4 times: %v", actions)
} }
func (s *DockerSuite) TestEventsSinceInTheFuture(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsSinceInTheFuture(c *testing.T) {
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
waitRun("test-container") waitRun("test-container")
@ -693,7 +705,7 @@ func (s *DockerSuite) TestEventsSinceInTheFuture(c *testing.T) {
assert.Assert(c, strings.Contains(out, "cannot be after `until`")) assert.Assert(c, strings.Contains(out, "cannot be after `until`"))
} }
func (s *DockerSuite) TestEventsUntilInThePast(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsUntilInThePast(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
@ -710,7 +722,7 @@ func (s *DockerSuite) TestEventsUntilInThePast(c *testing.T) {
assert.Assert(c, strings.Contains(out, "test-container")) assert.Assert(c, strings.Contains(out, "test-container"))
} }
func (s *DockerSuite) TestEventsFormat(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormat(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "--rm", "busybox", "true") dockerCmd(c, "run", "--rm", "busybox", "true")
dockerCmd(c, "run", "--rm", "busybox", "true") dockerCmd(c, "run", "--rm", "busybox", "true")
@ -733,7 +745,7 @@ func (s *DockerSuite) TestEventsFormat(c *testing.T) {
assert.Equal(c, startCount, 2, "should have had 2 start events but had %d, out: %s", startCount, out) assert.Equal(c, startCount, 2, "should have had 2 start events but had %d, out: %s", startCount, out)
} }
func (s *DockerSuite) TestEventsFormatBadFunc(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) {
// make sure it fails immediately, without receiving any event // make sure it fails immediately, without receiving any event
result := dockerCmdWithResult("events", "--format", "{{badFuncString .}}") result := dockerCmdWithResult("events", "--format", "{{badFuncString .}}")
result.Assert(c, icmd.Expected{ result.Assert(c, icmd.Expected{
@ -743,7 +755,7 @@ func (s *DockerSuite) TestEventsFormatBadFunc(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestEventsFormatBadField(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormatBadField(c *testing.T) {
// make sure it fails immediately, without receiving any event // make sure it fails immediately, without receiving any event
result := dockerCmdWithResult("events", "--format", "{{.badFieldString}}") result := dockerCmdWithResult("events", "--format", "{{.badFieldString}}")
result.Assert(c, icmd.Expected{ result.Assert(c, icmd.Expected{

View file

@ -22,7 +22,7 @@ import (
) )
// #5979 // #5979
func (s *DockerSuite) TestEventsRedirectStdout(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsRedirectStdout(c *testing.T) {
since := daemonUnixTime(c) since := daemonUnixTime(c)
dockerCmd(c, "run", "busybox", "true") dockerCmd(c, "run", "busybox", "true")
@ -48,7 +48,7 @@ func (s *DockerSuite) TestEventsRedirectStdout(c *testing.T) {
assert.NilError(c, scanner.Err(), "Scan err for command %q", command) assert.NilError(c, scanner.Err(), "Scan err for command %q", command)
} }
func (s *DockerSuite) TestEventsOOMDisableFalse(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsOOMDisableFalse(c *testing.T) {
testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, swapMemorySupport, NotPpc64le) testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, swapMemorySupport, NotPpc64le)
errChan := make(chan error, 1) errChan := make(chan error, 1)
@ -78,7 +78,7 @@ func (s *DockerSuite) TestEventsOOMDisableFalse(c *testing.T) {
assert.Equal(c, parseEventAction(c, events[nEvents-1]), "die") assert.Equal(c, parseEventAction(c, events[nEvents-1]), "die")
} }
func (s *DockerSuite) TestEventsOOMDisableTrue(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsOOMDisableTrue(c *testing.T) {
testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotArm, swapMemorySupport, NotPpc64le) testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotArm, swapMemorySupport, NotPpc64le)
errChan := make(chan error, 1) errChan := make(chan error, 1)
@ -126,7 +126,7 @@ func (s *DockerSuite) TestEventsOOMDisableTrue(c *testing.T) {
} }
// #18453 // #18453
func (s *DockerSuite) TestEventsContainerFilterByName(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerFilterByName(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
cOut, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") cOut, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
c1 := strings.TrimSpace(cOut) c1 := strings.TrimSpace(cOut)
@ -140,7 +140,7 @@ func (s *DockerSuite) TestEventsContainerFilterByName(c *testing.T) {
} }
// #18453 // #18453
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerFilterBeforeCreate(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
cmd := exec.Command(dockerBinary, "events", "-f", "container=foo", "--since=0") cmd := exec.Command(dockerBinary, "events", "-f", "container=foo", "--since=0")
@ -165,7 +165,7 @@ func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *testing.T) {
} }
} }
func (s *DockerSuite) TestVolumeEvents(c *testing.T) { func (s *DockerCLIEventSuite) TestVolumeEvents(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -192,7 +192,7 @@ func (s *DockerSuite) TestVolumeEvents(c *testing.T) {
assert.Equal(c, volumeEvents[3], "destroy") assert.Equal(c, volumeEvents[3], "destroy")
} }
func (s *DockerSuite) TestNetworkEvents(c *testing.T) { func (s *DockerCLIEventSuite) TestNetworkEvents(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -219,7 +219,7 @@ func (s *DockerSuite) TestNetworkEvents(c *testing.T) {
assert.Equal(c, netEvents[3], "destroy") assert.Equal(c, netEvents[3], "destroy")
} }
func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerWithMultiNetwork(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Observe create/connect network actions // Observe create/connect network actions
@ -247,7 +247,7 @@ func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *testing.T) {
assert.Assert(c, strings.Contains(out, "test-event-network-local-2")) assert.Assert(c, strings.Contains(out, "test-event-network-local-2"))
} }
func (s *DockerSuite) TestEventsStreaming(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsStreaming(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
observer, err := newEventObserver(c) observer, err := newEventObserver(c)
@ -301,7 +301,7 @@ func (s *DockerSuite) TestEventsStreaming(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsImageUntagDelete(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImageUntagDelete(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
observer, err := newEventObserver(c) observer, err := newEventObserver(c)
@ -340,7 +340,7 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *testing.T) {
} }
} }
func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -359,7 +359,7 @@ func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T) {
assert.Equal(c, networkActions[0], "create") assert.Equal(c, networkActions[0], "create")
} }
func (s *DockerSuite) TestEventsFilterVolumeID(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterVolumeID(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)
@ -374,7 +374,7 @@ func (s *DockerSuite) TestEventsFilterVolumeID(c *testing.T) {
assert.Assert(c, strings.Contains(events[0], "driver=local")) assert.Assert(c, strings.Contains(events[0], "driver=local"))
} }
func (s *DockerSuite) TestEventsFilterNetworkID(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterNetworkID(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c) since := daemonUnixTime(c)

View file

@ -22,7 +22,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestExec(c *testing.T) { type DockerCLIExecSuite struct {
ds *DockerSuite
}
func (s *DockerCLIExecSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIExecSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIExecSuite) TestExec(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
assert.NilError(c, waitRun(strings.TrimSpace(out))) assert.NilError(c, waitRun(strings.TrimSpace(out)))
@ -31,7 +43,7 @@ func (s *DockerSuite) TestExec(c *testing.T) {
assert.Equal(c, strings.Trim(out, "\r\n"), "test") assert.Equal(c, strings.Trim(out, "\r\n"), "test")
} }
func (s *DockerSuite) TestExecInteractive(c *testing.T) { func (s *DockerCLIExecSuite) TestExecInteractive(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
@ -67,7 +79,7 @@ func (s *DockerSuite) TestExecInteractive(c *testing.T) {
} }
func (s *DockerSuite) TestExecAfterContainerRestart(c *testing.T) { func (s *DockerCLIExecSuite) TestExecAfterContainerRestart(c *testing.T) {
out := runSleepingContainer(c) out := runSleepingContainer(c)
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
assert.NilError(c, waitRun(cleanedContainerID)) assert.NilError(c, waitRun(cleanedContainerID))
@ -96,7 +108,7 @@ func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *testing.T) {
} }
// Regression test for #9155, #9044 // Regression test for #9155, #9044
func (s *DockerSuite) TestExecEnv(c *testing.T) { func (s *DockerCLIExecSuite) TestExecEnv(c *testing.T) {
// TODO Windows CI: This one is interesting and may just end up being a feature // TODO Windows CI: This one is interesting and may just end up being a feature
// difference between Windows and Linux. On Windows, the environment is passed // difference between Windows and Linux. On Windows, the environment is passed
// into the process that is launched, not into the machine environment. Hence // into the process that is launched, not into the machine environment. Hence
@ -111,7 +123,7 @@ func (s *DockerSuite) TestExecEnv(c *testing.T) {
assert.Check(c, strings.Contains(out, "HOME=/root")) assert.Check(c, strings.Contains(out, "HOME=/root"))
} }
func (s *DockerSuite) TestExecSetEnv(c *testing.T) { func (s *DockerCLIExecSuite) TestExecSetEnv(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
runSleepingContainer(c, "-e", "HOME=/root", "-d", "--name", "testing") runSleepingContainer(c, "-e", "HOME=/root", "-d", "--name", "testing")
assert.NilError(c, waitRun("testing")) assert.NilError(c, waitRun("testing"))
@ -122,14 +134,14 @@ func (s *DockerSuite) TestExecSetEnv(c *testing.T) {
assert.Check(c, strings.Contains(out, "ABC=xyz")) assert.Check(c, strings.Contains(out, "ABC=xyz"))
} }
func (s *DockerSuite) TestExecExitStatus(c *testing.T) { func (s *DockerCLIExecSuite) TestExecExitStatus(c *testing.T) {
runSleepingContainer(c, "-d", "--name", "top") runSleepingContainer(c, "-d", "--name", "top")
result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23") result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
result.Assert(c, icmd.Expected{ExitCode: 23, Error: "exit status 23"}) result.Assert(c, icmd.Expected{ExitCode: 23, Error: "exit status 23"})
} }
func (s *DockerSuite) TestExecPausedContainer(c *testing.T) { func (s *DockerCLIExecSuite) TestExecPausedContainer(c *testing.T) {
testRequires(c, IsPausable) testRequires(c, IsPausable)
out := runSleepingContainer(c, "-d", "--name", "testing") out := runSleepingContainer(c, "-d", "--name", "testing")
@ -144,7 +156,7 @@ func (s *DockerSuite) TestExecPausedContainer(c *testing.T) {
} }
// regression test for #9476 // regression test for #9476
func (s *DockerSuite) TestExecTTYCloseStdin(c *testing.T) { func (s *DockerCLIExecSuite) TestExecTTYCloseStdin(c *testing.T) {
// TODO Windows CI: This requires some work to port to Windows. // TODO Windows CI: This requires some work to port to Windows.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox") dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
@ -165,7 +177,7 @@ func (s *DockerSuite) TestExecTTYCloseStdin(c *testing.T) {
assert.Assert(c, !strings.Contains(out, "nsenter-exec")) assert.Assert(c, !strings.Contains(out, "nsenter-exec"))
} }
func (s *DockerSuite) TestExecTTYWithoutStdin(c *testing.T) { func (s *DockerCLIExecSuite) TestExecTTYWithoutStdin(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
@ -202,7 +214,7 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *testing.T) {
} }
// FIXME(vdemeester) this should be a unit tests on cli/command/container package // FIXME(vdemeester) this should be a unit tests on cli/command/container package
func (s *DockerSuite) TestExecParseError(c *testing.T) { func (s *DockerCLIExecSuite) TestExecParseError(c *testing.T) {
// TODO Windows CI: Requires some extra work. Consider copying the // TODO Windows CI: Requires some extra work. Consider copying the
// runSleepingContainer helper to have an exec version. // runSleepingContainer helper to have an exec version.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -216,7 +228,7 @@ func (s *DockerSuite) TestExecParseError(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestExecStopNotHanging(c *testing.T) { func (s *DockerCLIExecSuite) TestExecStopNotHanging(c *testing.T) {
// TODO Windows CI: Requires some extra work. Consider copying the // TODO Windows CI: Requires some extra work. Consider copying the
// runSleepingContainer helper to have an exec version. // runSleepingContainer helper to have an exec version.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -244,7 +256,7 @@ func (s *DockerSuite) TestExecStopNotHanging(c *testing.T) {
} }
} }
func (s *DockerSuite) TestExecCgroup(c *testing.T) { func (s *DockerCLIExecSuite) TestExecCgroup(c *testing.T) {
// Not applicable on Windows - using Linux specific functionality // Not applicable on Windows - using Linux specific functionality
testRequires(c, NotUserNamespace) testRequires(c, NotUserNamespace)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -297,7 +309,7 @@ func (s *DockerSuite) TestExecCgroup(c *testing.T) {
} }
} }
func (s *DockerSuite) TestExecInspectID(c *testing.T) { func (s *DockerCLIExecSuite) TestExecInspectID(c *testing.T) {
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
id := strings.TrimSuffix(out, "\n") id := strings.TrimSuffix(out, "\n")
@ -364,7 +376,7 @@ func (s *DockerSuite) TestExecInspectID(c *testing.T) {
assert.ErrorContains(c, err, "No such exec instance") assert.ErrorContains(c, err, "No such exec instance")
} }
func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *testing.T) { func (s *DockerCLIExecSuite) TestLinksPingLinkedContainersOnRename(c *testing.T) {
// Problematic on Windows as Windows does not support links // Problematic on Windows as Windows does not support links
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
var out string var out string
@ -380,7 +392,7 @@ func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *testing.T) {
dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
} }
func (s *DockerSuite) TestRunMutableNetworkFiles(c *testing.T) { func (s *DockerCLIExecSuite) TestRunMutableNetworkFiles(c *testing.T) {
// Not applicable on Windows to Windows CI. // Not applicable on Windows to Windows CI.
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
for _, fn := range []string{"resolv.conf", "hosts"} { for _, fn := range []string{"resolv.conf", "hosts"} {
@ -421,7 +433,7 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *testing.T) {
} }
} }
func (s *DockerSuite) TestExecWithUser(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWithUser(c *testing.T) {
// TODO Windows CI: This may be fixable in the future once Windows // TODO Windows CI: This may be fixable in the future once Windows
// supports users // supports users
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -434,7 +446,7 @@ func (s *DockerSuite) TestExecWithUser(c *testing.T) {
assert.Assert(c, strings.Contains(out, "uid=0(root) gid=0(root)"), "exec with user by id expected daemon user got %s", out) assert.Assert(c, strings.Contains(out, "uid=0(root) gid=0(root)"), "exec with user by id expected daemon user got %s", out)
} }
func (s *DockerSuite) TestExecWithPrivileged(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWithPrivileged(c *testing.T) {
// Not applicable on Windows // Not applicable on Windows
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
// Start main loop which attempts mknod repeatedly // Start main loop which attempts mknod repeatedly
@ -464,7 +476,7 @@ func (s *DockerSuite) TestExecWithPrivileged(c *testing.T) {
assert.Assert(c, !strings.Contains(result.Combined(), "Success")) assert.Assert(c, !strings.Contains(result.Combined(), "Success"))
} }
func (s *DockerSuite) TestExecWithImageUser(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWithImageUser(c *testing.T) {
// Not applicable on Windows // Not applicable on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testbuilduser" name := "testbuilduser"
@ -477,7 +489,7 @@ func (s *DockerSuite) TestExecWithImageUser(c *testing.T) {
assert.Assert(c, strings.Contains(out, "dockerio"), "exec with user by id expected dockerio user got %s", out) assert.Assert(c, strings.Contains(out, "dockerio"), "exec with user by id expected dockerio user got %s", out)
} }
func (s *DockerSuite) TestExecOnReadonlyContainer(c *testing.T) { func (s *DockerCLIExecSuite) TestExecOnReadonlyContainer(c *testing.T) {
// Windows does not support read-only // Windows does not support read-only
// --read-only + userns has remount issues // --read-only + userns has remount issues
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
@ -485,7 +497,7 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *testing.T) {
dockerCmd(c, "exec", "parent", "true") dockerCmd(c, "exec", "parent", "true")
} }
func (s *DockerSuite) TestExecUlimits(c *testing.T) { func (s *DockerCLIExecSuite) TestExecUlimits(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testexeculimits" name := "testexeculimits"
runSleepingContainer(c, "-d", "--ulimit", "nofile=511:511", "--name", name) runSleepingContainer(c, "-d", "--ulimit", "nofile=511:511", "--name", name)
@ -497,7 +509,7 @@ func (s *DockerSuite) TestExecUlimits(c *testing.T) {
} }
// #15750 // #15750
func (s *DockerSuite) TestExecStartFails(c *testing.T) { func (s *DockerCLIExecSuite) TestExecStartFails(c *testing.T) {
// TODO Windows CI. This test should be portable. Figure out why it fails // TODO Windows CI. This test should be portable. Figure out why it fails
// currently. // currently.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -511,7 +523,7 @@ func (s *DockerSuite) TestExecStartFails(c *testing.T) {
} }
// Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297 // Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297
func (s *DockerSuite) TestExecWindowsPathNotWiped(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWindowsPathNotWiped(c *testing.T) {
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60") out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60")
assert.NilError(c, waitRun(strings.TrimSpace(out))) assert.NilError(c, waitRun(strings.TrimSpace(out)))
@ -521,7 +533,7 @@ func (s *DockerSuite) TestExecWindowsPathNotWiped(c *testing.T) {
assert.Assert(c, strings.Contains(out, `windowspowershell\v1.0`)) assert.Assert(c, strings.Contains(out, `windowspowershell\v1.0`))
} }
func (s *DockerSuite) TestExecEnvLinksHost(c *testing.T) { func (s *DockerCLIExecSuite) TestExecEnvLinksHost(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
runSleepingContainer(c, "-d", "--name", "foo") runSleepingContainer(c, "-d", "--name", "foo")
runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar") runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar")

View file

@ -16,7 +16,7 @@ import (
) )
// regression test for #12546 // regression test for #12546
func (s *DockerSuite) TestExecInteractiveStdinClose(c *testing.T) { func (s *DockerCLIExecSuite) TestExecInteractiveStdinClose(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat") out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
contID := strings.TrimSpace(out) contID := strings.TrimSpace(out)
@ -45,7 +45,7 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *testing.T) {
} }
} }
func (s *DockerSuite) TestExecTTY(c *testing.T) { func (s *DockerCLIExecSuite) TestExecTTY(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
dockerCmd(c, "run", "-d", "--name=test", "busybox", "sh", "-c", "echo hello > /foo && top") dockerCmd(c, "run", "-d", "--name=test", "busybox", "sh", "-c", "echo hello > /foo && top")
@ -75,7 +75,7 @@ func (s *DockerSuite) TestExecTTY(c *testing.T) {
} }
// Test the TERM env var is set when -t is provided on exec // Test the TERM env var is set when -t is provided on exec
func (s *DockerSuite) TestExecWithTERM(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWithTERM(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
out, _ := dockerCmd(c, "run", "-id", "busybox", "/bin/cat") out, _ := dockerCmd(c, "run", "-id", "busybox", "/bin/cat")
contID := strings.TrimSpace(out) contID := strings.TrimSpace(out)
@ -87,7 +87,7 @@ func (s *DockerSuite) TestExecWithTERM(c *testing.T) {
// Test that the TERM env var is not set on exec when -t is not provided, even if it was set // Test that the TERM env var is not set on exec when -t is not provided, even if it was set
// on run // on run
func (s *DockerSuite) TestExecWithNoTERM(c *testing.T) { func (s *DockerCLIExecSuite) TestExecWithNoTERM(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat") out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
contID := strings.TrimSpace(out) contID := strings.TrimSpace(out)

View file

@ -12,6 +12,18 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
type DockerCLIHealthSuite struct {
ds *DockerSuite
}
func (s *DockerCLIHealthSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIHealthSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func waitForHealthStatus(c *testing.T, name string, prev string, expected string) { func waitForHealthStatus(c *testing.T, name string, prev string, expected string) {
prev = prev + "\n" prev = prev + "\n"
expected = expected + "\n" expected = expected + "\n"
@ -36,7 +48,7 @@ func getHealth(c *testing.T, name string) *types.Health {
return &health return &health
} }
func (s *DockerSuite) TestHealth(c *testing.T) { func (s *DockerCLIHealthSuite) TestHealth(c *testing.T) {
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
@ -144,7 +156,7 @@ func (s *DockerSuite) TestHealth(c *testing.T) {
} }
// GitHub #33021 // GitHub #33021
func (s *DockerSuite) TestUnsetEnvVarHealthCheck(c *testing.T) { func (s *DockerCLIHealthSuite) TestUnsetEnvVarHealthCheck(c *testing.T) {
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
imageName := "testhealth" imageName := "testhealth"

View file

@ -12,9 +12,21 @@ import (
"gotest.tools/v3/assert/cmp" "gotest.tools/v3/assert/cmp"
) )
type DockerCLIHistorySuite struct {
ds *DockerSuite
}
func (s *DockerCLIHistorySuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIHistorySuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// This is a heisen-test. Because the created timestamp of images and the behavior of // This is a heisen-test. Because the created timestamp of images and the behavior of
// sort is not predictable it doesn't always fail. // sort is not predictable it doesn't always fail.
func (s *DockerSuite) TestBuildHistory(c *testing.T) { func (s *DockerCLIHistorySuite) TestBuildHistory(c *testing.T) {
name := "testbuildhistory" name := "testbuildhistory"
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM `+minimalBaseImage()+` buildImageSuccessfully(c, name, build.WithDockerfile(`FROM `+minimalBaseImage()+`
LABEL label.A="A" LABEL label.A="A"
@ -56,16 +68,16 @@ LABEL label.Z="Z"`))
} }
func (s *DockerSuite) TestHistoryExistentImage(c *testing.T) { func (s *DockerCLIHistorySuite) TestHistoryExistentImage(c *testing.T) {
dockerCmd(c, "history", "busybox") dockerCmd(c, "history", "busybox")
} }
func (s *DockerSuite) TestHistoryNonExistentImage(c *testing.T) { func (s *DockerCLIHistorySuite) TestHistoryNonExistentImage(c *testing.T) {
_, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage") _, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage")
assert.Assert(c, err != nil, "history on a non-existent image should fail.") assert.Assert(c, err != nil, "history on a non-existent image should fail.")
} }
func (s *DockerSuite) TestHistoryImageWithComment(c *testing.T) { func (s *DockerCLIHistorySuite) TestHistoryImageWithComment(c *testing.T) {
name := "testhistoryimagewithcomment" name := "testhistoryimagewithcomment"
// make an image through docker commit <container id> [ -m messages ] // make an image through docker commit <container id> [ -m messages ]
@ -84,7 +96,7 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *testing.T) {
assert.Assert(c, strings.Contains(actualValue, comment)) assert.Assert(c, strings.Contains(actualValue, comment))
} }
func (s *DockerSuite) TestHistoryHumanOptionFalse(c *testing.T) { func (s *DockerCLIHistorySuite) TestHistoryHumanOptionFalse(c *testing.T) {
out, _ := dockerCmd(c, "history", "--human=false", "busybox") out, _ := dockerCmd(c, "history", "--human=false", "busybox")
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
sizeColumnRegex, _ := regexp.Compile("SIZE +") sizeColumnRegex, _ := regexp.Compile("SIZE +")
@ -102,7 +114,7 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *testing.T) {
} }
} }
func (s *DockerSuite) TestHistoryHumanOptionTrue(c *testing.T) { func (s *DockerCLIHistorySuite) TestHistoryHumanOptionTrue(c *testing.T) {
out, _ := dockerCmd(c, "history", "--human=true", "busybox") out, _ := dockerCmd(c, "history", "--human=true", "busybox")
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
sizeColumnRegex, _ := regexp.Compile("SIZE +") sizeColumnRegex, _ := regexp.Compile("SIZE +")

View file

@ -17,12 +17,24 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *testing.T) { type DockerCLIImagesSuite struct {
ds *DockerSuite
}
func (s *DockerCLIImagesSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIImagesSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIImagesSuite) TestImagesEnsureImageIsListed(c *testing.T) {
imagesOut, _ := dockerCmd(c, "images") imagesOut, _ := dockerCmd(c, "images")
assert.Assert(c, strings.Contains(imagesOut, "busybox")) assert.Assert(c, strings.Contains(imagesOut, "busybox"))
} }
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureImageWithTagIsListed(c *testing.T) {
name := "imagewithtag" name := "imagewithtag"
dockerCmd(c, "tag", "busybox", name+":v1") dockerCmd(c, "tag", "busybox", name+":v1")
dockerCmd(c, "tag", "busybox", name+":v1v1") dockerCmd(c, "tag", "busybox", name+":v1v1")
@ -40,12 +52,12 @@ func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *testing.T) {
assert.Assert(c, strings.Contains(imagesOut, "v2")) assert.Assert(c, strings.Contains(imagesOut, "v2"))
} }
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *testing.T) {
imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent") imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent")
assert.Assert(c, !strings.Contains(imagesOut, "busybox")) assert.Assert(c, !strings.Contains(imagesOut, "busybox"))
} }
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesOrderedByCreationDate(c *testing.T) {
buildImageSuccessfully(c, "order:test_a", build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, "order:test_a", build.WithDockerfile(`FROM busybox
MAINTAINER dockerio1`)) MAINTAINER dockerio1`))
id1 := getIDByName(c, "order:test_a") id1 := getIDByName(c, "order:test_a")
@ -65,13 +77,13 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *testing.T) {
assert.Equal(c, imgs[2], id1, fmt.Sprintf("First image must be %s, got %s", id1, imgs[2])) assert.Equal(c, imgs[2], id1, fmt.Sprintf("First image must be %s, got %s", id1, imgs[2]))
} }
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesErrorWithInvalidFilterNameTest(c *testing.T) {
out, _, err := dockerCmdWithError("images", "-f", "FOO=123") out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "invalid filter")) assert.Assert(c, strings.Contains(out, "invalid filter"))
} }
func (s *DockerSuite) TestImagesFilterLabelMatch(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFilterLabelMatch(c *testing.T) {
imageName1 := "images_filter_test1" imageName1 := "images_filter_test1"
imageName2 := "images_filter_test2" imageName2 := "images_filter_test2"
imageName3 := "images_filter_test3" imageName3 := "images_filter_test3"
@ -101,7 +113,7 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *testing.T) {
} }
// Regression : #15659 // Regression : #15659
func (s *DockerSuite) TestCommitWithFilterLabel(c *testing.T) { func (s *DockerCLIImagesSuite) TestCommitWithFilterLabel(c *testing.T) {
// Create a container // Create a container
dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh") dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh")
// Commit with labels "using changes" // Commit with labels "using changes"
@ -113,7 +125,7 @@ func (s *DockerSuite) TestCommitWithFilterLabel(c *testing.T) {
assert.Equal(c, out, imageID) assert.Equal(c, out, imageID)
} }
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFilterSinceAndBefore(c *testing.T) {
buildImageSuccessfully(c, "image:1", build.WithDockerfile(`FROM `+minimalBaseImage()+` buildImageSuccessfully(c, "image:1", build.WithDockerfile(`FROM `+minimalBaseImage()+`
LABEL number=1`)) LABEL number=1`))
imageID1 := getIDByName(c, "image:1") imageID1 := getIDByName(c, "image:1")
@ -183,7 +195,7 @@ func assertImageList(out string, expected []string) bool {
} }
// FIXME(vdemeester) should be a unit test on `docker image ls` // FIXME(vdemeester) should be a unit test on `docker image ls`
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFilterSpaceTrimCase(c *testing.T) {
imageName := "images_filter_test" imageName := "images_filter_test"
// Build a image and fail to build so that we have dangling images ? // Build a image and fail to build so that we have dangling images ?
buildImage(imageName, build.WithDockerfile(`FROM busybox buildImage(imageName, build.WithDockerfile(`FROM busybox
@ -223,7 +235,7 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *testing.T) {
} }
} }
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// create container 1 // create container 1
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
@ -249,13 +261,13 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *testing.T)
} }
// FIXME(vdemeester) should be a unit test for `docker image ls` // FIXME(vdemeester) should be a unit test for `docker image ls`
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesWithIncorrectFilter(c *testing.T) {
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "invalid filter")) assert.Assert(c, strings.Contains(out, "invalid filter"))
} }
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureOnlyHeadsImagesShown(c *testing.T) {
dockerfile := ` dockerfile := `
FROM busybox FROM busybox
MAINTAINER docker MAINTAINER docker
@ -278,7 +290,7 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *testing.T) {
assert.Assert(c, strings.Contains(out, stringid.TruncateID(id))) assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
} }
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureImagesFromScratchShown(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch
dockerfile := ` dockerfile := `
FROM scratch FROM scratch
@ -295,7 +307,7 @@ func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *testing.T) {
// For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows // For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows
// doesn't support from scratch // doesn't support from scratch
func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesEnsureImagesFromBusyboxShown(c *testing.T) {
dockerfile := ` dockerfile := `
FROM busybox FROM busybox
MAINTAINER docker` MAINTAINER docker`
@ -310,7 +322,7 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *testing.T) {
} }
// #18181 // #18181
func (s *DockerSuite) TestImagesFilterNameWithPort(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFilterNameWithPort(c *testing.T) {
tag := "a.b.c.d:5000/hello" tag := "a.b.c.d:5000/hello"
dockerCmd(c, "tag", "busybox", tag) dockerCmd(c, "tag", "busybox", tag)
out, _ := dockerCmd(c, "images", tag) out, _ := dockerCmd(c, "images", tag)
@ -321,7 +333,7 @@ func (s *DockerSuite) TestImagesFilterNameWithPort(c *testing.T) {
assert.Assert(c, !strings.Contains(out, tag)) assert.Assert(c, !strings.Contains(out, tag))
} }
func (s *DockerSuite) TestImagesFormat(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFormat(c *testing.T) {
// testRequires(c, DaemonIsLinux) // testRequires(c, DaemonIsLinux)
tag := "myimage" tag := "myimage"
dockerCmd(c, "tag", "busybox", tag+":v1") dockerCmd(c, "tag", "busybox", tag+":v1")
@ -337,7 +349,7 @@ func (s *DockerSuite) TestImagesFormat(c *testing.T) {
} }
// ImagesDefaultFormatAndQuiet // ImagesDefaultFormatAndQuiet
func (s *DockerSuite) TestImagesFormatDefaultFormat(c *testing.T) { func (s *DockerCLIImagesSuite) TestImagesFormatDefaultFormat(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// create container 1 // create container 1

View file

@ -14,7 +14,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestImportDisplay(c *testing.T) { type DockerCLIImportSuite struct {
ds *DockerSuite
}
func (s *DockerCLIImportSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIImportSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIImportSuite) TestImportDisplay(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -32,7 +44,7 @@ func (s *DockerSuite) TestImportDisplay(c *testing.T) {
assert.Equal(c, out, "", "command output should've been nothing.") assert.Equal(c, out, "", "command output should've been nothing.")
} }
func (s *DockerSuite) TestImportBadURL(c *testing.T) { func (s *DockerCLIImportSuite) TestImportBadURL(c *testing.T) {
out, _, err := dockerCmdWithError("import", "https://nosuchdomain.invalid/bad") out, _, err := dockerCmdWithError("import", "https://nosuchdomain.invalid/bad")
assert.Assert(c, err != nil, "import was supposed to fail but didn't") assert.Assert(c, err != nil, "import was supposed to fail but didn't")
// Depending on your system you can get either of these errors // Depending on your system you can get either of these errors
@ -43,7 +55,7 @@ func (s *DockerSuite) TestImportBadURL(c *testing.T) {
} }
} }
func (s *DockerSuite) TestImportFile(c *testing.T) { func (s *DockerCLIImportSuite) TestImportFile(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "test-import", "busybox", "true") dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
@ -64,7 +76,7 @@ func (s *DockerSuite) TestImportFile(c *testing.T) {
assert.Equal(c, out, "", "command output should've been nothing.") assert.Equal(c, out, "", "command output should've been nothing.")
} }
func (s *DockerSuite) TestImportGzipped(c *testing.T) { func (s *DockerCLIImportSuite) TestImportGzipped(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "test-import", "busybox", "true") dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
@ -87,7 +99,7 @@ func (s *DockerSuite) TestImportGzipped(c *testing.T) {
assert.Equal(c, out, "", "command output should've been nothing.") assert.Equal(c, out, "", "command output should've been nothing.")
} }
func (s *DockerSuite) TestImportFileWithMessage(c *testing.T) { func (s *DockerCLIImportSuite) TestImportFileWithMessage(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "test-import", "busybox", "true") dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
@ -118,12 +130,12 @@ func (s *DockerSuite) TestImportFileWithMessage(c *testing.T) {
assert.Equal(c, out, "", "command output should've been nothing") assert.Equal(c, out, "", "command output should've been nothing")
} }
func (s *DockerSuite) TestImportFileNonExistentFile(c *testing.T) { func (s *DockerCLIImportSuite) TestImportFileNonExistentFile(c *testing.T) {
_, _, err := dockerCmdWithError("import", "example.com/myImage.tar") _, _, err := dockerCmdWithError("import", "example.com/myImage.tar")
assert.Assert(c, err != nil, "import non-existing file must failed") assert.Assert(c, err != nil, "import non-existing file must failed")
} }
func (s *DockerSuite) TestImportWithQuotedChanges(c *testing.T) { func (s *DockerCLIImportSuite) TestImportWithQuotedChanges(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
cli.DockerCmd(c, "run", "--name", "test-import", "busybox", "true") cli.DockerCmd(c, "run", "--name", "test-import", "busybox", "true")

View file

@ -9,8 +9,20 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
type DockerCLIInfoSuite struct {
ds *DockerSuite
}
func (s *DockerCLIInfoSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIInfoSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// ensure docker info succeeds // ensure docker info succeeds
func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) { func (s *DockerCLIInfoSuite) TestInfoEnsureSucceeds(c *testing.T) {
out, _ := dockerCmd(c, "info") out, _ := dockerCmd(c, "info")
// always shown fields // always shown fields
@ -53,7 +65,7 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) {
} }
} }
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *testing.T) { func (s *DockerCLIInfoSuite) TestInfoDisplaysRunningContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
existing := existingContainerStates(c) existing := existingContainerStates(c)
@ -66,7 +78,7 @@ func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *testing.T) {
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))) assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
} }
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *testing.T) { func (s *DockerCLIInfoSuite) TestInfoDisplaysPausedContainers(c *testing.T) {
testRequires(c, IsPausable) testRequires(c, IsPausable)
existing := existingContainerStates(c) existing := existingContainerStates(c)
@ -83,7 +95,7 @@ func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *testing.T) {
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))) assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
} }
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *testing.T) { func (s *DockerCLIInfoSuite) TestInfoDisplaysStoppedContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
existing := existingContainerStates(c) existing := existingContainerStates(c)

View file

@ -13,7 +13,7 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestInfoSecurityOptions(c *testing.T) { func (s *DockerCLIInfoSuite) TestInfoSecurityOptions(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
if !seccompEnabled() && !Apparmor() { if !seccompEnabled() && !Apparmor() {
c.Skip("test requires Seccomp and/or AppArmor") c.Skip("test requires Seccomp and/or AppArmor")

View file

@ -15,13 +15,25 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
type DockerCLIInspectSuite struct {
ds *DockerSuite
}
func (s *DockerCLIInspectSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIInspectSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func checkValidGraphDriver(c *testing.T, name string) { func checkValidGraphDriver(c *testing.T, name string) {
if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" { if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" {
c.Fatalf("%v is not a valid graph driver name", name) c.Fatalf("%v is not a valid graph driver name", name)
} }
} }
func (s *DockerSuite) TestInspectImage(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
imageTest := "emptyfs" imageTest := "emptyfs"
// It is important that this ID remain stable. If a code change causes // It is important that this ID remain stable. If a code change causes
@ -35,13 +47,13 @@ func (s *DockerSuite) TestInspectImage(c *testing.T) {
assert.Equal(c, id, imageTestID) assert.Equal(c, id, imageTestID)
} }
func (s *DockerSuite) TestInspectInt64(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectInt64(c *testing.T) {
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true") dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory") inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
assert.Equal(c, inspectOut, "314572800") assert.Equal(c, inspectOut, "314572800")
} }
func (s *DockerSuite) TestInspectDefault(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) {
// Both the container and image are named busybox. docker inspect will fetch the container JSON. // Both the container and image are named busybox. docker inspect will fetch the container JSON.
// If the container JSON is not available, it will go for the image JSON. // If the container JSON is not available, it will go for the image JSON.
@ -52,7 +64,7 @@ func (s *DockerSuite) TestInspectDefault(c *testing.T) {
assert.Equal(c, strings.TrimSpace(inspectOut), containerID) assert.Equal(c, strings.TrimSpace(inspectOut), containerID)
} }
func (s *DockerSuite) TestInspectStatus(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectStatus(c *testing.T) {
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
@ -77,7 +89,7 @@ func (s *DockerSuite) TestInspectStatus(c *testing.T) {
} }
func (s *DockerSuite) TestInspectTypeFlagContainer(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTypeFlagContainer(c *testing.T) {
// Both the container and image are named busybox. docker inspect will fetch container // Both the container and image are named busybox. docker inspect will fetch container
// JSON State.Running field. If the field is true, it's a container. // JSON State.Running field. If the field is true, it's a container.
runSleepingContainer(c, "--name=busybox", "-d") runSleepingContainer(c, "--name=busybox", "-d")
@ -87,7 +99,7 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *testing.T) {
assert.Equal(c, out, "true\n") // not a container JSON assert.Equal(c, out, "true\n") // not a container JSON
} }
func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) {
// Run this test on an image named busybox. docker inspect will try to fetch container // Run this test on an image named busybox. docker inspect will try to fetch container
// JSON. Since there is no container named busybox and --type=container, docker inspect will // JSON. Since there is no container named busybox and --type=container, docker inspect will
// not try to get the image JSON. It will throw an error. // not try to get the image JSON. It will throw an error.
@ -99,7 +111,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) {
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
} }
func (s *DockerSuite) TestInspectTypeFlagWithImage(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithImage(c *testing.T) {
// Both the container and image are named busybox. docker inspect will fetch image // Both the container and image are named busybox. docker inspect will fetch image
// JSON as --type=image. if there is no image with name busybox, docker inspect // JSON as --type=image. if there is no image with name busybox, docker inspect
// will throw an error. // will throw an error.
@ -111,7 +123,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *testing.T) {
assert.Assert(c, !strings.Contains(out, "State")) assert.Assert(c, !strings.Contains(out, "State"))
} }
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
// Both the container and image are named busybox. docker inspect will fail // Both the container and image are named busybox. docker inspect will fail
// as --type=foobar is not a valid value for the flag. // as --type=foobar is not a valid value for the flag.
@ -123,7 +135,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
assert.Assert(c, strings.Contains(out, "not a valid value for --type")) assert.Assert(c, strings.Contains(out, "not a valid value for --type"))
} }
func (s *DockerSuite) TestInspectImageFilterInt(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectImageFilterInt(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
imageTest := "emptyfs" imageTest := "emptyfs"
out := inspectField(c, imageTest, "Size") out := inspectField(c, imageTest, "Size")
@ -139,7 +151,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *testing.T) {
assert.Equal(c, result, true) assert.Equal(c, result, true)
} }
func (s *DockerSuite) TestInspectContainerFilterInt(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectContainerFilterInt(c *testing.T) {
result := icmd.RunCmd(icmd.Cmd{ result := icmd.RunCmd(icmd.Cmd{
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"}, Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
Stdin: strings.NewReader("blahblah"), Stdin: strings.NewReader("blahblah"),
@ -161,7 +173,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *testing.T) {
assert.Equal(c, inspectResult, true) assert.Equal(c, inspectResult, true)
} }
func (s *DockerSuite) TestInspectImageGraphDriver(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectImageGraphDriver(c *testing.T) {
testRequires(c, DaemonIsLinux, Devicemapper) testRequires(c, DaemonIsLinux, Devicemapper)
imageTest := "emptyfs" imageTest := "emptyfs"
name := inspectField(c, imageTest, "GraphDriver.Name") name := inspectField(c, imageTest, "GraphDriver.Name")
@ -179,7 +191,7 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *testing.T) {
assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err) assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)
} }
func (s *DockerSuite) TestInspectContainerGraphDriver(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectContainerGraphDriver(c *testing.T) {
testRequires(c, DaemonIsLinux, Devicemapper) testRequires(c, DaemonIsLinux, Devicemapper)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
@ -204,7 +216,7 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *testing.T) {
assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err) assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)
} }
func (s *DockerSuite) TestInspectBindMountPoint(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
modifier := ",z" modifier := ",z"
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
if testEnv.OSType == "windows" { if testEnv.OSType == "windows" {
@ -236,7 +248,7 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *testing.T) {
assert.Equal(c, m.RW, false) assert.Equal(c, m.RW, false)
} }
func (s *DockerSuite) TestInspectNamedMountPoint(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat") dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
@ -260,7 +272,7 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *testing.T) {
} }
// #14947 // #14947
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
startedAt := inspectField(c, id, "State.StartedAt") startedAt := inspectField(c, id, "State.StartedAt")
@ -281,7 +293,7 @@ func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
} }
// #15633 // #15633
func (s *DockerSuite) TestInspectLogConfigNoType(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectLogConfigNoType(c *testing.T) {
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox") dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
var logConfig container.LogConfig var logConfig container.LogConfig
@ -294,7 +306,7 @@ func (s *DockerSuite) TestInspectLogConfigNoType(c *testing.T) {
assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig)) assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig))
} }
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
// Both the container and image are named busybox. docker inspect will fetch container // Both the container and image are named busybox. docker inspect will fetch container
// JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields. // JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields.
@ -305,7 +317,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out)) assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out))
} }
func (s *DockerSuite) TestInspectSizeFlagContainer(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectSizeFlagContainer(c *testing.T) {
runSleepingContainer(c, "--name=busybox", "-d") runSleepingContainer(c, "--name=busybox", "-d")
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'" formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
@ -316,7 +328,7 @@ func (s *DockerSuite) TestInspectSizeFlagContainer(c *testing.T) {
assert.Assert(c, strings.TrimSpace(sz[1]) != "<nil>") assert.Assert(c, strings.TrimSpace(sz[1]) != "<nil>")
} }
func (s *DockerSuite) TestInspectTemplateError(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectTemplateError(c *testing.T) {
// Template parsing error for both the container and image. // Template parsing error for both the container and image.
runSleepingContainer(c, "--name=container1", "-d") runSleepingContainer(c, "--name=container1", "-d")
@ -329,7 +341,7 @@ func (s *DockerSuite) TestInspectTemplateError(c *testing.T) {
assert.Assert(c, strings.Contains(out, "Template parsing error")) assert.Assert(c, strings.Contains(out, "Template parsing error"))
} }
func (s *DockerSuite) TestInspectJSONFields(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectJSONFields(c *testing.T) {
runSleepingContainer(c, "--name=busybox", "-d") runSleepingContainer(c, "--name=busybox", "-d")
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox") out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox")
@ -337,7 +349,7 @@ func (s *DockerSuite) TestInspectJSONFields(c *testing.T) {
assert.Equal(c, out, "[]\n") assert.Equal(c, out, "[]\n")
} }
func (s *DockerSuite) TestInspectByPrefix(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectByPrefix(c *testing.T) {
id := inspectField(c, "busybox", "Id") id := inspectField(c, "busybox", "Id")
assert.Assert(c, strings.HasPrefix(id, "sha256:")) assert.Assert(c, strings.HasPrefix(id, "sha256:"))
@ -348,7 +360,7 @@ func (s *DockerSuite) TestInspectByPrefix(c *testing.T) {
assert.Equal(c, id, id3) assert.Equal(c, id, id3)
} }
func (s *DockerSuite) TestInspectStopWhenNotFound(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectStopWhenNotFound(c *testing.T) {
runSleepingContainer(c, "--name=busybox1", "-d") runSleepingContainer(c, "--name=busybox1", "-d")
runSleepingContainer(c, "--name=busybox2", "-d") runSleepingContainer(c, "--name=busybox2", "-d")
result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing") result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing")
@ -366,7 +378,7 @@ func (s *DockerSuite) TestInspectStopWhenNotFound(c *testing.T) {
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing")) assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
} }
func (s *DockerSuite) TestInspectHistory(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectHistory(c *testing.T) {
dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello") dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg") dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg") out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
@ -374,7 +386,7 @@ func (s *DockerSuite) TestInspectHistory(c *testing.T) {
assert.Assert(c, strings.Contains(out, "test comment")) assert.Assert(c, strings.Contains(out, "test comment"))
} }
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
contName := "test1" contName := "test1"
@ -386,7 +398,7 @@ func (s *DockerSuite) TestInspectContainerNetworkDefault(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut)) assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
} }
func (s *DockerSuite) TestInspectContainerNetworkCustom(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectContainerNetworkCustom(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
netOut, _ := dockerCmd(c, "network", "create", "net1") netOut, _ := dockerCmd(c, "network", "create", "net1")
@ -397,7 +409,7 @@ func (s *DockerSuite) TestInspectContainerNetworkCustom(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut)) assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
} }
func (s *DockerSuite) TestInspectRootFS(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectRootFS(c *testing.T) {
out, _, err := dockerCmdWithError("inspect", "busybox") out, _, err := dockerCmdWithError("inspect", "busybox")
assert.NilError(c, err) assert.NilError(c, err)
@ -407,7 +419,7 @@ func (s *DockerSuite) TestInspectRootFS(c *testing.T) {
assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1) assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1)
} }
func (s *DockerSuite) TestInspectAmpersand(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectAmpersand(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test" name := "test"
@ -417,7 +429,7 @@ func (s *DockerSuite) TestInspectAmpersand(c *testing.T) {
assert.Assert(c, strings.Contains(out, `soanni&rtr`)) assert.Assert(c, strings.Contains(out, `soanni&rtr`))
} }
func (s *DockerSuite) TestInspectPlugin(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectPlugin(c *testing.T) {
testRequires(c, DaemonIsLinux, IsAmd64, Network) testRequires(c, DaemonIsLinux, IsAmd64, Network)
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
assert.NilError(c, err) assert.NilError(c, err)
@ -448,7 +460,7 @@ func (s *DockerSuite) TestInspectPlugin(c *testing.T) {
} }
// Test case for 29185 // Test case for 29185
func (s *DockerSuite) TestInspectUnknownObject(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectUnknownObject(c *testing.T) {
// This test should work on both Windows and Linux // This test should work on both Windows and Linux
out, _, err := dockerCmdWithError("inspect", "foobar") out, _, err := dockerCmdWithError("inspect", "foobar")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")

View file

@ -13,7 +13,19 @@ import (
"gotest.tools/v3/assert/cmp" "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *testing.T) { type DockerCLILinksSuite struct {
ds *DockerSuite
}
func (s *DockerCLILinksSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLILinksSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLILinksSuite) TestLinksPingUnlinkedContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
_, exitCode, err := dockerCmdWithError("run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") _, exitCode, err := dockerCmdWithError("run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
@ -22,7 +34,7 @@ func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *testing.T) {
} }
// Test for appropriate error when calling --link with an invalid target container // Test for appropriate error when calling --link with an invalid target container
func (s *DockerSuite) TestLinksInvalidContainerTarget(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksInvalidContainerTarget(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true") out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true")
@ -34,7 +46,7 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *testing.T) {
assert.Assert(c, strings.Contains(strings.ToLower(out), "could not get container")) assert.Assert(c, strings.Contains(strings.ToLower(out), "could not get container"))
} }
func (s *DockerSuite) TestLinksPingLinkedContainers(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksPingLinkedContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Test with the three different ways of specifying the default network on Linux // Test with the three different ways of specifying the default network on Linux
testLinkPingOnNetwork(c, "") testLinkPingOnNetwork(c, "")
@ -78,7 +90,7 @@ func testLinkPingOnNetwork(c *testing.T, network string) {
dockerCmd(c, "rm", "-f", "container2") dockerCmd(c, "rm", "-f", "container2")
} }
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
idA := strings.TrimSpace(out) idA := strings.TrimSpace(out)
@ -91,7 +103,7 @@ func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
} }
func (s *DockerSuite) TestLinksInspectLinksStarted(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
@ -110,7 +122,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *testing.T) {
assert.DeepEqual(c, result, expected) assert.DeepEqual(c, result, expected)
} }
func (s *DockerSuite) TestLinksInspectLinksStopped(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
@ -130,7 +142,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *testing.T) {
assert.DeepEqual(c, result, expected) assert.DeepEqual(c, result, expected)
} }
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "--name=first", "busybox", "top") dockerCmd(c, "create", "--name=first", "busybox", "top")
dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top") dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
@ -138,7 +150,7 @@ func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
} }
func (s *DockerSuite) TestLinksHostsFilesInject(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
@ -156,7 +168,7 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *testing.T) {
assert.Assert(c, strings.Contains(string(contentTwo), "onetwo")) assert.Assert(c, strings.Contains(string(contentTwo), "onetwo"))
} }
func (s *DockerSuite) TestLinksUpdateOnRestart(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
@ -189,7 +201,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *testing.T) {
assert.Equal(c, ip, realIP) assert.Equal(c, ip, realIP)
} }
func (s *DockerSuite) TestLinksEnvs(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top") dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env") out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env")
@ -198,7 +210,7 @@ func (s *DockerSuite) TestLinksEnvs(c *testing.T) {
assert.Assert(c, strings.Contains(out, "FIRST_ENV_e3=v3=v3")) assert.Assert(c, strings.Contains(out, "FIRST_ENV_e3=v3=v3"))
} }
func (s *DockerSuite) TestLinkShortDefinition(c *testing.T) { func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
@ -214,7 +226,7 @@ func (s *DockerSuite) TestLinkShortDefinition(c *testing.T) {
assert.Equal(c, links, "[\"/shortlinkdef:/link2/shortlinkdef\"]") assert.Equal(c, links, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
} }
func (s *DockerSuite) TestLinksNetworkHostContainer(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top") dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true") out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
@ -225,14 +237,14 @@ func (s *DockerSuite) TestLinksNetworkHostContainer(c *testing.T) {
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error())) assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error()))
} }
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksEtcHostsRegularFile(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
// /etc/hosts should be a regular file // /etc/hosts should be a regular file
assert.Assert(c, cmp.Regexp("^-.+\n$", out)) assert.Assert(c, cmp.Regexp("^-.+\n$", out))
} }
func (s *DockerSuite) TestLinksMultipleWithSameName(c *testing.T) { func (s *DockerCLILinksSuite) TestLinksMultipleWithSameName(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top") dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top") dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")

View file

@ -9,7 +9,19 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestLoginWithoutTTY(c *testing.T) { type DockerCLILoginSuite struct {
ds *DockerSuite
}
func (s *DockerCLILoginSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLILoginSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLILoginSuite) TestLoginWithoutTTY(c *testing.T) {
cmd := exec.Command(dockerBinary, "login") cmd := exec.Command(dockerBinary, "login")
// Send to stdin so the process does not get the TTY // Send to stdin so the process does not get the TTY

View file

@ -1,31 +0,0 @@
package main
import (
"fmt"
"strings"
"testing"
"time"
)
func (s *DockerSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) {
out, _ := dockerCmd(c, "run", "-d", "--log-opt", "max-size=1b", "--log-opt", "max-file=10", "busybox", "sh", "-c", "while true; do usleep 50000; echo hello; done")
id := strings.TrimSpace(out)
ch := make(chan error, 1)
go func() {
ch <- nil
out, _, _ := dockerCmdWithError("logs", "-f", id)
// if this returns at all, it's an error
ch <- fmt.Errorf(out)
}()
<-ch
select {
case <-time.After(30 * time.Second):
// ran for 30 seconds with no problem
return
case err := <-ch:
if err != nil {
c.Fatal(err)
}
}
}

View file

@ -15,18 +15,30 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
type DockerCLILogsSuite struct {
ds *DockerSuite
}
func (s *DockerCLILogsSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLILogsSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// This used to work, it test a log of PageSize-1 (gh#4851) // This used to work, it test a log of PageSize-1 (gh#4851)
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsContainerSmallerThanPage(c *testing.T) {
testLogsContainerPagination(c, 32767) testLogsContainerPagination(c, 32767)
} }
// Regression test: When going over the PageSize, it used to panic (gh#4851) // Regression test: When going over the PageSize, it used to panic (gh#4851)
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsContainerBiggerThanPage(c *testing.T) {
testLogsContainerPagination(c, 32768) testLogsContainerPagination(c, 32768)
} }
// Regression test: When going much over the PageSize, it used to block (gh#4851) // Regression test: When going much over the PageSize, it used to block (gh#4851)
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsContainerMuchBiggerThanPage(c *testing.T) {
testLogsContainerPagination(c, 33000) testLogsContainerPagination(c, 33000)
} }
@ -38,7 +50,7 @@ func testLogsContainerPagination(c *testing.T, testLen int) {
assert.Equal(c, len(out), testLen+1) assert.Equal(c, len(out), testLen+1)
} }
func (s *DockerSuite) TestLogsTimestamps(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsTimestamps(c *testing.T) {
testLen := 100 testLen := 100
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen)) out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen))
@ -63,7 +75,7 @@ func (s *DockerSuite) TestLogsTimestamps(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsSeparateStderr(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsSeparateStderr(c *testing.T) {
msg := "stderr_log" msg := "stderr_log"
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined() out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -74,7 +86,7 @@ func (s *DockerSuite) TestLogsSeparateStderr(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestLogsStderrInStdout(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsStderrInStdout(c *testing.T) {
// TODO Windows: Needs investigation why this fails. Obtained string includes // TODO Windows: Needs investigation why this fails. Obtained string includes
// a bunch of ANSI escape sequences before the "stderr_log" message. // a bunch of ANSI escape sequences before the "stderr_log" message.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -89,7 +101,7 @@ func (s *DockerSuite) TestLogsStderrInStdout(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestLogsTail(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsTail(c *testing.T) {
testLen := 100 testLen := 100
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)).Combined() out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)).Combined()
@ -121,7 +133,7 @@ func (s *DockerSuite) TestLogsTail(c *testing.T) {
assert.Equal(c, len(lines), testLen+1) assert.Equal(c, len(lines), testLen+1)
} }
func (s *DockerSuite) TestLogsFollowStopped(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsFollowStopped(c *testing.T) {
dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello")
id := getIDByName(c, "test") id := getIDByName(c, "test")
@ -142,7 +154,7 @@ func (s *DockerSuite) TestLogsFollowStopped(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsSince(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsSince(c *testing.T) {
name := "testlogssince" name := "testlogssince"
dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done") dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done")
out, _ := dockerCmd(c, "logs", "-t", name) out, _ := dockerCmd(c, "logs", "-t", name)
@ -177,7 +189,7 @@ func (s *DockerSuite) TestLogsSince(c *testing.T) {
} }
} }
func (s *DockerSuite) TestLogsSinceFutureFollow(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsSinceFutureFollow(c *testing.T) {
// TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now. // TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testlogssincefuturefollow" name := "testlogssincefuturefollow"
@ -211,7 +223,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *testing.T) {
} }
// Regression test for #8832 // Regression test for #8832
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsFollowSlowStdoutConsumer(c *testing.T) {
// TODO Windows: Fix this test for TP5. // TODO Windows: Fix this test for TP5.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
expected := 150000 expected := 150000
@ -269,7 +281,7 @@ func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, s
} }
} }
func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
@ -297,7 +309,7 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
assert.NilError(c, waitForGoroutines(nroutines)) assert.NilError(c, waitForGoroutines(nroutines))
} }
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 2; done") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 2; done")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
@ -315,14 +327,14 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
assert.NilError(c, waitForGoroutines(nroutines)) assert.NilError(c, waitForGoroutines(nroutines))
} }
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsCLIContainerNotFound(c *testing.T) {
name := "testlogsnocontainer" name := "testlogsnocontainer"
out, _, _ := dockerCmdWithError("logs", name) out, _, _ := dockerCmdWithError("logs", name)
message := fmt.Sprintf("No such container: %s\n", name) message := fmt.Sprintf("No such container: %s\n", name)
assert.Assert(c, strings.Contains(out, message)) assert.Assert(c, strings.Contains(out, message))
} }
func (s *DockerSuite) TestLogsWithDetails(c *testing.T) { func (s *DockerCLILogsSuite) TestLogsWithDetails(c *testing.T) {
dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello") dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello")
out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test") out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test")

View file

@ -14,6 +14,18 @@ import (
// the command executed in a container did really run PS correctly. // the command executed in a container did really run PS correctly.
const stringCheckPS = "PID USER" const stringCheckPS = "PID USER"
type DockerCLINetmodeSuite struct {
ds *DockerSuite
}
func (s *DockerCLINetmodeSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLINetmodeSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// DockerCmdWithFail executes a docker command that is supposed to fail and returns // DockerCmdWithFail executes a docker command that is supposed to fail and returns
// the output, the exit code. If the command returns a Nil error, it will fail and // the output, the exit code. If the command returns a Nil error, it will fail and
// stop the tests. // stop the tests.
@ -23,14 +35,14 @@ func dockerCmdWithFail(c *testing.T, args ...string) (string, int) {
return out, status return out, status
} }
func (s *DockerSuite) TestNetHostnameWithNetHost(c *testing.T) { func (s *DockerCLINetmodeSuite) TestNetHostnameWithNetHost(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ps") out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ps")
assert.Assert(c, strings.Contains(out, stringCheckPS)) assert.Assert(c, strings.Contains(out, stringCheckPS))
} }
func (s *DockerSuite) TestNetHostname(c *testing.T) { func (s *DockerCLINetmodeSuite) TestNetHostname(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-h=name", "busybox", "ps") out, _ := dockerCmd(c, "run", "-h=name", "busybox", "ps")
@ -47,28 +59,28 @@ func (s *DockerSuite) TestNetHostname(c *testing.T) {
assert.Assert(c, strings.Contains(strings.ToLower(out), "not found")) assert.Assert(c, strings.Contains(strings.ToLower(out), "not found"))
} }
func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *testing.T) { func (s *DockerCLINetmodeSuite) TestConflictContainerNetworkAndLinks(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps") out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps")
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndLinks.Error())) assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndLinks.Error()))
} }
func (s *DockerSuite) TestConflictContainerNetworkHostAndLinks(c *testing.T) { func (s *DockerCLINetmodeSuite) TestConflictContainerNetworkHostAndLinks(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--link=zip:zap", "busybox", "ps") out, _ := dockerCmdWithFail(c, "run", "--net=host", "--link=zip:zap", "busybox", "ps")
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error())) assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error()))
} }
func (s *DockerSuite) TestConflictNetworkModeNetHostAndOptions(c *testing.T) { func (s *DockerCLINetmodeSuite) TestConflictNetworkModeNetHostAndOptions(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps") out, _ := dockerCmdWithFail(c, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps")
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error())) assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error()))
} }
func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *testing.T) { func (s *DockerCLINetmodeSuite) TestConflictNetworkModeAndOptions(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps") out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps")

View file

@ -2,10 +2,23 @@ package main
import ( import (
"net/http/httptest" "net/http/httptest"
"testing"
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
) )
type DockerCLINetworkSuite struct {
ds *DockerSuite
}
func (s *DockerCLINetworkSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLINetworkSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
type DockerNetworkSuite struct { type DockerNetworkSuite struct {
server *httptest.Server server *httptest.Server
ds *DockerSuite ds *DockerSuite

View file

@ -383,12 +383,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkCreateLabel(c *testing.T) {
assertNwNotAvailable(c, testNet) assertNwNotAvailable(c, testNet)
} }
func (s *DockerSuite) TestDockerNetworkDeleteNotExists(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkDeleteNotExists(c *testing.T) {
out, _, err := dockerCmdWithError("network", "rm", "test") out, _, err := dockerCmdWithError("network", "rm", "test")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestDockerNetworkDeleteMultiple(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkDeleteMultiple(c *testing.T) {
dockerCmd(c, "network", "create", "testDelMulti0") dockerCmd(c, "network", "create", "testDelMulti0")
assertNwIsAvailable(c, "testDelMulti0") assertNwIsAvailable(c, "testDelMulti0")
dockerCmd(c, "network", "create", "testDelMulti1") dockerCmd(c, "network", "create", "testDelMulti1")
@ -412,7 +412,7 @@ func (s *DockerSuite) TestDockerNetworkDeleteMultiple(c *testing.T) {
assertNwIsAvailable(c, "testDelMulti2") assertNwIsAvailable(c, "testDelMulti2")
} }
func (s *DockerSuite) TestDockerNetworkInspect(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkInspect(c *testing.T) {
out, _ := dockerCmd(c, "network", "inspect", "host") out, _ := dockerCmd(c, "network", "inspect", "host")
var networkResources []types.NetworkResource var networkResources []types.NetworkResource
err := json.Unmarshal([]byte(out), &networkResources) err := json.Unmarshal([]byte(out), &networkResources)
@ -423,7 +423,7 @@ func (s *DockerSuite) TestDockerNetworkInspect(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "host") assert.Equal(c, strings.TrimSpace(out), "host")
} }
func (s *DockerSuite) TestDockerNetworkInspectWithID(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkInspectWithID(c *testing.T) {
out, _ := dockerCmd(c, "network", "create", "test2") out, _ := dockerCmd(c, "network", "create", "test2")
networkID := strings.TrimSpace(out) networkID := strings.TrimSpace(out)
assertNwIsAvailable(c, "test2") assertNwIsAvailable(c, "test2")
@ -434,7 +434,7 @@ func (s *DockerSuite) TestDockerNetworkInspectWithID(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), networkID) assert.Equal(c, strings.TrimSpace(out), networkID)
} }
func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerInspectMultipleNetwork(c *testing.T) {
result := dockerCmdWithResult("network", "inspect", "host", "none") result := dockerCmdWithResult("network", "inspect", "host", "none")
result.Assert(c, icmd.Success) result.Assert(c, icmd.Success)
@ -444,7 +444,7 @@ func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *testing.T) {
assert.Equal(c, len(networkResources), 2) assert.Equal(c, len(networkResources), 2)
} }
func (s *DockerSuite) TestDockerInspectMultipleNetworksIncludingNonexistent(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerInspectMultipleNetworksIncludingNonexistent(c *testing.T) {
// non-existent network was not at the beginning of the inspect list // non-existent network was not at the beginning of the inspect list
// This should print an error, return an exitCode 1 and print the host network // This should print an error, return an exitCode 1 and print the host network
result := dockerCmdWithResult("network", "inspect", "host", "nonexistent") result := dockerCmdWithResult("network", "inspect", "host", "nonexistent")
@ -483,7 +483,7 @@ func (s *DockerSuite) TestDockerInspectMultipleNetworksIncludingNonexistent(c *t
assert.Equal(c, len(networkResources), 1) assert.Equal(c, len(networkResources), 1)
} }
func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerInspectNetworkWithContainerName(c *testing.T) {
dockerCmd(c, "network", "create", "brNetForInspect") dockerCmd(c, "network", "create", "brNetForInspect")
assertNwIsAvailable(c, "brNetForInspect") assertNwIsAvailable(c, "brNetForInspect")
defer func() { defer func() {
@ -999,7 +999,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacInspect(c *testing.T) {
assert.Equal(c, mac, "a0:b1:c2:d3:e4:f5") assert.Equal(c, mac, "a0:b1:c2:d3:e4:f5")
} }
func (s *DockerSuite) TestInspectAPIMultipleNetworks(c *testing.T) { func (s *DockerCLINetworkSuite) TestInspectAPIMultipleNetworks(c *testing.T) {
dockerCmd(c, "network", "create", "mybridge1") dockerCmd(c, "network", "create", "mybridge1")
dockerCmd(c, "network", "create", "mybridge2") dockerCmd(c, "network", "create", "mybridge2")
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
@ -1418,7 +1418,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectLinkLocalIP(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectLink(c *testing.T) { func (s *DockerCLINetworkSuite) TestUserDefinedNetworkConnectDisconnectLink(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm)
dockerCmd(c, "network", "create", "-d", "bridge", "foo1") dockerCmd(c, "network", "create", "-d", "bridge", "foo1")
dockerCmd(c, "network", "create", "-d", "bridge", "foo2") dockerCmd(c, "network", "create", "-d", "bridge", "foo2")
@ -1492,7 +1492,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithAliasOnDefaultNetworks(
} }
} }
func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *testing.T) { func (s *DockerCLINetworkSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm)
dockerCmd(c, "network", "create", "-d", "bridge", "net1") dockerCmd(c, "network", "create", "-d", "bridge", "net1")
dockerCmd(c, "network", "create", "-d", "bridge", "net2") dockerCmd(c, "network", "create", "-d", "bridge", "net2")
@ -1546,7 +1546,7 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *testing.T)
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndAlias.Error())) assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndAlias.Error()))
} }
func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *testing.T) { func (s *DockerCLINetworkSuite) TestUserDefinedNetworkConnectivity(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "network", "create", "-d", "bridge", "br.net1") dockerCmd(c, "network", "create", "-d", "bridge", "br.net1")
@ -1569,7 +1569,7 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *testing.T) {
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
} }
func (s *DockerSuite) TestEmbeddedDNSInvalidInput(c *testing.T) { func (s *DockerCLINetworkSuite) TestEmbeddedDNSInvalidInput(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "network", "create", "-d", "bridge", "nw1") dockerCmd(c, "network", "create", "-d", "bridge", "nw1")
@ -1577,7 +1577,7 @@ func (s *DockerSuite) TestEmbeddedDNSInvalidInput(c *testing.T) {
dockerCmd(c, "run", "-i", "--net=nw1", "--name=c1", "debian:bullseye-slim", "bash", "-c", "echo InvalidQuery > /dev/udp/127.0.0.11/53") dockerCmd(c, "run", "-i", "--net=nw1", "--name=c1", "debian:bullseye-slim", "bash", "-c", "echo InvalidQuery > /dev/udp/127.0.0.11/53")
} }
func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkConnectFailsNoInspectChange(c *testing.T) {
dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top") dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top")
assert.Assert(c, waitRun("bb") == nil) assert.Assert(c, waitRun("bb") == nil)
defer dockerCmd(c, "stop", "bb") defer dockerCmd(c, "stop", "bb")
@ -1592,7 +1592,7 @@ func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *testing.T)
assert.Equal(c, ns1, ns0) assert.Equal(c, ns1, ns0)
} }
func (s *DockerSuite) TestDockerNetworkInternalMode(c *testing.T) { func (s *DockerCLINetworkSuite) TestDockerNetworkInternalMode(c *testing.T) {
dockerCmd(c, "network", "create", "--driver=bridge", "--internal", "internal") dockerCmd(c, "network", "create", "--driver=bridge", "--internal", "internal")
assertNwIsAvailable(c, "internal") assertNwIsAvailable(c, "internal")
nr := getNetworkResource(c, "internal") nr := getNetworkResource(c, "internal")

View file

@ -9,7 +9,19 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestPluginLogDriver(c *testing.T) { type DockerCLIPluginLogDriverSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPluginLogDriverSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPluginLogDriverSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIPluginLogDriverSuite) TestPluginLogDriver(c *testing.T) {
testRequires(c, IsAmd64, DaemonIsLinux) testRequires(c, IsAmd64, DaemonIsLinux)
pluginName := "cpuguy83/docker-logdriver-test:latest" pluginName := "cpuguy83/docker-logdriver-test:latest"
@ -29,7 +41,7 @@ func (s *DockerSuite) TestPluginLogDriver(c *testing.T) {
} }
// Make sure log drivers are listed in info, and v2 plugins are not. // Make sure log drivers are listed in info, and v2 plugins are not.
func (s *DockerSuite) TestPluginLogDriverInfoList(c *testing.T) { func (s *DockerCLIPluginLogDriverSuite) TestPluginLogDriverInfoList(c *testing.T) {
testRequires(c, IsAmd64, DaemonIsLinux) testRequires(c, IsAmd64, DaemonIsLinux)
pluginName := "cpuguy83/docker-logdriver-test" pluginName := "cpuguy83/docker-logdriver-test"

View file

@ -28,6 +28,18 @@ var (
npNameWithTag = npName + ":" + pTag npNameWithTag = npName + ":" + pTag
) )
type DockerCLIPluginsSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPluginsSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPluginsSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) { func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) {
plugin := ps.getPluginRepoWithTag() plugin := ps.getPluginRepoWithTag()
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin) _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
@ -69,7 +81,7 @@ func (ps *DockerPluginSuite) TestPluginForceRemove(c *testing.T) {
assert.Assert(c, strings.Contains(out, pNameWithTag)) assert.Assert(c, strings.Contains(out, pNameWithTag))
} }
func (s *DockerSuite) TestPluginActive(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginActive(c *testing.T) {
testRequires(c, DaemonIsLinux, IsAmd64, Network) testRequires(c, DaemonIsLinux, IsAmd64, Network)
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
@ -91,7 +103,7 @@ func (s *DockerSuite) TestPluginActive(c *testing.T) {
assert.Assert(c, strings.Contains(out, pNameWithTag)) assert.Assert(c, strings.Contains(out, pNameWithTag))
} }
func (s *DockerSuite) TestPluginActiveNetwork(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginActiveNetwork(c *testing.T) {
testRequires(c, DaemonIsLinux, IsAmd64, Network) testRequires(c, DaemonIsLinux, IsAmd64, Network)
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag) _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
assert.NilError(c, err) assert.NilError(c, err)
@ -136,7 +148,7 @@ func (ps *DockerPluginSuite) TestPluginInstallDisable(c *testing.T) {
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName)) assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
} }
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginInstallDisableVolumeLs(c *testing.T) {
testRequires(c, DaemonIsLinux, IsAmd64, Network) testRequires(c, DaemonIsLinux, IsAmd64, Network)
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
assert.NilError(c, err) assert.NilError(c, err)
@ -316,7 +328,7 @@ func (ps *DockerPluginSuite) TestPluginInspect(c *testing.T) {
} }
// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345 // Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
func (s *DockerSuite) TestPluginInspectOnWindows(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginInspectOnWindows(c *testing.T) {
// This test should work on Windows only // This test should work on Windows only
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
@ -411,7 +423,7 @@ enabled: false`, id, name)
assert.Assert(c, strings.Contains(strings.TrimSpace(out), expectedOutput)) assert.Assert(c, strings.Contains(strings.TrimSpace(out), expectedOutput))
} }
func (s *DockerSuite) TestPluginUpgrade(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginUpgrade(c *testing.T) {
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64, NotUserNamespace) testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64, NotUserNamespace)
plugin := "cpuguy83/docker-volume-driver-plugin-local:latest" plugin := "cpuguy83/docker-volume-driver-plugin-local:latest"
pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2" pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2"
@ -442,7 +454,7 @@ func (s *DockerSuite) TestPluginUpgrade(c *testing.T) {
dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core") dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
} }
func (s *DockerSuite) TestPluginMetricsCollector(c *testing.T) { func (s *DockerCLIPluginsSuite) TestPluginMetricsCollector(c *testing.T) {
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64) testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64)
d := daemon.New(c, dockerBinary, dockerdBinary) d := daemon.New(c, dockerBinary, dockerdBinary)
d.Start(c) d.Start(c)

View file

@ -12,7 +12,19 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestPortList(c *testing.T) { type DockerCLIPortSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPortSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPortSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIPortSuite) TestPortList(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// one port // one port
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "top")
@ -241,7 +253,7 @@ func stopRemoveContainer(id string, c *testing.T) {
dockerCmd(c, "rm", "-f", id) dockerCmd(c, "rm", "-f", id)
} }
func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *testing.T) { func (s *DockerCLIPortSuite) TestUnpublishedPortsInPsOutput(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Run busybox with command line expose (equivalent to EXPOSE in image's Dockerfile) for the following ports // Run busybox with command line expose (equivalent to EXPOSE in image's Dockerfile) for the following ports
port1 := 80 port1 := 80
@ -312,7 +324,7 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *testing.T) {
assert.Assert(c, strings.Contains(out, expBnd2)) assert.Assert(c, strings.Contains(out, expBnd2))
} }
func (s *DockerSuite) TestPortHostBinding(c *testing.T) { func (s *DockerCLIPortSuite) TestPortHostBinding(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "nc", "-l", "-p", "80") out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "nc", "-l", "-p", "80")
firstID := strings.TrimSpace(out) firstID := strings.TrimSpace(out)
@ -332,7 +344,7 @@ func (s *DockerSuite) TestPortHostBinding(c *testing.T) {
assert.Assert(c, err != nil, "out: %s", out) assert.Assert(c, err != nil, "out: %s", out)
} }
func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) { func (s *DockerCLIPortSuite) TestPortExposeHostBinding(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox", "nc", "-l", "-p", "80") out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox", "nc", "-l", "-p", "80")
firstID := strings.TrimSpace(out) firstID := strings.TrimSpace(out)
@ -349,7 +361,7 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) {
assert.Assert(c, err != nil, "out: %s", out) assert.Assert(c, err != nil, "out: %s", out)
} }
func (s *DockerSuite) TestPortBindingOnSandbox(c *testing.T) { func (s *DockerCLIPortSuite) TestPortBindingOnSandbox(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net") dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net")
nr := getNetworkResource(c, "internal-net") nr := getNetworkResource(c, "internal-net")

View file

@ -9,7 +9,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) { type DockerCLIProxySuite struct {
ds *DockerSuite
}
func (s *DockerCLIProxySuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIProxySuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIProxySuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
icmd.RunCmd(icmd.Cmd{ icmd.RunCmd(icmd.Cmd{

View file

@ -0,0 +1,5 @@
package main
type DockerCLIPruneSuite struct {
ds *DockerSuite
}

View file

@ -20,6 +20,14 @@ import (
"gotest.tools/v3/poll" "gotest.tools/v3/poll"
) )
func (s *DockerCLIPruneSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPruneSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) { func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) {
_, err := d.Cmd("network", "prune", "--force") _, err := d.Cmd("network", "prune", "--force")
assert.NilError(c, err) assert.NilError(c, err)
@ -109,7 +117,7 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *testing.T) {
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id)) assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id))
} }
func (s *DockerSuite) TestPruneContainerUntil(c *testing.T) { func (s *DockerCLIPruneSuite) TestPruneContainerUntil(c *testing.T) {
out := cli.DockerCmd(c, "run", "-d", "busybox").Combined() out := cli.DockerCmd(c, "run", "-d", "busybox").Combined()
id1 := strings.TrimSpace(out) id1 := strings.TrimSpace(out)
cli.WaitExited(c, id1, 5*time.Second) cli.WaitExited(c, id1, 5*time.Second)
@ -128,7 +136,7 @@ func (s *DockerSuite) TestPruneContainerUntil(c *testing.T) {
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2)) assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
} }
func (s *DockerSuite) TestPruneContainerLabel(c *testing.T) { func (s *DockerCLIPruneSuite) TestPruneContainerLabel(c *testing.T) {
out := cli.DockerCmd(c, "run", "-d", "--label", "foo", "busybox").Combined() out := cli.DockerCmd(c, "run", "-d", "--label", "foo", "busybox").Combined()
id1 := strings.TrimSpace(out) id1 := strings.TrimSpace(out)
cli.WaitExited(c, id1, 5*time.Second) cli.WaitExited(c, id1, 5*time.Second)
@ -180,7 +188,7 @@ func (s *DockerSuite) TestPruneContainerLabel(c *testing.T) {
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2)) assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
} }
func (s *DockerSuite) TestPruneVolumeLabel(c *testing.T) { func (s *DockerCLIPruneSuite) TestPruneVolumeLabel(c *testing.T) {
out, _ := dockerCmd(c, "volume", "create", "--label", "foo") out, _ := dockerCmd(c, "volume", "create", "--label", "foo")
id1 := strings.TrimSpace(out) id1 := strings.TrimSpace(out)
assert.Assert(c, id1 != "") assert.Assert(c, id1 != "")
@ -232,7 +240,7 @@ func (s *DockerSuite) TestPruneVolumeLabel(c *testing.T) {
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2)) assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
} }
func (s *DockerSuite) TestPruneNetworkLabel(c *testing.T) { func (s *DockerCLIPruneSuite) TestPruneNetworkLabel(c *testing.T) {
dockerCmd(c, "network", "create", "--label", "foo", "n1") dockerCmd(c, "network", "create", "--label", "foo", "n1")
dockerCmd(c, "network", "create", "--label", "bar", "n2") dockerCmd(c, "network", "create", "--label", "bar", "n2")
dockerCmd(c, "network", "create", "n3") dockerCmd(c, "network", "create", "n3")

View file

@ -18,7 +18,19 @@ import (
"gotest.tools/v3/skip" "gotest.tools/v3/skip"
) )
func (s *DockerSuite) TestPsListContainersBase(c *testing.T) { type DockerCLIPsSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPsSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPsSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIPsSuite) TestPsListContainersBase(c *testing.T) {
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
@ -139,7 +151,7 @@ func assertContainerList(out string, expected []string) bool {
return true return true
} }
func (s *DockerSuite) TestPsListContainersSize(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersSize(c *testing.T) {
// Problematic on Windows as it doesn't report the size correctly @swernli // Problematic on Windows as it doesn't report the size correctly @swernli
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "busybox") dockerCmd(c, "run", "-d", "busybox")
@ -179,7 +191,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *testing.T) {
assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize) assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize)
} }
func (s *DockerSuite) TestPsListContainersFilterStatus(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterStatus(c *testing.T) {
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
// start exited container // start exited container
@ -226,7 +238,7 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *testing.T) {
} }
} }
func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterHealth(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME. Hang on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME. Hang on Windows + containerd combination")
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
// Test legacy no health check // Test legacy no health check
@ -270,7 +282,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out)) assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
} }
func (s *DockerSuite) TestPsListContainersFilterID(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterID(c *testing.T) {
// start container // start container
out, _ := dockerCmd(c, "run", "-d", "busybox") out, _ := dockerCmd(c, "run", "-d", "busybox")
firstID := strings.TrimSpace(out) firstID := strings.TrimSpace(out)
@ -284,7 +296,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *testing.T) {
assert.Equal(c, containerOut, firstID[:12], fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)) assert.Equal(c, containerOut, firstID[:12], fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
} }
func (s *DockerSuite) TestPsListContainersFilterName(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterName(c *testing.T) {
// start container // start container
dockerCmd(c, "run", "--name=a_name_to_match", "busybox") dockerCmd(c, "run", "--name=a_name_to_match", "busybox")
id := getIDByName(c, "a_name_to_match") id := getIDByName(c, "a_name_to_match")
@ -306,7 +318,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *testing.T) {
// - Create an image based on the previous image (images_ps_filter_test2) // - Create an image based on the previous image (images_ps_filter_test2)
// - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2) // - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2)
// - Filter them out :P // - Filter them out :P
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterAncestorImage(c *testing.T) {
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
// Build images // Build images
@ -401,7 +413,7 @@ func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, ex
} }
} }
func (s *DockerSuite) TestPsListContainersFilterLabel(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterLabel(c *testing.T) {
// start container // start container
dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox") dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox")
firstID := getIDByName(c, "first") firstID := getIDByName(c, "first")
@ -437,7 +449,7 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *testing.T) {
assert.Assert(c, !strings.Contains(containerOut, thirdID)) assert.Assert(c, !strings.Contains(containerOut, thirdID))
} }
func (s *DockerSuite) TestPsListContainersFilterExited(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterExited(c *testing.T) {
// TODO Flaky on Windows CI [both RS1 and RS5] // TODO Flaky on Windows CI [both RS1 and RS5]
// On slower machines the container may not have exited // On slower machines the container may not have exited
// yet when we filter below by exit status/exit value. // yet when we filter below by exit status/exit value.
@ -468,7 +480,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *testing.T) {
assert.Assert(c, !strings.Contains(out, strings.TrimSpace(secondZero))) assert.Assert(c, !strings.Contains(out, strings.TrimSpace(secondZero)))
} }
func (s *DockerSuite) TestPsRightTagName(c *testing.T) { func (s *DockerCLIPsSuite) TestPsRightTagName(c *testing.T) {
// TODO Investigate further why this fails on Windows to Windows CI // TODO Investigate further why this fails on Windows to Windows CI
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -514,7 +526,7 @@ func (s *DockerSuite) TestPsRightTagName(c *testing.T) {
} }
} }
func (s *DockerSuite) TestPsListContainersFilterCreated(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterCreated(c *testing.T) {
// create a container // create a container
out, _ := dockerCmd(c, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
@ -544,7 +556,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *testing.T) {
} }
// Test for GitHub issue #12595 // Test for GitHub issue #12595
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *testing.T) { func (s *DockerCLIPsSuite) TestPsImageIDAfterUpdate(c *testing.T) {
// TODO: Investigate why this fails on Windows to Windows CI further. // TODO: Investigate why this fails on Windows to Windows CI further.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
originalImageName := "busybox:TestPsImageIDAfterUpdate-original" originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
@ -593,7 +605,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *testing.T) {
} }
func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *testing.T) { func (s *DockerCLIPsSuite) TestPsNotShowPortsOfStoppedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name=foo", "-d", "-p", "6000:5000", "busybox", "top") dockerCmd(c, "run", "--name=foo", "-d", "-p", "6000:5000", "busybox", "top")
assert.Assert(c, waitRun("foo") == nil) assert.Assert(c, waitRun("foo") == nil)
@ -607,7 +619,7 @@ func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *testing.T) {
assert.Equal(c, ports, "", "Should not got %v", expected) assert.Equal(c, ports, "", "Should not got %v", expected)
} }
func (s *DockerSuite) TestPsShowMounts(c *testing.T) { func (s *DockerCLIPsSuite) TestPsShowMounts(c *testing.T) {
existingContainers := ExistingContainerNames(c) existingContainers := ExistingContainerNames(c)
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
@ -707,7 +719,7 @@ func (s *DockerSuite) TestPsShowMounts(c *testing.T) {
assert.Equal(c, len(strings.TrimSpace(out)), 0) assert.Equal(c, len(strings.TrimSpace(out)), 0)
} }
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterNetwork(c *testing.T) {
existing := ExistingContainerIDs(c) existing := ExistingContainerIDs(c)
// TODO default network on Windows is not called "bridge", and creating a // TODO default network on Windows is not called "bridge", and creating a
@ -784,7 +796,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *testing.T) {
assert.Assert(c, strings.Contains(containerOut, "onbridgenetwork"), "Missing the container on network\n") assert.Assert(c, strings.Contains(containerOut, "onbridgenetwork"), "Missing the container on network\n")
} }
func (s *DockerSuite) TestPsByOrder(c *testing.T) { func (s *DockerCLIPsSuite) TestPsByOrder(c *testing.T) {
out := runSleepingContainer(c, "--name", "xyz-abc") out := runSleepingContainer(c, "--name", "xyz-abc")
container1 := strings.TrimSpace(out) container1 := strings.TrimSpace(out)
@ -803,7 +815,7 @@ func (s *DockerSuite) TestPsByOrder(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), fmt.Sprintf("%s\n%s", container2, container1)) assert.Equal(c, strings.TrimSpace(out), fmt.Sprintf("%s\n%s", container2, container1))
} }
func (s *DockerSuite) TestPsListContainersFilterPorts(c *testing.T) { func (s *DockerCLIPsSuite) TestPsListContainersFilterPorts(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
existingContainers := ExistingContainerIDs(c) existingContainers := ExistingContainerIDs(c)
@ -853,7 +865,7 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != id3) assert.Assert(c, strings.TrimSpace(out) != id3)
} }
func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *testing.T) { func (s *DockerCLIPsSuite) TestPsNotShowLinknamesOfDeletedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31")) testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31"))
existingContainers := ExistingContainerNames(c) existingContainers := ExistingContainerNames(c)

View file

@ -13,6 +13,18 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
type DockerCLIPullSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPullSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPullSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client // TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client
// prints all expected output. // prints all expected output.
func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *testing.T) { func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *testing.T) {
@ -263,14 +275,14 @@ func (s *DockerHubPullSuite) TestPullClientDisconnect(c *testing.T) {
} }
// Regression test for https://github.com/docker/docker/issues/26429 // Regression test for https://github.com/docker/docker/issues/26429
func (s *DockerSuite) TestPullLinuxImageFailsOnWindows(c *testing.T) { func (s *DockerCLIPullSuite) TestPullLinuxImageFailsOnWindows(c *testing.T) {
testRequires(c, DaemonIsWindows, Network) testRequires(c, DaemonIsWindows, Network)
_, _, err := dockerCmdWithError("pull", "ubuntu") _, _, err := dockerCmdWithError("pull", "ubuntu")
assert.ErrorContains(c, err, "no matching manifest for windows") assert.ErrorContains(c, err, "no matching manifest for windows")
} }
// Regression test for https://github.com/docker/docker/issues/28892 // Regression test for https://github.com/docker/docker/issues/28892
func (s *DockerSuite) TestPullWindowsImageFailsOnLinux(c *testing.T) { func (s *DockerCLIPullSuite) TestPullWindowsImageFailsOnLinux(c *testing.T) {
testRequires(c, DaemonIsLinux, Network) testRequires(c, DaemonIsLinux, Network)
_, _, err := dockerCmdWithError("pull", "mcr.microsoft.com/windows/servercore:ltsc2019") _, _, err := dockerCmdWithError("pull", "mcr.microsoft.com/windows/servercore:ltsc2019")
assert.ErrorContains(c, err, "no matching manifest for linux") assert.ErrorContains(c, err, "no matching manifest for linux")

View file

@ -17,6 +17,18 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
type DockerCLIPushSuite struct {
ds *DockerSuite
}
func (s *DockerCLIPushSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIPushSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) { func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image to upload it to the private registry // tag the image to upload it to the private registry
@ -26,7 +38,7 @@ func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) {
} }
// pushing an image without a prefix should throw an error // pushing an image without a prefix should throw an error
func (s *DockerSuite) TestPushUnprefixedRepo(c *testing.T) { func (s *DockerCLIPushSuite) TestPushUnprefixedRepo(c *testing.T) {
out, _, err := dockerCmdWithError("push", "busybox") out, _, err := dockerCmdWithError("push", "busybox")
assert.ErrorContains(c, err, "", "pushing an unprefixed repo didn't result in a non-zero exit status: %s", out) assert.ErrorContains(c, err, "", "pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
} }
@ -208,7 +220,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *testin
} }
// This may be flaky but it's needed not to regress on unauthorized push, see #21054 // This may be flaky but it's needed not to regress on unauthorized push, see #21054
func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *testing.T) { func (s *DockerCLIPushSuite) TestPushToCentralRegistryUnauthorized(c *testing.T) {
testRequires(c, Network) testRequires(c, Network)
repoName := "test/busybox" repoName := "test/busybox"
dockerCmd(c, "tag", "busybox", repoName) dockerCmd(c, "tag", "busybox", repoName)

View file

@ -14,7 +14,19 @@ import (
"gotest.tools/v3/skip" "gotest.tools/v3/skip"
) )
func (s *DockerSuite) TestRestartStoppedContainer(c *testing.T) { type DockerCLIRestartSuite struct {
ds *DockerSuite
}
func (s *DockerCLIRestartSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIRestartSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIRestartSuite) TestRestartStoppedContainer(c *testing.T) {
dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar") dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar")
cleanedContainerID := getIDByName(c, "test") cleanedContainerID := getIDByName(c, "test")
@ -31,7 +43,7 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *testing.T) {
assert.Equal(c, out, "foobar\nfoobar\n") assert.Equal(c, out, "foobar\nfoobar\n")
} }
func (s *DockerSuite) TestRestartRunningContainer(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartRunningContainer(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'") out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -54,7 +66,7 @@ func (s *DockerSuite) TestRestartRunningContainer(c *testing.T) {
} }
// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819. // Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819.
func (s *DockerSuite) TestRestartWithVolumes(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartWithVolumes(c *testing.T) {
prefix, slash := getPrefixAndSlashFromDaemonPlatform() prefix, slash := getPrefixAndSlashFromDaemonPlatform()
out := runSleepingContainer(c, "-d", "-v", prefix+slash+"test") out := runSleepingContainer(c, "-d", "-v", prefix+slash+"test")
@ -79,7 +91,7 @@ func (s *DockerSuite) TestRestartWithVolumes(c *testing.T) {
assert.Equal(c, source, sourceAfterRestart) assert.Equal(c, source, sourceAfterRestart)
} }
func (s *DockerSuite) TestRestartDisconnectedContainer(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartDisconnectedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm)
// Run a container on the default bridge network // Run a container on the default bridge network
@ -96,7 +108,7 @@ func (s *DockerSuite) TestRestartDisconnectedContainer(c *testing.T) {
assert.Assert(c, exitCode == 0, out) assert.Assert(c, exitCode == 0, out)
} }
func (s *DockerSuite) TestRestartPolicyNO(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartPolicyNO(c *testing.T) {
out, _ := dockerCmd(c, "create", "--restart=no", "busybox") out, _ := dockerCmd(c, "create", "--restart=no", "busybox")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -104,7 +116,7 @@ func (s *DockerSuite) TestRestartPolicyNO(c *testing.T) {
assert.Equal(c, name, "no") assert.Equal(c, name, "no")
} }
func (s *DockerSuite) TestRestartPolicyAlways(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartPolicyAlways(c *testing.T) {
out, _ := dockerCmd(c, "create", "--restart=always", "busybox") out, _ := dockerCmd(c, "create", "--restart=always", "busybox")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -117,7 +129,7 @@ func (s *DockerSuite) TestRestartPolicyAlways(c *testing.T) {
assert.Equal(c, MaximumRetryCount, "0") assert.Equal(c, MaximumRetryCount, "0")
} }
func (s *DockerSuite) TestRestartPolicyOnFailure(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartPolicyOnFailure(c *testing.T) {
out, _, err := dockerCmdWithError("create", "--restart=on-failure:-1", "busybox") out, _, err := dockerCmdWithError("create", "--restart=on-failure:-1", "busybox")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
assert.Assert(c, strings.Contains(out, "maximum retry count cannot be negative")) assert.Assert(c, strings.Contains(out, "maximum retry count cannot be negative"))
@ -152,7 +164,7 @@ func (s *DockerSuite) TestRestartPolicyOnFailure(c *testing.T) {
// a good container with --restart=on-failure:3 // a good container with --restart=on-failure:3
// MaximumRetryCount!=0; RestartCount=0 // MaximumRetryCount!=0; RestartCount=0
func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartContainerwithGoodContainer(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -166,7 +178,7 @@ func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *testing.T) {
assert.Equal(c, MaximumRetryCount, "3") assert.Equal(c, MaximumRetryCount, "3")
} }
func (s *DockerSuite) TestRestartContainerSuccess(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartContainerSuccess(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
// Skipped for Hyper-V isolated containers. Test is currently written // Skipped for Hyper-V isolated containers. Test is currently written
// such that it assumes there is a host process to kill. In Hyper-V // such that it assumes there is a host process to kill. In Hyper-V
@ -199,7 +211,7 @@ func (s *DockerSuite) TestRestartContainerSuccess(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartWithPolicyUserDefinedNetwork(c *testing.T) {
// TODO Windows. This may be portable following HNS integration post TP5. // TODO Windows. This may be portable following HNS integration post TP5.
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm)
dockerCmd(c, "network", "create", "-d", "bridge", "udNet") dockerCmd(c, "network", "create", "-d", "bridge", "udNet")
@ -243,7 +255,7 @@ func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestRestartPolicyAfterRestart(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartPolicyAfterRestart(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
// Skipped for Hyper-V isolated containers. Test is currently written // Skipped for Hyper-V isolated containers. Test is currently written
// such that it assumes there is a host process to kill. In Hyper-V // such that it assumes there is a host process to kill. In Hyper-V
@ -280,7 +292,7 @@ func (s *DockerSuite) TestRestartPolicyAfterRestart(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartContainerwithRestartPolicy(c *testing.T) {
out1, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false") out1, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false")
out2, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false") out2, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false")
@ -311,7 +323,7 @@ func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
} }
func (s *DockerSuite) TestRestartAutoRemoveContainer(c *testing.T) { func (s *DockerCLIRestartSuite) TestRestartAutoRemoveContainer(c *testing.T) {
out := runSleepingContainer(c, "--rm") out := runSleepingContainer(c, "--rm")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)

View file

@ -13,7 +13,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestRmiWithContainerFails(c *testing.T) { type DockerCLIRmiSuite struct {
ds *DockerSuite
}
func (s *DockerCLIRmiSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIRmiSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIRmiSuite) TestRmiWithContainerFails(c *testing.T) {
errSubstr := "is using it" errSubstr := "is using it"
// create a container // create a container
@ -33,7 +45,7 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *testing.T) {
assert.Assert(c, strings.Contains(images, "busybox")) assert.Assert(c, strings.Contains(images, "busybox"))
} }
func (s *DockerSuite) TestRmiTag(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiTag(c *testing.T) {
imagesBefore, _ := dockerCmd(c, "images", "-a") imagesBefore, _ := dockerCmd(c, "images", "-a")
dockerCmd(c, "tag", "busybox", "utest:tag1") dockerCmd(c, "tag", "busybox", "utest:tag1")
dockerCmd(c, "tag", "busybox", "utest/docker:tag2") dockerCmd(c, "tag", "busybox", "utest/docker:tag2")
@ -61,7 +73,7 @@ func (s *DockerSuite) TestRmiTag(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiImgIDMultipleTag(c *testing.T) {
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined() out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -102,7 +114,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *testing.T) {
assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]), "ImageID:%q; ImagesAfter: %q", imgID, imagesAfter) assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]), "ImageID:%q; ImagesAfter: %q", imgID, imagesAfter)
} }
func (s *DockerSuite) TestRmiImgIDForce(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiImgIDForce(c *testing.T) {
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined() out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -140,7 +152,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *testing.T) {
} }
// See https://github.com/docker/docker/issues/14116 // See https://github.com/docker/docker/issues/14116
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *testing.T) {
dockerfile := "FROM busybox\nRUN echo test 14116\n" dockerfile := "FROM busybox\nRUN echo test 14116\n"
buildImageSuccessfully(c, "test-14116", build.WithDockerfile(dockerfile)) buildImageSuccessfully(c, "test-14116", build.WithDockerfile(dockerfile))
imgID := getIDByName(c, "test-14116") imgID := getIDByName(c, "test-14116")
@ -155,7 +167,7 @@ func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c
assert.Assert(c, strings.Contains(out, "(cannot be forced) - image is being used by running container")) assert.Assert(c, strings.Contains(out, "(cannot be forced) - image is being used by running container"))
} }
func (s *DockerSuite) TestRmiTagWithExistingContainers(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiTagWithExistingContainers(c *testing.T) {
container := "test-delete-tag" container := "test-delete-tag"
newtag := "busybox:newtag" newtag := "busybox:newtag"
bb := "busybox:latest" bb := "busybox:latest"
@ -167,7 +179,7 @@ func (s *DockerSuite) TestRmiTagWithExistingContainers(c *testing.T) {
assert.Equal(c, strings.Count(out, "Untagged: "), 1) assert.Equal(c, strings.Count(out, "Untagged: "), 1)
} }
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiForceWithExistingContainers(c *testing.T) {
image := "busybox-clone" image := "busybox-clone"
icmd.RunCmd(icmd.Cmd{ icmd.RunCmd(icmd.Cmd{
@ -181,7 +193,7 @@ MAINTAINER foo`),
dockerCmd(c, "rmi", "-f", image) dockerCmd(c, "rmi", "-f", image)
} }
func (s *DockerSuite) TestRmiWithMultipleRepositories(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiWithMultipleRepositories(c *testing.T) {
newRepo := "127.0.0.1:5000/busybox" newRepo := "127.0.0.1:5000/busybox"
oldRepo := "busybox" oldRepo := "busybox"
newTag := "busybox:test" newTag := "busybox:test"
@ -195,7 +207,7 @@ func (s *DockerSuite) TestRmiWithMultipleRepositories(c *testing.T) {
assert.Assert(c, strings.Contains(out, "Untagged: "+newTag)) assert.Assert(c, strings.Contains(out, "Untagged: "+newTag))
} }
func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiForceWithMultipleRepositories(c *testing.T) {
imageName := "rmiimage" imageName := "rmiimage"
tag1 := imageName + ":tag1" tag1 := imageName + ":tag1"
tag2 := imageName + ":tag2" tag2 := imageName + ":tag2"
@ -212,7 +224,7 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *testing.T) {
assert.Assert(c, strings.Contains(images, imageName), "Built image missing %q; Images: %q", imageName, images) assert.Assert(c, strings.Contains(images, imageName), "Built image missing %q; Images: %q", imageName, images)
} }
func (s *DockerSuite) TestRmiBlank(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiBlank(c *testing.T) {
out, _, err := dockerCmdWithError("rmi", " ") out, _, err := dockerCmdWithError("rmi", " ")
// Should have failed to delete ' ' image // Should have failed to delete ' ' image
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
@ -222,7 +234,7 @@ func (s *DockerSuite) TestRmiBlank(c *testing.T) {
assert.Assert(c, strings.Contains(out, "image name cannot be blank"), "out: %s", out) assert.Assert(c, strings.Contains(out, "image name cannot be blank"), "out: %s", out)
} }
func (s *DockerSuite) TestRmiContainerImageNotFound(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiContainerImageNotFound(c *testing.T) {
// Build 2 images for testing. // Build 2 images for testing.
imageNames := []string{"test1", "test2"} imageNames := []string{"test1", "test2"}
imageIds := make([]string, 2) imageIds := make([]string, 2)
@ -248,7 +260,7 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *testing.T) {
} }
// #13422 // #13422
func (s *DockerSuite) TestRmiUntagHistoryLayer(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiUntagHistoryLayer(c *testing.T) {
image := "tmp1" image := "tmp1"
// Build an image for testing. // Build an image for testing.
dockerfile := `FROM busybox dockerfile := `FROM busybox
@ -291,7 +303,7 @@ RUN echo 2 #layer2
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Untagged: %s:latest", newTag))) assert.Assert(c, strings.Contains(out, fmt.Sprintf("Untagged: %s:latest", newTag)))
} }
func (*DockerSuite) TestRmiParentImageFail(c *testing.T) { func (*DockerCLIRmiSuite) TestRmiParentImageFail(c *testing.T) {
buildImageSuccessfully(c, "test", build.WithDockerfile(` buildImageSuccessfully(c, "test", build.WithDockerfile(`
FROM busybox FROM busybox
RUN echo hello`)) RUN echo hello`))
@ -304,7 +316,7 @@ func (*DockerSuite) TestRmiParentImageFail(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRmiWithParentInUse(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiWithParentInUse(c *testing.T) {
out, _ := dockerCmd(c, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
@ -321,7 +333,7 @@ func (s *DockerSuite) TestRmiWithParentInUse(c *testing.T) {
} }
// #18873 // #18873
func (s *DockerSuite) TestRmiByIDHardConflict(c *testing.T) { func (s *DockerCLIRmiSuite) TestRmiByIDHardConflict(c *testing.T) {
dockerCmd(c, "create", "busybox") dockerCmd(c, "create", "busybox")
imgID := inspectField(c, "busybox:latest", "Id") imgID := inspectField(c, "busybox:latest", "Id")

File diff suppressed because it is too large Load diff

View file

@ -31,7 +31,7 @@ import (
) )
// #6509 // #6509
func (s *DockerSuite) TestRunRedirectStdout(c *testing.T) { func (s *DockerCLIRunSuite) TestRunRedirectStdout(c *testing.T) {
checkRedirect := func(command string) { checkRedirect := func(command string) {
_, tty, err := pty.Open() _, tty, err := pty.Open()
assert.Assert(c, err == nil, "Could not open pty") assert.Assert(c, err == nil, "Could not open pty")
@ -59,7 +59,7 @@ func (s *DockerSuite) TestRunRedirectStdout(c *testing.T) {
} }
// Test recursive bind mount works by default // Test recursive bind mount works by default
func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithVolumesIsRecursive(c *testing.T) {
// /tmp gets permission denied // /tmp gets permission denied
testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon) testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon)
tmpDir, err := os.MkdirTemp("", "docker_recursive_mount_test") tmpDir, err := os.MkdirTemp("", "docker_recursive_mount_test")
@ -80,7 +80,7 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *testing.T) {
assert.Assert(c, strings.Contains(out, filepath.Base(f.Name())), "Recursive bind mount test failed. Expected file not found") assert.Assert(c, strings.Contains(out, filepath.Base(f.Name())), "Recursive bind mount test failed. Expected file not found")
} }
func (s *DockerSuite) TestRunDeviceDirectory(c *testing.T) { func (s *DockerCLIRunSuite) TestRunDeviceDirectory(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm)
if _, err := os.Stat("/dev/snd"); err != nil { if _, err := os.Stat("/dev/snd"); err != nil {
c.Skip("Host does not have /dev/snd") c.Skip("Host does not have /dev/snd")
@ -93,7 +93,7 @@ func (s *DockerSuite) TestRunDeviceDirectory(c *testing.T) {
} }
// TestRunAttachDetach checks attaching and detaching with the default escape sequence. // TestRunAttachDetach checks attaching and detaching with the default escape sequence.
func (s *DockerSuite) TestRunAttachDetach(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachDetach(c *testing.T) {
name := "attach-detach" name := "attach-detach"
dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat")
@ -144,7 +144,7 @@ func (s *DockerSuite) TestRunAttachDetach(c *testing.T) {
} }
// TestRunAttachDetachFromFlag checks attaching and detaching with the escape sequence specified via flags. // TestRunAttachDetachFromFlag checks attaching and detaching with the escape sequence specified via flags.
func (s *DockerSuite) TestRunAttachDetachFromFlag(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachDetachFromFlag(c *testing.T) {
name := "attach-detach" name := "attach-detach"
keyCtrlA := []byte{1} keyCtrlA := []byte{1}
keyA := []byte{97} keyA := []byte{97}
@ -205,7 +205,7 @@ func (s *DockerSuite) TestRunAttachDetachFromFlag(c *testing.T) {
} }
// TestRunAttachDetachFromInvalidFlag checks attaching and detaching with the escape sequence specified via flags. // TestRunAttachDetachFromInvalidFlag checks attaching and detaching with the escape sequence specified via flags.
func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachDetachFromInvalidFlag(c *testing.T) {
name := "attach-detach" name := "attach-detach"
dockerCmd(c, "run", "--name", name, "-itd", "busybox", "top") dockerCmd(c, "run", "--name", name, "-itd", "busybox", "top")
assert.Assert(c, waitRun(name) == nil) assert.Assert(c, waitRun(name) == nil)
@ -238,7 +238,7 @@ func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *testing.T) {
} }
// TestRunAttachDetachFromConfig checks attaching and detaching with the escape sequence specified via config file. // TestRunAttachDetachFromConfig checks attaching and detaching with the escape sequence specified via config file.
func (s *DockerSuite) TestRunAttachDetachFromConfig(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachDetachFromConfig(c *testing.T) {
keyCtrlA := []byte{1} keyCtrlA := []byte{1}
keyA := []byte{97} keyA := []byte{97}
@ -318,7 +318,7 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *testing.T) {
} }
// TestRunAttachDetachKeysOverrideConfig checks attaching and detaching with the detach flags, making sure it overrides config file // TestRunAttachDetachKeysOverrideConfig checks attaching and detaching with the detach flags, making sure it overrides config file
func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) {
keyCtrlA := []byte{1} keyCtrlA := []byte{1}
keyA := []byte{97} keyA := []byte{97}
@ -397,7 +397,7 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) {
assert.Equal(c, running, "true", "expected container to still be running") assert.Equal(c, running, "true", "expected container to still be running")
} }
func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *testing.T) { func (s *DockerCLIRunSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *testing.T) {
name := "attach-detach" name := "attach-detach"
keyA := []byte{97} keyA := []byte{97}
keyB := []byte{98} keyB := []byte{98}
@ -448,7 +448,7 @@ func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *testing.
} }
// "test" should be printed // "test" should be printed
func (s *DockerSuite) TestRunWithCPUQuota(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithCPUQuota(c *testing.T) {
testRequires(c, cpuCfsQuota) testRequires(c, cpuCfsQuota)
file := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" file := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
@ -459,7 +459,7 @@ func (s *DockerSuite) TestRunWithCPUQuota(c *testing.T) {
assert.Equal(c, out, "8000", "setting the CPU CFS quota failed") assert.Equal(c, out, "8000", "setting the CPU CFS quota failed")
} }
func (s *DockerSuite) TestRunWithCpuPeriod(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithCpuPeriod(c *testing.T) {
testRequires(c, cpuCfsPeriod) testRequires(c, cpuCfsPeriod)
file := "/sys/fs/cgroup/cpu/cpu.cfs_period_us" file := "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
@ -473,7 +473,7 @@ func (s *DockerSuite) TestRunWithCpuPeriod(c *testing.T) {
assert.Equal(c, out, "50000", "setting the CPU CFS period failed") assert.Equal(c, out, "50000", "setting the CPU CFS period failed")
} }
func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidCpuPeriod(c *testing.T) {
testRequires(c, cpuCfsPeriod) testRequires(c, cpuCfsPeriod)
out, _, err := dockerCmdWithError("run", "--cpu-period", "900", "busybox", "true") out, _, err := dockerCmdWithError("run", "--cpu-period", "900", "busybox", "true")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
@ -489,7 +489,7 @@ func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunWithCPUShares(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithCPUShares(c *testing.T) {
testRequires(c, cpuShare) testRequires(c, cpuShare)
file := "/sys/fs/cgroup/cpu/cpu.shares" file := "/sys/fs/cgroup/cpu/cpu.shares"
@ -501,7 +501,7 @@ func (s *DockerSuite) TestRunWithCPUShares(c *testing.T) {
} }
// "test" should be printed // "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *testing.T) {
testRequires(c, cpuShare) testRequires(c, cpuShare)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
cli.DockerCmd(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test").Assert(c, icmd.Expected{ cli.DockerCmd(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test").Assert(c, icmd.Expected{
@ -509,7 +509,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *testing.T)
}) })
} }
func (s *DockerSuite) TestRunWithCpusetCpus(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithCpusetCpus(c *testing.T) {
testRequires(c, cgroupCpuset) testRequires(c, cgroupCpuset)
file := "/sys/fs/cgroup/cpuset/cpuset.cpus" file := "/sys/fs/cgroup/cpuset/cpuset.cpus"
@ -520,7 +520,7 @@ func (s *DockerSuite) TestRunWithCpusetCpus(c *testing.T) {
assert.Equal(c, out, "0") assert.Equal(c, out, "0")
} }
func (s *DockerSuite) TestRunWithCpusetMems(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithCpusetMems(c *testing.T) {
testRequires(c, cgroupCpuset) testRequires(c, cgroupCpuset)
file := "/sys/fs/cgroup/cpuset/cpuset.mems" file := "/sys/fs/cgroup/cpuset/cpuset.mems"
@ -531,7 +531,7 @@ func (s *DockerSuite) TestRunWithCpusetMems(c *testing.T) {
assert.Equal(c, out, "0") assert.Equal(c, out, "0")
} }
func (s *DockerSuite) TestRunWithBlkioWeight(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithBlkioWeight(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
file := "/sys/fs/cgroup/blkio/blkio.weight" file := "/sys/fs/cgroup/blkio/blkio.weight"
@ -542,7 +542,7 @@ func (s *DockerSuite) TestRunWithBlkioWeight(c *testing.T) {
assert.Equal(c, out, "300") assert.Equal(c, out, "300")
} }
func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidBlkioWeight(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--blkio-weight", "5", "busybox", "true") out, _, err := dockerCmdWithError("run", "--blkio-weight", "5", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
@ -550,37 +550,37 @@ func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunWithInvalidPathforBlkioWeightDevice(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidPathforBlkioWeightDevice(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--blkio-weight-device", "/dev/sdX:100", "busybox", "true") out, _, err := dockerCmdWithError("run", "--blkio-weight-device", "/dev/sdX:100", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadBps(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidPathforBlkioDeviceReadBps(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--device-read-bps", "/dev/sdX:500", "busybox", "true") out, _, err := dockerCmdWithError("run", "--device-read-bps", "/dev/sdX:500", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteBps(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidPathforBlkioDeviceWriteBps(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--device-write-bps", "/dev/sdX:500", "busybox", "true") out, _, err := dockerCmdWithError("run", "--device-write-bps", "/dev/sdX:500", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadIOps(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidPathforBlkioDeviceReadIOps(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--device-read-iops", "/dev/sdX:500", "busybox", "true") out, _, err := dockerCmdWithError("run", "--device-read-iops", "/dev/sdX:500", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteIOps(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithInvalidPathforBlkioDeviceWriteIOps(c *testing.T) {
testRequires(c, blkioWeight) testRequires(c, blkioWeight)
out, _, err := dockerCmdWithError("run", "--device-write-iops", "/dev/sdX:500", "busybox", "true") out, _, err := dockerCmdWithError("run", "--device-write-iops", "/dev/sdX:500", "busybox", "true")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
} }
func (s *DockerSuite) TestRunOOMExitCode(c *testing.T) { func (s *DockerCLIRunSuite) TestRunOOMExitCode(c *testing.T) {
testRequires(c, memoryLimitSupport, swapMemorySupport, NotPpc64le) testRequires(c, memoryLimitSupport, swapMemorySupport, NotPpc64le)
errChan := make(chan error, 1) errChan := make(chan error, 1)
go func() { go func() {
@ -600,7 +600,7 @@ func (s *DockerSuite) TestRunOOMExitCode(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRunWithMemoryLimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithMemoryLimit(c *testing.T) {
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
@ -616,14 +616,14 @@ func (s *DockerSuite) TestRunWithMemoryLimit(c *testing.T) {
// memory limit, this means the processes in the container can use // memory limit, this means the processes in the container can use
// 16M memory and as much swap memory as they need (if the host // 16M memory and as much swap memory as they need (if the host
// supports swap memory). // supports swap memory).
func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithoutMemoryswapLimit(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport) testRequires(c, swapMemorySupport)
dockerCmd(c, "run", "-m", "32m", "--memory-swap", "-1", "busybox", "true") dockerCmd(c, "run", "-m", "32m", "--memory-swap", "-1", "busybox", "true")
} }
func (s *DockerSuite) TestRunWithSwappiness(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithSwappiness(c *testing.T) {
testRequires(c, memorySwappinessSupport) testRequires(c, memorySwappinessSupport)
file := "/sys/fs/cgroup/memory/memory.swappiness" file := "/sys/fs/cgroup/memory/memory.swappiness"
out, _ := dockerCmd(c, "run", "--memory-swappiness", "0", "--name", "test", "busybox", "cat", file) out, _ := dockerCmd(c, "run", "--memory-swappiness", "0", "--name", "test", "busybox", "cat", file)
@ -633,7 +633,7 @@ func (s *DockerSuite) TestRunWithSwappiness(c *testing.T) {
assert.Equal(c, out, "0") assert.Equal(c, out, "0")
} }
func (s *DockerSuite) TestRunWithSwappinessInvalid(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithSwappinessInvalid(c *testing.T) {
testRequires(c, memorySwappinessSupport) testRequires(c, memorySwappinessSupport)
out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true") out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
@ -644,7 +644,7 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected), "Expected output to contain %q, not %q", out, expected) assert.Assert(c, strings.Contains(out, expected), "Expected output to contain %q, not %q", out, expected)
} }
func (s *DockerSuite) TestRunWithMemoryReservation(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithMemoryReservation(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport) testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport)
file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes" file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"
@ -655,7 +655,7 @@ func (s *DockerSuite) TestRunWithMemoryReservation(c *testing.T) {
assert.Equal(c, out, "209715200") assert.Equal(c, out, "209715200")
} }
func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithMemoryReservationInvalid(c *testing.T) {
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport) testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport)
out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true") out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true")
@ -668,7 +668,7 @@ func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *testing.T) {
assert.Assert(c, strings.Contains(strings.TrimSpace(out), expected), "run container should fail with invalid memory reservation") assert.Assert(c, strings.Contains(strings.TrimSpace(out), expected), "run container should fail with invalid memory reservation")
} }
func (s *DockerSuite) TestStopContainerSignal(c *testing.T) { func (s *DockerCLIRunSuite) TestStopContainerSignal(c *testing.T) {
out, _ := dockerCmd(c, "run", "--stop-signal", "SIGUSR1", "-d", "busybox", "/bin/sh", "-c", `trap 'echo "exit trapped"; exit 0' USR1; while true; do sleep 1; done`) out, _ := dockerCmd(c, "run", "--stop-signal", "SIGUSR1", "-d", "busybox", "/bin/sh", "-c", `trap 'echo "exit trapped"; exit 0' USR1; while true; do sleep 1; done`)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -680,7 +680,7 @@ func (s *DockerSuite) TestStopContainerSignal(c *testing.T) {
assert.Assert(c, strings.Contains(out, "exit trapped"), "Expected `exit trapped` in the log") assert.Assert(c, strings.Contains(out, "exit trapped"), "Expected `exit trapped` in the log")
} }
func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSwapLessThanMemoryLimit(c *testing.T) {
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport) testRequires(c, swapMemorySupport)
out, _, err := dockerCmdWithError("run", "-m", "16m", "--memory-swap", "15m", "busybox", "echo", "test") out, _, err := dockerCmdWithError("run", "-m", "16m", "--memory-swap", "15m", "busybox", "echo", "test")
@ -690,7 +690,7 @@ func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) { func (s *DockerCLIRunSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) {
testRequires(c, cgroupCpuset, testEnv.IsLocalDaemon) testRequires(c, cgroupCpuset, testEnv.IsLocalDaemon)
sysInfo := sysinfo.New() sysInfo := sysinfo.New()
@ -709,7 +709,7 @@ func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *testing.T) { func (s *DockerCLIRunSuite) TestRunInvalidCpusetMemsFlagValue(c *testing.T) {
testRequires(c, cgroupCpuset) testRequires(c, cgroupCpuset)
sysInfo := sysinfo.New() sysInfo := sysinfo.New()
@ -728,7 +728,7 @@ func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunInvalidCPUShares(c *testing.T) { func (s *DockerCLIRunSuite) TestRunInvalidCPUShares(c *testing.T) {
testRequires(c, cpuShare, DaemonIsLinux) testRequires(c, cpuShare, DaemonIsLinux)
out, _, err := dockerCmdWithError("run", "--cpu-shares", "1", "busybox", "echo", "test") out, _, err := dockerCmdWithError("run", "--cpu-shares", "1", "busybox", "echo", "test")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
@ -746,7 +746,7 @@ func (s *DockerSuite) TestRunInvalidCPUShares(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestRunWithDefaultShmSize(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithDefaultShmSize(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "shm-default" name := "shm-default"
@ -759,7 +759,7 @@ func (s *DockerSuite) TestRunWithDefaultShmSize(c *testing.T) {
assert.Equal(c, shmSize, "67108864") assert.Equal(c, shmSize, "67108864")
} }
func (s *DockerSuite) TestRunWithShmSize(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithShmSize(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "shm" name := "shm"
@ -772,7 +772,7 @@ func (s *DockerSuite) TestRunWithShmSize(c *testing.T) {
assert.Equal(c, shmSize, "1073741824") assert.Equal(c, shmSize, "1073741824")
} }
func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *testing.T) { func (s *DockerCLIRunSuite) TestRunTmpfsMountsEnsureOrdered(c *testing.T) {
tmpFile, err := os.CreateTemp("", "test") tmpFile, err := os.CreateTemp("", "test")
assert.NilError(c, err) assert.NilError(c, err)
defer tmpFile.Close() defer tmpFile.Close()
@ -780,7 +780,7 @@ func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *testing.T) {
assert.Assert(c, strings.Contains(out, "test")) assert.Assert(c, strings.Contains(out, "test"))
} }
func (s *DockerSuite) TestRunTmpfsMounts(c *testing.T) { func (s *DockerCLIRunSuite) TestRunTmpfsMounts(c *testing.T) {
// TODO Windows (Post TP5): This test cannot run on a Windows daemon as // TODO Windows (Post TP5): This test cannot run on a Windows daemon as
// Windows does not support tmpfs mounts. // Windows does not support tmpfs mounts.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -801,7 +801,7 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *testing.T) { func (s *DockerCLIRunSuite) TestRunTmpfsMountsOverrideImageVolumes(c *testing.T) {
name := "img-with-volumes" name := "img-with-volumes"
buildImageSuccessfully(c, name, build.WithDockerfile(` buildImageSuccessfully(c, name, build.WithDockerfile(`
FROM busybox FROM busybox
@ -813,7 +813,7 @@ func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *testing.T) {
} }
// Test case for #22420 // Test case for #22420
func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *testing.T) { func (s *DockerCLIRunSuite) TestRunTmpfsMountsWithOptions(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
expectedOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime"} expectedOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime"}
@ -851,7 +851,7 @@ func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRunSysctls(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSysctls(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
var err error var err error
@ -882,7 +882,7 @@ func (s *DockerSuite) TestRunSysctls(c *testing.T) {
} }
// TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:bullseye-slim unshare' exits with operation not permitted. // TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:bullseye-slim unshare' exits with operation not permitted.
func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompProfileDenyUnshare(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor)
jsonData := `{ jsonData := `{
"defaultAction": "SCMP_ACT_ALLOW", "defaultAction": "SCMP_ACT_ALLOW",
@ -911,7 +911,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *testing.T) {
} }
// TestRunSeccompProfileDenyChmod checks that 'docker run --security-opt seccomp=/tmp/profile.json busybox chmod 400 /etc/hostname' exits with operation not permitted. // TestRunSeccompProfileDenyChmod checks that 'docker run --security-opt seccomp=/tmp/profile.json busybox chmod 400 /etc/hostname' exits with operation not permitted.
func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompProfileDenyChmod(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
jsonData := `{ jsonData := `{
"defaultAction": "SCMP_ACT_ALLOW", "defaultAction": "SCMP_ACT_ALLOW",
@ -946,7 +946,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *testing.T) {
// TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:bullseye-slim unshare --map-root-user --user sh -c whoami' with a specific profile to // TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:bullseye-slim unshare --map-root-user --user sh -c whoami' with a specific profile to
// deny unshare of a userns exits with operation not permitted. // deny unshare of a userns exits with operation not permitted.
func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompProfileDenyUnshareUserns(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor)
// from sched.h // from sched.h
jsonData := fmt.Sprintf(`{ jsonData := fmt.Sprintf(`{
@ -984,7 +984,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *testing.T) {
// TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test' // TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test'
// with a the default seccomp profile exits with operation not permitted. // with a the default seccomp profile exits with operation not permitted.
func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompProfileDenyCloneUserns(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -996,7 +996,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *testing.T) {
// TestRunSeccompUnconfinedCloneUserns checks that // TestRunSeccompUnconfinedCloneUserns checks that
// 'docker run --security-opt seccomp=unconfined syscall-test' allows creating a userns. // 'docker run --security-opt seccomp=unconfined syscall-test' allows creating a userns.
func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompUnconfinedCloneUserns(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace, unprivilegedUsernsClone) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace, unprivilegedUsernsClone)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1009,7 +1009,7 @@ func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *testing.T) {
// TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test' // TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test'
// allows creating a userns. // allows creating a userns.
func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompAllowPrivCloneUserns(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1021,7 +1021,7 @@ func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *testing.T) {
// TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64 // TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64
// with the default seccomp profile. // with the default seccomp profile.
func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompProfileAllow32Bit(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, IsAmd64) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, IsAmd64)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1029,14 +1029,14 @@ func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *testing.T) {
} }
// TestRunSeccompAllowSetrlimit checks that 'docker run debian:bullseye-slim ulimit -v 1048510' succeeds. // TestRunSeccompAllowSetrlimit checks that 'docker run debian:bullseye-slim ulimit -v 1048510' succeeds.
func (s *DockerSuite) TestRunSeccompAllowSetrlimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompAllowSetrlimit(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
// ulimit uses setrlimit, so we want to make sure we don't break it // ulimit uses setrlimit, so we want to make sure we don't break it
icmd.RunCommand(dockerBinary, "run", "debian:bullseye-slim", "bash", "-c", "ulimit -v 1048510").Assert(c, icmd.Success) icmd.RunCommand(dockerBinary, "run", "debian:bullseye-slim", "bash", "-c", "ulimit -v 1048510").Assert(c, icmd.Success)
} }
func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompDefaultProfileAcct(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1066,7 +1066,7 @@ func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *testing.T) {
} }
} }
func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompDefaultProfileNS(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1103,7 +1103,7 @@ func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *testing.T) {
// TestRunNoNewPrivSetuid checks that --security-opt='no-new-privileges=true' prevents // TestRunNoNewPrivSetuid checks that --security-opt='no-new-privileges=true' prevents
// effective uid transitions on executing setuid binaries. // effective uid transitions on executing setuid binaries.
func (s *DockerSuite) TestRunNoNewPrivSetuid(c *testing.T) { func (s *DockerCLIRunSuite) TestRunNoNewPrivSetuid(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
ensureNNPTest(c) ensureNNPTest(c)
@ -1116,7 +1116,7 @@ func (s *DockerSuite) TestRunNoNewPrivSetuid(c *testing.T) {
// TestLegacyRunNoNewPrivSetuid checks that --security-opt=no-new-privileges prevents // TestLegacyRunNoNewPrivSetuid checks that --security-opt=no-new-privileges prevents
// effective uid transitions on executing setuid binaries. // effective uid transitions on executing setuid binaries.
func (s *DockerSuite) TestLegacyRunNoNewPrivSetuid(c *testing.T) { func (s *DockerCLIRunSuite) TestLegacyRunNoNewPrivSetuid(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
ensureNNPTest(c) ensureNNPTest(c)
@ -1127,7 +1127,7 @@ func (s *DockerSuite) TestLegacyRunNoNewPrivSetuid(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesChown(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1145,7 +1145,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1158,7 +1158,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesFowner(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1174,7 +1174,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *testing.T) {
// TODO CAP_KILL // TODO CAP_KILL
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesSetuid(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1192,7 +1192,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesSetgid(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1220,7 +1220,7 @@ func sysctlExists(s string) bool {
return err == nil return err == nil
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1249,7 +1249,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *testing.T
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1267,7 +1267,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesChroot(c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1285,7 +1285,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *testing.T) { func (s *DockerCLIRunSuite) TestUserNoEffectiveCapabilitiesMknod(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
ensureSyscallTest(c) ensureSyscallTest(c)
@ -1307,7 +1307,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *testing.T) {
// TODO CAP_AUDIT_WRITE // TODO CAP_AUDIT_WRITE
// TODO CAP_SETFCAP // TODO CAP_SETFCAP
func (s *DockerSuite) TestRunApparmorProcDirectory(c *testing.T) { func (s *DockerCLIRunSuite) TestRunApparmorProcDirectory(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, Apparmor) testRequires(c, testEnv.IsLocalDaemon, Apparmor)
// running w seccomp unconfined tests the apparmor profile // running w seccomp unconfined tests the apparmor profile
@ -1326,7 +1326,7 @@ func (s *DockerSuite) TestRunApparmorProcDirectory(c *testing.T) {
// make sure the default profile can be successfully parsed (using unshare as it is // make sure the default profile can be successfully parsed (using unshare as it is
// something which we know is blocked in the default profile) // something which we know is blocked in the default profile)
func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *testing.T) { func (s *DockerCLIRunSuite) TestRunSeccompWithDefaultProfile(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled) testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
out, _, err := dockerCmdWithError("run", "--security-opt", "seccomp=../profiles/seccomp/default.json", "debian:bullseye-slim", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami") out, _, err := dockerCmdWithError("run", "--security-opt", "seccomp=../profiles/seccomp/default.json", "debian:bullseye-slim", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami")
@ -1335,7 +1335,7 @@ func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *testing.T) {
} }
// TestRunDeviceSymlink checks run with device that follows symlink (#13840 and #22271) // TestRunDeviceSymlink checks run with device that follows symlink (#13840 and #22271)
func (s *DockerSuite) TestRunDeviceSymlink(c *testing.T) { func (s *DockerCLIRunSuite) TestRunDeviceSymlink(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm, testEnv.IsLocalDaemon)
if _, err := os.Stat("/dev/zero"); err != nil { if _, err := os.Stat("/dev/zero"); err != nil {
c.Skip("Host does not have /dev/zero") c.Skip("Host does not have /dev/zero")
@ -1382,7 +1382,7 @@ func (s *DockerSuite) TestRunDeviceSymlink(c *testing.T) {
} }
// TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit // TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit
func (s *DockerSuite) TestRunPIDsLimit(c *testing.T) { func (s *DockerCLIRunSuite) TestRunPIDsLimit(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, pidsLimit) testRequires(c, testEnv.IsLocalDaemon, pidsLimit)
file := "/sys/fs/cgroup/pids/pids.max" file := "/sys/fs/cgroup/pids/pids.max"
@ -1393,7 +1393,7 @@ func (s *DockerSuite) TestRunPIDsLimit(c *testing.T) {
assert.Equal(c, out, "4", "setting the pids limit failed") assert.Equal(c, out, "4", "setting the pids limit failed")
} }
func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *testing.T) { func (s *DockerCLIRunSuite) TestRunPrivilegedAllowedDevices(c *testing.T) {
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
file := "/sys/fs/cgroup/devices/devices.list" file := "/sys/fs/cgroup/devices/devices.list"
@ -1402,7 +1402,7 @@ func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "a *:* rwm") assert.Equal(c, strings.TrimSpace(out), "a *:* rwm")
} }
func (s *DockerSuite) TestRunUserDeviceAllowed(c *testing.T) { func (s *DockerCLIRunSuite) TestRunUserDeviceAllowed(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
fi, err := os.Stat("/dev/snd/timer") fi, err := os.Stat("/dev/snd/timer")
@ -1543,7 +1543,7 @@ func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *testing.T)
assert.Assert(c, strings.Contains(out, "Operation not permitted")) assert.Assert(c, strings.Contains(out, "Operation not permitted"))
} }
func (s *DockerSuite) TestRunWithNanoCPUs(c *testing.T) { func (s *DockerCLIRunSuite) TestRunWithNanoCPUs(c *testing.T) {
testRequires(c, cpuCfsQuota, cpuCfsPeriod) testRequires(c, cpuCfsQuota, cpuCfsPeriod)
file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"

View file

@ -22,8 +22,20 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
type DockerCLISaveLoadSuite struct {
ds *DockerSuite
}
func (s *DockerCLISaveLoadSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLISaveLoadSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// save a repo using gz compression and try to load it using stdout // save a repo using gz compression and try to load it using stdout
func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-save-xz-and-load-repo-stdout" name := "test-save-xz-and-load-repo-stdout"
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
@ -52,7 +64,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
} }
// save a repo using xz+gz compression and try to load it using stdout // save a repo using xz+gz compression and try to load it using stdout
func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-save-xz-gz-and-load-repo-stdout" name := "test-save-xz-gz-and-load-repo-stdout"
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
@ -81,7 +93,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) {
assert.ErrorContains(c, err, "", "the repo should not exist: %v", after) assert.ErrorContains(c, err, "", "the repo should not exist: %v", after)
} }
func (s *DockerSuite) TestSaveSingleTag(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveSingleTag(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
repoName := "foobar-save-single-tag-test" repoName := "foobar-save-single-tag-test"
dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName)) dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
@ -96,7 +108,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *testing.T) {
assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err) assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
} }
func (s *DockerSuite) TestSaveCheckTimes(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveCheckTimes(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
repoName := "busybox:latest" repoName := "busybox:latest"
out, _ := dockerCmd(c, "inspect", repoName) out, _ := dockerCmd(c, "inspect", repoName)
@ -115,7 +127,7 @@ func (s *DockerSuite) TestSaveCheckTimes(c *testing.T) {
assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err) assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
} }
func (s *DockerSuite) TestSaveImageId(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveImageId(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
repoName := "foobar-save-image-id-test" repoName := "foobar-save-image-id-test"
dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName)) dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
@ -154,7 +166,7 @@ func (s *DockerSuite) TestSaveImageId(c *testing.T) {
} }
// save a repo and try to load it using flags // save a repo and try to load it using flags
func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoFlags(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-save-and-load-repo-flags" name := "test-save-and-load-repo-flags"
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
@ -175,7 +187,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *testing.T) {
assert.Equal(c, before, after, "inspect is not the same after a save / load") assert.Equal(c, before, after, "inspect is not the same after a save / load")
} }
func (s *DockerSuite) TestSaveWithNoExistImage(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveWithNoExistImage(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
imgName := "foobar-non-existing-image" imgName := "foobar-non-existing-image"
@ -185,7 +197,7 @@ func (s *DockerSuite) TestSaveWithNoExistImage(c *testing.T) {
assert.Assert(c, strings.Contains(out, fmt.Sprintf("No such image: %s", imgName))) assert.Assert(c, strings.Contains(out, fmt.Sprintf("No such image: %s", imgName)))
} }
func (s *DockerSuite) TestSaveMultipleNames(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveMultipleNames(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
repoName := "foobar-save-multi-name-test" repoName := "foobar-save-multi-name-test"
@ -203,7 +215,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *testing.T) {
assert.NilError(c, err, "failed to save multiple repos: %s, %v", out, err) assert.NilError(c, err, "failed to save multiple repos: %s, %v", out, err)
} }
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveRepoWithMultipleImages(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
makeImage := func(from string, tag string) string { makeImage := func(from string, tag string) string {
var ( var (
@ -255,7 +267,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *testing.T) {
} }
// Issue #6722 #5892 ensure directories are included in changes // Issue #6722 #5892 ensure directories are included in changes
func (s *DockerSuite) TestSaveDirectoryPermissions(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveDirectoryPermissions(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
layerEntries := []string{"opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"} layerEntries := []string{"opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
layerEntriesAUFS := []string{"./", ".wh..wh.aufs", ".wh..wh.orph/", ".wh..wh.plnk/", "opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"} layerEntriesAUFS := []string{"./", ".wh..wh.aufs", ".wh..wh.orph/", ".wh..wh.plnk/", "opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
@ -329,7 +341,7 @@ func listTar(f io.Reader) ([]string, error) {
// Test loading a weird image where one of the layers is of zero size. // Test loading a weird image where one of the layers is of zero size.
// The layer.tar file is actually zero bytes, no padding or anything else. // The layer.tar file is actually zero bytes, no padding or anything else.
// See issue: 18170 // See issue: 18170
func (s *DockerSuite) TestLoadZeroSizeLayer(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestLoadZeroSizeLayer(c *testing.T) {
// this will definitely not work if using remote daemon // this will definitely not work if using remote daemon
// very weird test // very weird test
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
@ -337,7 +349,7 @@ func (s *DockerSuite) TestLoadZeroSizeLayer(c *testing.T) {
dockerCmd(c, "load", "-i", "testdata/emptyLayer.tar") dockerCmd(c, "load", "-i", "testdata/emptyLayer.tar")
} }
func (s *DockerSuite) TestSaveLoadParents(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveLoadParents(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
makeImage := func(from string, addfile string) string { makeImage := func(from string, addfile string) string {
@ -376,7 +388,7 @@ func (s *DockerSuite) TestSaveLoadParents(c *testing.T) {
assert.Equal(c, inspectOut, "") assert.Equal(c, inspectOut, "")
} }
func (s *DockerSuite) TestSaveLoadNoTag(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveLoadNoTag(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "saveloadnotag" name := "saveloadnotag"

View file

@ -19,7 +19,7 @@ import (
) )
// save a repo and try to load it using stdout // save a repo and try to load it using stdout
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
name := "test-save-and-load-repo-stdout" name := "test-save-and-load-repo-stdout"
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
@ -70,7 +70,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
assert.Assert(c, strings.Contains(string(buf[:n]), "cowardly refusing"), "help output is not being yielded") assert.Assert(c, strings.Contains(string(buf[:n]), "cowardly refusing"), "help output is not being yielded")
} }
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestSaveAndLoadWithProgressBar(c *testing.T) {
name := "test-load" name := "test-load"
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, name, build.WithDockerfile(`FROM busybox
RUN touch aa RUN touch aa
@ -88,7 +88,7 @@ func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *testing.T) {
} }
// fail because load didn't receive data from stdin // fail because load didn't receive data from stdin
func (s *DockerSuite) TestLoadNoStdinFail(c *testing.T) { func (s *DockerCLISaveLoadSuite) TestLoadNoStdinFail(c *testing.T) {
pty, tty, err := pty.Open() pty, tty, err := pty.Open()
assert.NilError(c, err) assert.NilError(c, err)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

View file

@ -8,13 +8,25 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
type DockerCLISearchSuite struct {
ds *DockerSuite
}
func (s *DockerCLISearchSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLISearchSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// search for repos named "registry" on the central registry // search for repos named "registry" on the central registry
func (s *DockerSuite) TestSearchOnCentralRegistry(c *testing.T) { func (s *DockerCLISearchSuite) TestSearchOnCentralRegistry(c *testing.T) {
out, _ := dockerCmd(c, "search", "busybox") out, _ := dockerCmd(c, "search", "busybox")
assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'") assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'")
} }
func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *testing.T) { func (s *DockerCLISearchSuite) TestSearchStarsOptionWithWrongParameter(c *testing.T) {
out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox") out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox")
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
assert.Assert(c, strings.Contains(out, "invalid filter"), "couldn't find the invalid filter warning") assert.Assert(c, strings.Contains(out, "invalid filter"), "couldn't find the invalid filter warning")
@ -32,7 +44,7 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *testing.T) {
assert.Assert(c, strings.Contains(out, "invalid filter"), "couldn't find the invalid filter warning") assert.Assert(c, strings.Contains(out, "invalid filter"), "couldn't find the invalid filter warning")
} }
func (s *DockerSuite) TestSearchCmdOptions(c *testing.T) { func (s *DockerCLISearchSuite) TestSearchCmdOptions(c *testing.T) {
outSearchCmd, _ := dockerCmd(c, "search", "busybox") outSearchCmd, _ := dockerCmd(c, "search", "busybox")
assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd) assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd)
@ -60,12 +72,12 @@ func (s *DockerSuite) TestSearchCmdOptions(c *testing.T) {
} }
// search for repos which start with "ubuntu-" on the central registry // search for repos which start with "ubuntu-" on the central registry
func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *testing.T) { func (s *DockerCLISearchSuite) TestSearchOnCentralRegistryWithDash(c *testing.T) {
dockerCmd(c, "search", "ubuntu-") dockerCmd(c, "search", "ubuntu-")
} }
// test case for #23055 // test case for #23055
func (s *DockerSuite) TestSearchWithLimit(c *testing.T) { func (s *DockerCLISearchSuite) TestSearchWithLimit(c *testing.T) {
for _, limit := range []int{10, 50, 100} { for _, limit := range []int{10, 50, 100} {
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
assert.NilError(c, err) assert.NilError(c, err)

View file

@ -14,7 +14,19 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestClientSetsTLSServerName(c *testing.T) { type DockerCLISNISuite struct {
ds *DockerSuite
}
func (s *DockerCLISNISuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLISNISuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLISNISuite) TestClientSetsTLSServerName(c *testing.T) {
c.Skip("Flakey test") c.Skip("Flakey test")
// there may be more than one hit to the server for each registry request // there may be more than one hit to the server for each registry request
var serverNameReceived []string var serverNameReceived []string

View file

@ -11,8 +11,20 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
type DockerCLIStartSuite struct {
ds *DockerSuite
}
func (s *DockerCLIStartSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIStartSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
// Regression test for https://github.com/docker/docker/issues/7843 // Regression test for https://github.com/docker/docker/issues/7843
func (s *DockerSuite) TestStartAttachReturnsOnError(c *testing.T) { func (s *DockerCLIStartSuite) TestStartAttachReturnsOnError(c *testing.T) {
// Windows does not support link // Windows does not support link
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "test", "busybox") dockerCmd(c, "run", "--name", "test", "busybox")
@ -41,7 +53,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *testing.T) {
} }
// gh#8555: Exit code should be passed through when using start -a // gh#8555: Exit code should be passed through when using start -a
func (s *DockerSuite) TestStartAttachCorrectExitCode(c *testing.T) { func (s *DockerCLIStartSuite) TestStartAttachCorrectExitCode(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1").Stdout() out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1").Stdout()
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
@ -54,7 +66,7 @@ func (s *DockerSuite) TestStartAttachCorrectExitCode(c *testing.T) {
}) })
} }
func (s *DockerSuite) TestStartAttachSilent(c *testing.T) { func (s *DockerCLIStartSuite) TestStartAttachSilent(c *testing.T) {
name := "teststartattachcorrectexitcode" name := "teststartattachcorrectexitcode"
dockerCmd(c, "run", "--name", name, "busybox", "echo", "test") dockerCmd(c, "run", "--name", name, "busybox", "echo", "test")
@ -66,7 +78,7 @@ func (s *DockerSuite) TestStartAttachSilent(c *testing.T) {
assert.Equal(c, startOut, "test\n") assert.Equal(c, startOut, "test\n")
} }
func (s *DockerSuite) TestStartRecordError(c *testing.T) { func (s *DockerCLIStartSuite) TestStartRecordError(c *testing.T) {
// TODO Windows CI: Requires further porting work. Should be possible. // TODO Windows CI: Requires further porting work. Should be possible.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// when container runs successfully, we should not have state.Error // when container runs successfully, we should not have state.Error
@ -90,7 +102,7 @@ func (s *DockerSuite) TestStartRecordError(c *testing.T) {
assert.Equal(c, stateErr, "") assert.Equal(c, stateErr, "")
} }
func (s *DockerSuite) TestStartPausedContainer(c *testing.T) { func (s *DockerCLIStartSuite) TestStartPausedContainer(c *testing.T) {
// Windows does not support pausing containers // Windows does not support pausing containers
testRequires(c, IsPausable) testRequires(c, IsPausable)
@ -105,7 +117,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *testing.T) {
assert.Assert(c, strings.Contains(strings.ToLower(out), "cannot start a paused container, try unpause instead")) assert.Assert(c, strings.Contains(strings.ToLower(out), "cannot start a paused container, try unpause instead"))
} }
func (s *DockerSuite) TestStartMultipleContainers(c *testing.T) { func (s *DockerCLIStartSuite) TestStartMultipleContainers(c *testing.T) {
// Windows does not support --link // Windows does not support --link
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// run a container named 'parent' and create two container link to `parent` // run a container named 'parent' and create two container link to `parent`
@ -141,7 +153,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *testing.T) {
} }
} }
func (s *DockerSuite) TestStartAttachMultipleContainers(c *testing.T) { func (s *DockerCLIStartSuite) TestStartAttachMultipleContainers(c *testing.T) {
// run multiple containers to test // run multiple containers to test
for _, container := range []string{"test1", "test2", "test3"} { for _, container := range []string{"test1", "test2", "test3"} {
runSleepingContainer(c, "--name", container) runSleepingContainer(c, "--name", container)
@ -170,7 +182,7 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *testing.T) {
} }
// Test case for #23716 // Test case for #23716
func (s *DockerSuite) TestStartAttachWithRename(c *testing.T) { func (s *DockerCLIStartSuite) TestStartAttachWithRename(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
cli.DockerCmd(c, "create", "-t", "--name", "before", "busybox") cli.DockerCmd(c, "create", "-t", "--name", "before", "busybox")
go func() { go func() {
@ -185,7 +197,7 @@ func (s *DockerSuite) TestStartAttachWithRename(c *testing.T) {
assert.Assert(c, !strings.Contains(result.Stderr(), "No such container")) assert.Assert(c, !strings.Contains(result.Stderr(), "No such container"))
} }
func (s *DockerSuite) TestStartReturnCorrectExitCode(c *testing.T) { func (s *DockerCLIStartSuite) TestStartReturnCorrectExitCode(c *testing.T) {
cli.DockerCmd(c, "create", "--restart=on-failure:2", "--name", "withRestart", "busybox", "sh", "-c", "exit 11") cli.DockerCmd(c, "create", "--restart=on-failure:2", "--name", "withRestart", "busybox", "sh", "-c", "exit 11")
cli.DockerCmd(c, "create", "--rm", "--name", "withRm", "busybox", "sh", "-c", "exit 12") cli.DockerCmd(c, "create", "--rm", "--name", "withRm", "busybox", "sh", "-c", "exit 12")
cli.Docker(cli.Args("start", "-a", "withRestart")).Assert(c, icmd.Expected{ExitCode: 11}) cli.Docker(cli.Args("start", "-a", "withRestart")).Assert(c, icmd.Expected{ExitCode: 11})

View file

@ -13,7 +13,19 @@ import (
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerSuite) TestStatsNoStream(c *testing.T) { type DockerCLIStatsSuite struct {
ds *DockerSuite
}
func (s *DockerCLIStatsSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIStatsSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIStatsSuite) TestStatsNoStream(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
@ -42,7 +54,7 @@ func (s *DockerSuite) TestStatsNoStream(c *testing.T) {
} }
} }
func (s *DockerSuite) TestStatsContainerNotFound(c *testing.T) { func (s *DockerCLIStatsSuite) TestStatsContainerNotFound(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -55,7 +67,7 @@ func (s *DockerSuite) TestStatsContainerNotFound(c *testing.T) {
assert.Assert(c, is.Contains(out, "No such container: notfound"), "Expected to fail on not found container stats with --no-stream, got %q instead", out) assert.Assert(c, is.Contains(out, "No such container: notfound"), "Expected to fail on not found container stats with --no-stream, got %q instead", out)
} }
func (s *DockerSuite) TestStatsAllRunningNoStream(c *testing.T) { func (s *DockerCLIStatsSuite) TestStatsAllRunningNoStream(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -91,7 +103,7 @@ func (s *DockerSuite) TestStatsAllRunningNoStream(c *testing.T) {
assert.Assert(c, realData != nil, "stat result are empty: %s", out) assert.Assert(c, realData != nil, "stat result are empty: %s", out)
} }
func (s *DockerSuite) TestStatsAllNoStream(c *testing.T) { func (s *DockerCLIStatsSuite) TestStatsAllNoStream(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -121,7 +133,7 @@ func (s *DockerSuite) TestStatsAllNoStream(c *testing.T) {
assert.Assert(c, realData == nil, "stat result of %s should be empty : %s", id1, out) assert.Assert(c, realData == nil, "stat result of %s should be empty : %s", id1, out)
} }
func (s *DockerSuite) TestStatsAllNewContainersAdded(c *testing.T) { func (s *DockerCLIStatsSuite) TestStatsAllNewContainersAdded(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -162,7 +174,7 @@ func (s *DockerSuite) TestStatsAllNewContainersAdded(c *testing.T) {
} }
} }
func (s *DockerSuite) TestStatsFormatAll(c *testing.T) { func (s *DockerCLIStatsSuite) TestStatsFormatAll(c *testing.T) {
// Windows does not support stats // Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)

View file

@ -8,7 +8,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestTopMultipleArgs(c *testing.T) { type DockerCLITopSuite struct {
ds *DockerSuite
}
func (s *DockerCLITopSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLITopSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLITopSuite) TestTopMultipleArgs(c *testing.T) {
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -23,7 +35,7 @@ func (s *DockerSuite) TestTopMultipleArgs(c *testing.T) {
result.Assert(c, expected) result.Assert(c, expected)
} }
func (s *DockerSuite) TestTopNonPrivileged(c *testing.T) { func (s *DockerCLITopSuite) TestTopNonPrivileged(c *testing.T) {
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -47,7 +59,7 @@ func (s *DockerSuite) TestTopNonPrivileged(c *testing.T) {
// TestTopWindowsCoreProcesses validates that there are lines for the critical // TestTopWindowsCoreProcesses validates that there are lines for the critical
// processes which are found in a Windows container. Note Windows is architecturally // processes which are found in a Windows container. Note Windows is architecturally
// very different to Linux in this regard. // very different to Linux in this regard.
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *testing.T) { func (s *DockerCLITopSuite) TestTopWindowsCoreProcesses(c *testing.T) {
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
out := runSleepingContainer(c, "-d") out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
@ -58,7 +70,7 @@ func (s *DockerSuite) TestTopWindowsCoreProcesses(c *testing.T) {
} }
} }
func (s *DockerSuite) TestTopPrivileged(c *testing.T) { func (s *DockerCLITopSuite) TestTopPrivileged(c *testing.T) {
// Windows does not support --privileged // Windows does not support --privileged
testRequires(c, DaemonIsLinux, NotUserNamespace) testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")

View file

@ -0,0 +1,5 @@
package main
type DockerCLIUpdateSuite struct {
ds *DockerSuite
}

View file

@ -19,7 +19,15 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
func (s *DockerSuite) TestUpdateRunningContainer(c *testing.T) { func (s *DockerCLIUpdateSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIUpdateSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIUpdateSuite) TestUpdateRunningContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
@ -34,7 +42,7 @@ func (s *DockerSuite) TestUpdateRunningContainer(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "524288000") assert.Equal(c, strings.TrimSpace(out), "524288000")
} }
func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateRunningContainerWithRestart(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
@ -50,7 +58,7 @@ func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "524288000") assert.Equal(c, strings.TrimSpace(out), "524288000")
} }
func (s *DockerSuite) TestUpdateStoppedContainer(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateStoppedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
@ -65,7 +73,7 @@ func (s *DockerSuite) TestUpdateStoppedContainer(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "524288000") assert.Equal(c, strings.TrimSpace(out), "524288000")
} }
func (s *DockerSuite) TestUpdatePausedContainer(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdatePausedContainer(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, cpuShare) testRequires(c, cpuShare)
@ -82,7 +90,7 @@ func (s *DockerSuite) TestUpdatePausedContainer(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "500") assert.Equal(c, strings.TrimSpace(out), "500")
} }
func (s *DockerSuite) TestUpdateWithUntouchedFields(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateWithUntouchedFields(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, cpuShare) testRequires(c, cpuShare)
@ -100,7 +108,7 @@ func (s *DockerSuite) TestUpdateWithUntouchedFields(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "800") assert.Equal(c, strings.TrimSpace(out), "800")
} }
func (s *DockerSuite) TestUpdateContainerInvalidValue(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateContainerInvalidValue(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
@ -112,7 +120,7 @@ func (s *DockerSuite) TestUpdateContainerInvalidValue(c *testing.T) {
assert.Assert(c, strings.Contains(out, expected)) assert.Assert(c, strings.Contains(out, expected))
} }
func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateContainerWithoutFlags(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
@ -122,7 +130,7 @@ func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *testing.T) {
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
} }
func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateSwapMemoryOnly(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport) testRequires(c, swapMemorySupport)
@ -138,7 +146,7 @@ func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "629145600") assert.Equal(c, strings.TrimSpace(out), "629145600")
} }
func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateInvalidSwapMemory(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport) testRequires(c, swapMemorySupport)
@ -163,7 +171,7 @@ func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "629145600") assert.Equal(c, strings.TrimSpace(out), "629145600")
} }
func (s *DockerSuite) TestUpdateStats(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateStats(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, cpuCfsQuota) testRequires(c, cpuCfsQuota)
@ -192,7 +200,7 @@ func (s *DockerSuite) TestUpdateStats(c *testing.T) {
assert.Equal(c, preMemLimit, curMemLimit) assert.Equal(c, preMemLimit, curMemLimit)
} }
func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateMemoryWithSwapMemory(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport) testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport) testRequires(c, swapMemorySupport)
@ -206,7 +214,7 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *testing.T) {
dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name) dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
} }
func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateNotAffectMonitorRestartPolicy(c *testing.T) {
testRequires(c, DaemonIsLinux, cpuShare) testRequires(c, DaemonIsLinux, cpuShare)
out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh") out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
@ -234,7 +242,7 @@ func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *testing.T) {
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
} }
func (s *DockerSuite) TestUpdateWithNanoCPUs(c *testing.T) { func (s *DockerCLIUpdateSuite) TestUpdateWithNanoCPUs(c *testing.T) {
testRequires(c, cpuCfsQuota, cpuCfsPeriod) testRequires(c, cpuCfsQuota, cpuCfsPeriod)
file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"

View file

@ -18,7 +18,19 @@ import (
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
) )
func (s *DockerSuite) TestVolumeCLICreate(c *testing.T) { type DockerCLIVolumeSuite struct {
ds *DockerSuite
}
func (s *DockerCLIVolumeSuite) TearDownTest(c *testing.T) {
s.ds.TearDownTest(c)
}
func (s *DockerCLIVolumeSuite) OnTimeout(c *testing.T) {
s.ds.OnTimeout(c)
}
func (s *DockerCLIVolumeSuite) TestVolumeCLICreate(c *testing.T) {
dockerCmd(c, "volume", "create") dockerCmd(c, "volume", "create")
_, _, err := dockerCmdWithError("volume", "create", "-d", "nosuchdriver") _, _, err := dockerCmdWithError("volume", "create", "-d", "nosuchdriver")
@ -34,7 +46,7 @@ func (s *DockerSuite) TestVolumeCLICreate(c *testing.T) {
assert.Equal(c, name, "test2") assert.Equal(c, name, "test2")
} }
func (s *DockerSuite) TestVolumeCLIInspect(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIInspect(c *testing.T) {
assert.Assert(c, exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run() != nil, "volume inspect should error on non-existent volume") assert.Assert(c, exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run() != nil, "volume inspect should error on non-existent volume")
out, _ := dockerCmd(c, "volume", "create") out, _ := dockerCmd(c, "volume", "create")
name := strings.TrimSpace(out) name := strings.TrimSpace(out)
@ -46,7 +58,7 @@ func (s *DockerSuite) TestVolumeCLIInspect(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), "test") assert.Equal(c, strings.TrimSpace(out), "test")
} }
func (s *DockerSuite) TestVolumeCLIInspectMulti(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIInspectMulti(c *testing.T) {
dockerCmd(c, "volume", "create", "test1") dockerCmd(c, "volume", "create", "test1")
dockerCmd(c, "volume", "create", "test2") dockerCmd(c, "volume", "create", "test2")
dockerCmd(c, "volume", "create", "test3") dockerCmd(c, "volume", "create", "test3")
@ -63,7 +75,7 @@ func (s *DockerSuite) TestVolumeCLIInspectMulti(c *testing.T) {
assert.Assert(c, strings.Contains(out, "test3")) assert.Assert(c, strings.Contains(out, "test3"))
} }
func (s *DockerSuite) TestVolumeCLILs(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILs(c *testing.T) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform() prefix, _ := getPrefixAndSlashFromDaemonPlatform()
dockerCmd(c, "volume", "create", "aaa") dockerCmd(c, "volume", "create", "aaa")
@ -76,7 +88,7 @@ func (s *DockerSuite) TestVolumeCLILs(c *testing.T) {
assertVolumesInList(c, out, []string{"aaa", "soo", "test"}) assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
} }
func (s *DockerSuite) TestVolumeLsFormat(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeLsFormat(c *testing.T) {
dockerCmd(c, "volume", "create", "aaa") dockerCmd(c, "volume", "create", "aaa")
dockerCmd(c, "volume", "create", "test") dockerCmd(c, "volume", "create", "test")
dockerCmd(c, "volume", "create", "soo") dockerCmd(c, "volume", "create", "soo")
@ -85,7 +97,7 @@ func (s *DockerSuite) TestVolumeLsFormat(c *testing.T) {
assertVolumesInList(c, out, []string{"aaa", "soo", "test"}) assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
} }
func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeLsFormatDefaultFormat(c *testing.T) {
dockerCmd(c, "volume", "create", "aaa") dockerCmd(c, "volume", "create", "aaa")
dockerCmd(c, "volume", "create", "test") dockerCmd(c, "volume", "create", "test")
dockerCmd(c, "volume", "create", "soo") dockerCmd(c, "volume", "create", "soo")
@ -118,7 +130,7 @@ func assertVolumesInList(c *testing.T, out string, expected []string) {
} }
} }
func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILsFilterDangling(c *testing.T) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform() prefix, _ := getPrefixAndSlashFromDaemonPlatform()
dockerCmd(c, "volume", "create", "testnotinuse1") dockerCmd(c, "volume", "create", "testnotinuse1")
dockerCmd(c, "volume", "create", "testisinuse1") dockerCmd(c, "volume", "create", "testisinuse1")
@ -163,19 +175,19 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *testing.T) {
assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output") assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output")
} }
func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *testing.T) {
out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123") out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "invalid filter")) assert.Assert(c, strings.Contains(out, "invalid filter"))
} }
func (s *DockerSuite) TestVolumeCLILsWithIncorrectFilterValue(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILsWithIncorrectFilterValue(c *testing.T) {
out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid") out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "invalid filter")) assert.Assert(c, strings.Contains(out, "invalid filter"))
} }
func (s *DockerSuite) TestVolumeCLIRm(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIRm(c *testing.T) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform() prefix, _ := getPrefixAndSlashFromDaemonPlatform()
out, _ := dockerCmd(c, "volume", "create") out, _ := dockerCmd(c, "volume", "create")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -207,7 +219,7 @@ func (s *DockerSuite) TestVolumeCLIRm(c *testing.T) {
} }
// FIXME(vdemeester) should be a unit test in cli/command/volume package // FIXME(vdemeester) should be a unit test in cli/command/volume package
func (s *DockerSuite) TestVolumeCLINoArgs(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLINoArgs(c *testing.T) {
out, _ := dockerCmd(c, "volume") out, _ := dockerCmd(c, "volume")
// no args should produce the cmd usage output // no args should produce the cmd usage output
usage := "Usage: docker volume COMMAND" usage := "Usage: docker volume COMMAND"
@ -229,7 +241,7 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *testing.T) {
assert.Assert(c, strings.Contains(result.Stderr(), "unknown flag: --no-such-flag")) assert.Assert(c, strings.Contains(result.Stderr(), "unknown flag: --no-such-flag"))
} }
func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIInspectTmplError(c *testing.T) {
out, _ := dockerCmd(c, "volume", "create") out, _ := dockerCmd(c, "volume", "create")
name := strings.TrimSpace(out) name := strings.TrimSpace(out)
@ -239,7 +251,7 @@ func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *testing.T) {
assert.Assert(c, strings.Contains(out, "Template parsing error")) assert.Assert(c, strings.Contains(out, "Template parsing error"))
} }
func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLICreateWithOpts(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "volume", "create", "-d", "local", "test", "--opt=type=tmpfs", "--opt=device=tmpfs", "--opt=o=size=1m,uid=1000") dockerCmd(c, "volume", "create", "-d", "local", "test", "--opt=type=tmpfs", "--opt=device=tmpfs", "--opt=o=size=1m,uid=1000")
@ -263,7 +275,7 @@ func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *testing.T) {
assert.Equal(c, found, true) assert.Equal(c, found, true)
} }
func (s *DockerSuite) TestVolumeCLICreateLabel(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLICreateLabel(c *testing.T) {
testVol := "testvolcreatelabel" testVol := "testvolcreatelabel"
testLabel := "foo" testLabel := "foo"
testValue := "bar" testValue := "bar"
@ -275,7 +287,7 @@ func (s *DockerSuite) TestVolumeCLICreateLabel(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), testValue) assert.Equal(c, strings.TrimSpace(out), testValue)
} }
func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLICreateLabelMultiple(c *testing.T) {
testVol := "testvolcreatelabel" testVol := "testvolcreatelabel"
testLabels := map[string]string{ testLabels := map[string]string{
@ -302,7 +314,7 @@ func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *testing.T) {
} }
} }
func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILsFilterLabels(c *testing.T) {
testVol1 := "testvolcreatelabel-1" testVol1 := "testvolcreatelabel-1"
_, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1) _, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1)
assert.NilError(c, err) assert.NilError(c, err)
@ -330,7 +342,7 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *testing.T) {
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out)) assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
} }
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLILsFilterDrivers(c *testing.T) {
// using default volume driver local to create volumes // using default volume driver local to create volumes
testVol1 := "testvol-1" testVol1 := "testvol-1"
_, _, err := dockerCmdWithError("volume", "create", testVol1) _, _, err := dockerCmdWithError("volume", "create", testVol1)
@ -360,7 +372,7 @@ func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *testing.T) {
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out)) assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
} }
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIRmForceUsage(c *testing.T) {
out, _ := dockerCmd(c, "volume", "create") out, _ := dockerCmd(c, "volume", "create")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -368,7 +380,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *testing.T) {
dockerCmd(c, "volume", "rm", "--force", "nonexist") dockerCmd(c, "volume", "rm", "--force", "nonexist")
} }
func (s *DockerSuite) TestVolumeCLIRmForce(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIRmForce(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
name := "test" name := "test"
@ -392,7 +404,7 @@ func (s *DockerSuite) TestVolumeCLIRmForce(c *testing.T) {
// TestVolumeCLIRmForceInUse verifies that repeated `docker volume rm -f` calls does not remove a volume // TestVolumeCLIRmForceInUse verifies that repeated `docker volume rm -f` calls does not remove a volume
// if it is in use. Test case for https://github.com/docker/docker/issues/31446 // if it is in use. Test case for https://github.com/docker/docker/issues/31446
func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCLIRmForceInUse(c *testing.T) {
name := "testvolume" name := "testvolume"
out, _ := dockerCmd(c, "volume", "create", name) out, _ := dockerCmd(c, "volume", "create", name)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
@ -428,7 +440,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *testing.T) {
assert.Assert(c, !strings.Contains(out, name)) assert.Assert(c, !strings.Contains(out, name))
} }
func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *testing.T) { func (s *DockerCLIVolumeSuite) TestVolumeCliInspectWithVolumeOpts(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Without options // Without options
@ -449,7 +461,7 @@ func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *testing.T) {
} }
// Test case (1) for 21845: duplicate targets for --volumes-from // Test case (1) for 21845: duplicate targets for --volumes-from
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *testing.T) { func (s *DockerCLIVolumeSuite) TestDuplicateMountpointsForVolumesFrom(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
image := "vimage" image := "vimage"
@ -490,7 +502,7 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *testing.T) {
} }
// Test case (2) for 21845: duplicate targets for --volumes-from and -v (bind) // Test case (2) for 21845: duplicate targets for --volumes-from and -v (bind)
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *testing.T) { func (s *DockerCLIVolumeSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
image := "vimage" image := "vimage"
@ -532,7 +544,7 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *testing.T
} }
// Test case (3) for 21845: duplicate targets for --volumes-from and `Mounts` (API only) // Test case (3) for 21845: duplicate targets for --volumes-from and `Mounts` (API only)
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *testing.T) { func (s *DockerCLIVolumeSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
image := "vimage" image := "vimage"

View file

@ -18,7 +18,7 @@ func formatV123StartAPIURL(url string) string {
return "/v1.23" + url return "/v1.23" + url
} }
func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) {
name := "test-deprecated-api-124" name := "test-deprecated-api-124"
dockerCmd(c, "create", "--name", name, "busybox") dockerCmd(c, "create", "--name", name, "busybox")
config := map[string]interface{}{ config := map[string]interface{}{
@ -37,7 +37,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) {
} }
} }
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumeBinds(c *testing.T) {
// TODO Windows CI: Investigate further why this fails on Windows to Windows CI. // TODO Windows CI: Investigate further why this fails on Windows to Windows CI.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
path := "/foo" path := "/foo"
@ -68,7 +68,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *testing.T) {
} }
// Test for GH#10618 // Test for GH#10618
func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *testing.T) {
// TODO Windows to Windows CI - Port this // TODO Windows to Windows CI - Port this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testdups" name := "testdups"
@ -101,7 +101,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *testing.T
assert.Assert(c, strings.Contains(string(buf), "Duplicate mount point"), "Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(buf), err) assert.Assert(c, strings.Contains(string(buf), "Duplicate mount point"), "Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(buf), err)
} }
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T) {
// TODO Windows to Windows CI - Port this // TODO Windows to Windows CI - Port this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
volName := "voltst" volName := "voltst"
@ -134,7 +134,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T) {
} }
// #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume // #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume
func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) {
// TODO Windows to Windows CI - Port this // TODO Windows to Windows CI - Port this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox") dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
@ -154,7 +154,7 @@ func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T)
assert.Equal(c, fooDir2, fooDir, "expected volume path to be %s, got: %s", fooDir, fooDir2) assert.Equal(c, fooDir2, fooDir, "expected volume path to be %s, got: %s", fooDir, fooDir2)
} }
func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) {
// TODO Windows: Port once memory is supported // TODO Windows: Port once memory is supported
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
@ -179,7 +179,7 @@ func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) {
} }
// #14640 // #14640
func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *testing.T) {
// TODO Windows: Windows doesn't support supplying a hostconfig on start. // TODO Windows: Windows doesn't support supplying a hostconfig on start.
// An alternate test could be written to validate the negative testing aspect of this // An alternate test could be written to validate the negative testing aspect of this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -196,7 +196,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(
} }
// #14640 // #14640
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *testing.T) {
// TODO Windows: Windows doesn't support supplying a hostconfig on start. // TODO Windows: Windows doesn't support supplying a hostconfig on start.
// An alternate test could be written to validate the negative testing aspect of this // An alternate test could be written to validate the negative testing aspect of this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
@ -214,7 +214,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *
} }
// #14640 // #14640
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) {
// Windows does not support links // Windows does not support links
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-host-config-links" name := "test-host-config-links"
@ -233,7 +233,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLi
b.Close() b.Close()
} }
func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedStartWithNilDNS(c *testing.T) {
// TODO Windows: Add once DNS is supported // TODO Windows: Add once DNS is supported
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")