Merge pull request #39799 from tiborvass/bye-bye-gocheck
Remove go-check
This commit is contained in:
commit
1fd0107d7f
130 changed files with 4262 additions and 7724 deletions
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
|
@ -306,10 +306,10 @@ pipeline {
|
|||
TEST_INTEGRATION_DEST=1 CONTAINER_NAME=${CONTAINER_NAME}-1 TEST_SKIP_INTEGRATION_CLI=1 run_tests test-integration-flaky &
|
||||
|
||||
# integration-cli first set
|
||||
TEST_INTEGRATION_DEST=2 CONTAINER_NAME=${CONTAINER_NAME}-2 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-check.f ^(DockerSuite|DockerNetworkSuite|DockerHubPullSuite|DockerRegistrySuite|DockerSchema1RegistrySuite|DockerRegistryAuthTokenSuite|DockerRegistryAuthHtpasswdSuite)" run_tests &
|
||||
TEST_INTEGRATION_DEST=2 CONTAINER_NAME=${CONTAINER_NAME}-2 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run /(DockerSuite|DockerNetworkSuite|DockerHubPullSuite|DockerRegistrySuite|DockerSchema1RegistrySuite|DockerRegistryAuthTokenSuite|DockerRegistryAuthHtpasswdSuite)/" run_tests &
|
||||
|
||||
# integration-cli second set
|
||||
TEST_INTEGRATION_DEST=3 CONTAINER_NAME=${CONTAINER_NAME}-3 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-check.f ^(DockerSwarmSuite|DockerDaemonSuite|DockerExternalVolumeSuite)" run_tests &
|
||||
TEST_INTEGRATION_DEST=3 CONTAINER_NAME=${CONTAINER_NAME}-3 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run /(DockerSwarmSuite|DockerDaemonSuite|DockerExternalVolumeSuite)/" run_tests &
|
||||
|
||||
set +x
|
||||
c=0
|
||||
|
|
|
@ -174,13 +174,13 @@ flag's value is passed as arguments to the `go test` command. For example, from
|
|||
your local host you can run the `TestBuild` test with this command:
|
||||
|
||||
```bash
|
||||
$ TESTFLAGS='-check.f DockerSuite.TestBuild*' make test-integration
|
||||
$ TESTFLAGS='-test.run /DockerSuite/TestBuild*' make test-integration
|
||||
```
|
||||
|
||||
To run the same test inside your Docker development container, you do this:
|
||||
|
||||
```bash
|
||||
# TESTFLAGS='-check.f TestBuild*' hack/make.sh binary test-integration
|
||||
# TESTFLAGS='-test.run /DockerSuite/TestBuild*' hack/make.sh binary test-integration
|
||||
```
|
||||
|
||||
## Test the Windows binary against a Linux daemon
|
||||
|
@ -228,11 +228,11 @@ run a Bash terminal on Windows.
|
|||
```
|
||||
|
||||
Should you wish to run a single test such as one with the name
|
||||
'TestExample', you can pass in `TESTFLAGS='-check.f TestExample'`. For
|
||||
'TestExample', you can pass in `TESTFLAGS='-test.run //TestExample'`. For
|
||||
example
|
||||
|
||||
```bash
|
||||
$ TESTFLAGS='-check.f TestExample' hack/make.sh binary test-integration
|
||||
$ TESTFLAGS='-test.run //TestExample' hack/make.sh binary test-integration
|
||||
```
|
||||
|
||||
You can now choose to make changes to the Moby source or the tests. If you
|
||||
|
|
|
@ -797,14 +797,13 @@ Try {
|
|||
|
||||
#https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising
|
||||
$c = "go test "
|
||||
$c += "`"-check.v`" "
|
||||
$c += "`"-test.v`" "
|
||||
if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
|
||||
$c += "`"-check.f`" "
|
||||
$c += "`"-test.run`" "
|
||||
$c += "`"$env:INTEGRATION_TEST_NAME`" "
|
||||
Write-Host -ForegroundColor Magenta "WARN: Only running integration tests matching $env:INTEGRATION_TEST_NAME"
|
||||
}
|
||||
$c += "`"-tags`" " + "`"autogen`" "
|
||||
$c += "`"-check.timeout`" " + "`"10m`" "
|
||||
$c += "`"-test.timeout`" " + "`"200m`" "
|
||||
|
||||
if ($null -ne $env:INTEGRATION_IN_CONTAINER) {
|
||||
|
@ -892,14 +891,13 @@ Try {
|
|||
} else {
|
||||
#https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising
|
||||
$c = "go test "
|
||||
$c += "`"-check.v`" "
|
||||
$c += "`"-test.v`" "
|
||||
if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
|
||||
$c += "`"-check.f`" "
|
||||
$c += "`"-test.run`" "
|
||||
$c += "`"$env:INTEGRATION_TEST_NAME`" "
|
||||
Write-Host -ForegroundColor Magenta "WARN: Only running LCOW integration tests matching $env:INTEGRATION_TEST_NAME"
|
||||
}
|
||||
$c += "`"-tags`" " + "`"autogen`" "
|
||||
$c += "`"-check.timeout`" " + "`"10m`" "
|
||||
$c += "`"-test.timeout`" " + "`"200m`" "
|
||||
|
||||
Write-Host -ForegroundColor Green "INFO: LCOW Integration tests being run from the host:"
|
||||
|
|
|
@ -3,20 +3,9 @@
|
|||
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
|
||||
# to run certain tests on your local host, you should run with command:
|
||||
#
|
||||
# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration
|
||||
# TESTFLAGS='-test.run /DockerSuite/TestBuild*' ./hack/make.sh binary test-integration
|
||||
#
|
||||
|
||||
if [[ "${TESTFLAGS}" = *-check.f* ]]; then
|
||||
echo Skipping integration tests since TESTFLAGS includes integration-cli only flags
|
||||
TEST_SKIP_INTEGRATION=1
|
||||
fi
|
||||
|
||||
if [[ "${TESTFLAGS}" = *-test.run* ]]; then
|
||||
echo Skipping integration-cli tests since TESTFLAGS includes integration only flags
|
||||
TEST_SKIP_INTEGRATION_CLI=1
|
||||
fi
|
||||
|
||||
|
||||
if [ -z "${MAKEDIR}" ]; then
|
||||
MAKEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
export MAKEDIR
|
||||
|
@ -32,24 +21,22 @@ setup_integration_test_filter() {
|
|||
if [ -z "${TEST_FILTER}" ]; then
|
||||
return
|
||||
fi
|
||||
TESTFLAGS+="-test.run ${TEST_FILTER}"
|
||||
|
||||
local dirs
|
||||
dirs=$(grep -rIlE --include '*_test.go' "func .*${TEST_FILTER}.*\(. \*testing\.T\)" ./integration*/ | xargs -I file dirname file | uniq)
|
||||
if [ -z "${TEST_SKIP_INTEGRATION}" ]; then
|
||||
: "${TEST_INTEGRATION_DIR:=$(grep -rl "func\ .*${TEST_FILTER}.*\(t\ \*testing\.T\)" ./integration | grep '_test\.go' | xargs -I file dirname file | uniq)}"
|
||||
: "${TEST_INTEGRATION_DIR:=$(echo "$dirs" | grep -v '^\./integration-cli$')}"
|
||||
if [ -z "${TEST_INTEGRATION_DIR}" ]; then
|
||||
echo "Skipping integration tests since the supplied filter \"${TEST_FILTER}\" omits all integration tests"
|
||||
TEST_SKIP_INTEGRATION=1
|
||||
else
|
||||
TESTFLAGS_INTEGRATION+="-test.run ${TEST_FILTER}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${TEST_SKIP_INTEGRATION_CLI}" ]; then
|
||||
# ease up on the filtering here since CLI suites are namespaced by an object
|
||||
if grep -r "${TEST_FILTER}.*\(c\ \*check\.C\)" ./integration-cli | grep -q '_test\.go$'; then
|
||||
if echo "$dirs" | grep -vq '^./integration-cli$'; then
|
||||
TEST_SKIP_INTEGRATION_CLI=1
|
||||
echo "Skipping integration-cli tests since the supplied filter \"${TEST_FILTER}\" omits all integration-cli tests"
|
||||
else
|
||||
TESTFLAGS_INTEGRATION_CLI+="-check.f ${TEST_FILTER}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -68,7 +55,7 @@ run_test_integration() {
|
|||
}
|
||||
|
||||
run_test_integration_suites() {
|
||||
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS ${TESTFLAGS_INTEGRATION}"
|
||||
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
||||
for dir in ${integration_api_dirs}; do
|
||||
if ! (
|
||||
cd "$dir"
|
||||
|
@ -81,7 +68,7 @@ run_test_integration_suites() {
|
|||
|
||||
run_test_integration_legacy_suites() {
|
||||
(
|
||||
flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS ${TESTFLAGS_INTEGRATION_CLI}"
|
||||
flags="-test.v -test.timeout=360m $TESTFLAGS"
|
||||
cd integration-cli
|
||||
echo "Running $PWD flags=${flags}"
|
||||
# shellcheck disable=SC2086
|
||||
|
|
|
@ -18,12 +18,8 @@ integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(
|
|||
|
||||
run_test_integration() {
|
||||
set_platform_timeout
|
||||
if [[ "$TESTFLAGS" != *-check.f* ]]; then
|
||||
run_test_integration_suites
|
||||
fi
|
||||
if [[ "$TESTFLAGS" != *-test.run* ]]; then
|
||||
run_test_integration_legacy_suites
|
||||
fi
|
||||
run_test_integration_suites
|
||||
run_test_integration_legacy_suites
|
||||
}
|
||||
|
||||
run_test_integration_suites() {
|
||||
|
@ -39,7 +35,7 @@ run_test_integration_suites() {
|
|||
|
||||
run_test_integration_legacy_suites() {
|
||||
(
|
||||
flags="-check.v -check.timeout=${TIMEOUT:-200m} -test.timeout=360m $TESTFLAGS"
|
||||
flags="-test.v -test.timeout=360m $TESTFLAGS"
|
||||
cd /tests/integration-cli
|
||||
echo "Running $PWD"
|
||||
test_env ./test.main $flags
|
||||
|
|
|
@ -10,8 +10,7 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
. ${SCRIPTDIR}/pkg-imports
|
||||
. ${SCRIPTDIR}/swagger
|
||||
. ${SCRIPTDIR}/swagger-gen
|
||||
. ${SCRIPTDIR}/test-imports
|
||||
. ${SCRIPTDIR}/toml
|
||||
. ${SCRIPTDIR}/changelog-well-formed
|
||||
. ${SCRIPTDIR}/changelog-date-descending
|
||||
. ${SCRIPTDIR}/deprecate-integration-cli
|
||||
#. ${SCRIPTDIR}/deprecate-integration-cli
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Make sure we're not using gos' Testing package any more in integration-cli
|
||||
|
||||
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source "${SCRIPTDIR}/.validate"
|
||||
|
||||
IFS=$'\n'
|
||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'integration-cli/*.go' || true) )
|
||||
unset IFS
|
||||
|
||||
badFiles=()
|
||||
for f in "${files[@]}"; do
|
||||
# skip check_test.go since it *does* use the testing package
|
||||
if [ "$f" = "integration-cli/check_test.go" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# we use "git show" here to validate that what's committed doesn't contain golang built-in testing
|
||||
if git show "$VALIDATE_HEAD:$f" | grep -q testing.T; then
|
||||
if [ "$(echo $f | grep '_test')" ]; then
|
||||
# allow testing.T for non- _test files
|
||||
badFiles+=( "$f" )
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#badFiles[@]} -eq 0 ]; then
|
||||
echo 'Congratulations! No testing.T found.'
|
||||
else
|
||||
{
|
||||
echo "These files use the wrong testing infrastructure:"
|
||||
for f in "${badFiles[@]}"; do
|
||||
echo " - $f"
|
||||
done
|
||||
echo
|
||||
} >&2
|
||||
false
|
||||
fi
|
|
@ -7,12 +7,12 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *check.C) {
|
||||
func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
|
||||
maxConcurrency := runtime.GOMAXPROCS(0)
|
||||
numIterations := c.N
|
||||
outerGroup := &sync.WaitGroup{}
|
||||
|
|
|
@ -2,12 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
@ -22,8 +24,8 @@ import (
|
|||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/docker/docker/internal/test/fixtures/plugin"
|
||||
"github.com/docker/docker/internal/test/registry"
|
||||
"github.com/docker/docker/internal/test/suite"
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -58,6 +60,9 @@ func init() {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
|
||||
// Global set up
|
||||
dockerBinary = testEnv.DockerBinary()
|
||||
err := ienv.EnsureFrozenImagesLinux(&testEnv.Execution)
|
||||
if err != nil {
|
||||
|
@ -73,17 +78,27 @@ func Test(t *testing.T) {
|
|||
cli.SetTestEnvironment(testEnv)
|
||||
fakestorage.SetTestEnvironment(&testEnv.Execution)
|
||||
ienv.ProtectAll(t, &testEnv.Execution)
|
||||
check.TestingT(t)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerSuite{})
|
||||
suite.Run(t, &DockerSuite{})
|
||||
suite.Run(t, &DockerRegistrySuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerSchema1RegistrySuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerRegistryAuthHtpasswdSuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerRegistryAuthTokenSuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerDaemonSuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerSwarmSuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerPluginSuite{ds: &DockerSuite{}})
|
||||
if runtime.GOOS != "windows" {
|
||||
suite.Run(t, &DockerExternalVolumeSuite{ds: &DockerSuite{}})
|
||||
suite.Run(t, &DockerNetworkSuite{ds: &DockerSuite{}})
|
||||
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
|
||||
// Windows to Linux CI @icecrime
|
||||
suite.Run(t, newDockerHubPullSuite())
|
||||
}
|
||||
}
|
||||
|
||||
type DockerSuite struct {
|
||||
}
|
||||
|
||||
func (s *DockerSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerSuite) OnTimeout(c *testing.T) {
|
||||
if testEnv.IsRemoteDaemon() {
|
||||
return
|
||||
}
|
||||
|
@ -104,34 +119,28 @@ func (s *DockerSuite) OnTimeout(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerSuite) TearDownTest(c *testing.T) {
|
||||
testEnv.Clean(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerRegistrySuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerRegistrySuite struct {
|
||||
ds *DockerSuite
|
||||
reg *registry.V2
|
||||
d *daemon.Daemon
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerRegistrySuite) OnTimeout(c *testing.T) {
|
||||
s.d.DumpStackAndQuit()
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
||||
s.reg = registry.NewV2(c)
|
||||
s.reg.WaitReady(c)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TearDownTest(c *testing.T) {
|
||||
if s.reg != nil {
|
||||
s.reg.Close()
|
||||
}
|
||||
|
@ -141,30 +150,24 @@ func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerSchema1RegistrySuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerSchema1RegistrySuite struct {
|
||||
ds *DockerSuite
|
||||
reg *registry.V2
|
||||
d *daemon.Daemon
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) OnTimeout(c *testing.T) {
|
||||
s.d.DumpStackAndQuit()
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64, testEnv.IsLocalDaemon)
|
||||
s.reg = registry.NewV2(c, registry.Schema1)
|
||||
s.reg.WaitReady(c)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TearDownTest(c *testing.T) {
|
||||
if s.reg != nil {
|
||||
s.reg.Close()
|
||||
}
|
||||
|
@ -174,30 +177,24 @@ func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerRegistryAuthHtpasswdSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerRegistryAuthHtpasswdSuite struct {
|
||||
ds *DockerSuite
|
||||
reg *registry.V2
|
||||
d *daemon.Daemon
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *testing.T) {
|
||||
s.d.DumpStackAndQuit()
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
||||
s.reg = registry.NewV2(c, registry.Htpasswd)
|
||||
s.reg.WaitReady(c)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *testing.T) {
|
||||
if s.reg != nil {
|
||||
out, err := s.d.Cmd("logout", privateRegistryURL)
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -209,28 +206,22 @@ func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerRegistryAuthTokenSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerRegistryAuthTokenSuite struct {
|
||||
ds *DockerSuite
|
||||
reg *registry.V2
|
||||
d *daemon.Daemon
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *testing.T) {
|
||||
s.d.DumpStackAndQuit()
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *testing.T) {
|
||||
if s.reg != nil {
|
||||
out, err := s.d.Cmd("logout", privateRegistryURL)
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -242,7 +233,7 @@ func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C, tokenURL string) {
|
||||
func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *testing.T, tokenURL string) {
|
||||
if s == nil {
|
||||
c.Fatal("registry suite isn't initialized")
|
||||
}
|
||||
|
@ -250,27 +241,21 @@ func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C,
|
|||
s.reg.WaitReady(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerDaemonSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerDaemonSuite struct {
|
||||
ds *DockerSuite
|
||||
d *daemon.Daemon
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerDaemonSuite) OnTimeout(c *testing.T) {
|
||||
s.d.DumpStackAndQuit()
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerDaemonSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TearDownTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
if s.d != nil {
|
||||
s.d.Stop(c)
|
||||
|
@ -278,7 +263,7 @@ func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TearDownSuite(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TearDownSuite(c *testing.T) {
|
||||
filepath.Walk(testdaemon.SockRoot, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// ignore errors here
|
||||
|
@ -295,12 +280,6 @@ func (s *DockerDaemonSuite) TearDownSuite(c *check.C) {
|
|||
|
||||
const defaultSwarmPort = 2477
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerSwarmSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerSwarmSuite struct {
|
||||
server *httptest.Server
|
||||
ds *DockerSuite
|
||||
|
@ -309,7 +288,7 @@ type DockerSwarmSuite struct {
|
|||
portIndex int
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerSwarmSuite) OnTimeout(c *testing.T) {
|
||||
s.daemonsLock.Lock()
|
||||
defer s.daemonsLock.Unlock()
|
||||
for _, d := range s.daemons {
|
||||
|
@ -317,11 +296,11 @@ func (s *DockerSwarmSuite) OnTimeout(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerSwarmSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *daemon.Daemon {
|
||||
func (s *DockerSwarmSuite) AddDaemon(c *testing.T, joinSwarm, manager bool) *daemon.Daemon {
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary,
|
||||
testdaemon.WithEnvironment(testEnv.Execution),
|
||||
testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex),
|
||||
|
@ -344,7 +323,7 @@ func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *daemo
|
|||
return d
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TearDownTest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
s.daemonsLock.Lock()
|
||||
for _, d := range s.daemons {
|
||||
|
@ -359,12 +338,6 @@ func (s *DockerSwarmSuite) TearDownTest(c *check.C) {
|
|||
s.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerPluginSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type DockerPluginSuite struct {
|
||||
ds *DockerSuite
|
||||
registry *registry.V2
|
||||
|
@ -381,7 +354,7 @@ func (ps *DockerPluginSuite) getPluginRepoWithTag() string {
|
|||
return ps.getPluginRepo() + ":" + "latest"
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) SetUpSuite(c *check.C) {
|
||||
func (ps *DockerPluginSuite) SetUpSuite(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, RegistryHosting)
|
||||
ps.registry = registry.NewV2(c)
|
||||
ps.registry.WaitReady(c)
|
||||
|
@ -393,16 +366,16 @@ func (ps *DockerPluginSuite) SetUpSuite(c *check.C) {
|
|||
assert.NilError(c, err, "failed to create plugin")
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TearDownSuite(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TearDownSuite(c *testing.T) {
|
||||
if ps.registry != nil {
|
||||
ps.registry.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TearDownTest(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TearDownTest(c *testing.T) {
|
||||
ps.ds.TearDownTest(c)
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) OnTimeout(c *check.C) {
|
||||
func (ps *DockerPluginSuite) OnTimeout(c *testing.T) {
|
||||
ps.ds.OnTimeout(c)
|
||||
}
|
||||
|
|
|
@ -1,24 +1,78 @@
|
|||
// Package checker provides Docker specific implementations of the go-check.Checker interface.
|
||||
// Package checker provides helpers for gotest.tools/assert.
|
||||
// Please remove this package whenever possible.
|
||||
package checker // import "github.com/docker/docker/integration-cli/checker"
|
||||
|
||||
import (
|
||||
"github.com/go-check/check"
|
||||
"github.com/vdemeester/shakers"
|
||||
"fmt"
|
||||
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
// As a commodity, we bring all check.Checker variables into the current namespace to avoid having
|
||||
// to think about check.X versus checker.X.
|
||||
var (
|
||||
DeepEquals = check.DeepEquals
|
||||
HasLen = check.HasLen
|
||||
IsNil = check.IsNil
|
||||
Matches = check.Matches
|
||||
Not = check.Not
|
||||
NotNil = check.NotNil
|
||||
type Compare func(x interface{}) assert.BoolOrComparison
|
||||
|
||||
Contains = shakers.Contains
|
||||
Equals = shakers.Equals
|
||||
False = shakers.False
|
||||
GreaterThan = shakers.GreaterThan
|
||||
True = shakers.True
|
||||
)
|
||||
func False() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return !x.(bool)
|
||||
}
|
||||
}
|
||||
|
||||
func True() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
func Equals(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Equal(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func Contains(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Contains(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func Not(c Compare) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
r := c(x)
|
||||
switch r := r.(type) {
|
||||
case bool:
|
||||
return !r
|
||||
case cmp.Comparison:
|
||||
return !r().Success()
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected type %T", r))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DeepEquals(y interface{}) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.DeepEqual(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func HasLen(y int) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Len(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func IsNil() Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return cmp.Nil(x)
|
||||
}
|
||||
}
|
||||
|
||||
func GreaterThan(y int) Compare {
|
||||
return func(x interface{}) assert.BoolOrComparison {
|
||||
return x.(int) > y
|
||||
}
|
||||
}
|
||||
|
||||
func NotNil() Compare {
|
||||
return Not(IsNil())
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package daemon // import "github.com/docker/docker/integration-cli/daemon"
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/go-check/check"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
|
@ -88,13 +88,13 @@ func (d *Daemon) inspectFieldWithError(name, field string) (string, error) {
|
|||
|
||||
// CheckActiveContainerCount returns the number of active containers
|
||||
// FIXME(vdemeester) should re-use ActivateContainers in some way
|
||||
func (d *Daemon) CheckActiveContainerCount(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckActiveContainerCount(c *testing.T) (interface{}, string) {
|
||||
out, err := d.Cmd("ps", "-q")
|
||||
assert.NilError(c, err)
|
||||
if len(strings.TrimSpace(out)) == 0 {
|
||||
return 0, nil
|
||||
return 0, ""
|
||||
}
|
||||
return len(strings.Split(strings.TrimSpace(out), "\n")), check.Commentf("output: %q", string(out))
|
||||
return len(strings.Split(strings.TrimSpace(out), "\n")), fmt.Sprintf("output: %q", string(out))
|
||||
}
|
||||
|
||||
// WaitRun waits for a container to be running for 10s
|
||||
|
|
|
@ -4,19 +4,19 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// CheckServiceTasksInState returns the number of tasks with a matching state,
|
||||
// and optional message substring.
|
||||
func (d *Daemon) CheckServiceTasksInState(service string, state swarm.TaskState, message string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckServiceTasksInState(service string, state swarm.TaskState, message string) func(*testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
tasks := d.GetServiceTasks(c, service)
|
||||
var count int
|
||||
for _, task := range tasks {
|
||||
|
@ -26,14 +26,14 @@ func (d *Daemon) CheckServiceTasksInState(service string, state swarm.TaskState,
|
|||
}
|
||||
}
|
||||
}
|
||||
return count, nil
|
||||
return count, ""
|
||||
}
|
||||
}
|
||||
|
||||
// CheckServiceTasksInStateWithError returns the number of tasks with a matching state,
|
||||
// and optional message substring.
|
||||
func (d *Daemon) CheckServiceTasksInStateWithError(service string, state swarm.TaskState, errorMessage string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckServiceTasksInStateWithError(service string, state swarm.TaskState, errorMessage string) func(*testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
tasks := d.GetServiceTasks(c, service)
|
||||
var count int
|
||||
for _, task := range tasks {
|
||||
|
@ -43,62 +43,62 @@ func (d *Daemon) CheckServiceTasksInStateWithError(service string, state swarm.T
|
|||
}
|
||||
}
|
||||
}
|
||||
return count, nil
|
||||
return count, ""
|
||||
}
|
||||
}
|
||||
|
||||
// CheckServiceRunningTasks returns the number of running tasks for the specified service
|
||||
func (d *Daemon) CheckServiceRunningTasks(service string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckServiceRunningTasks(service string) func(*testing.T) (interface{}, string) {
|
||||
return d.CheckServiceTasksInState(service, swarm.TaskStateRunning, "")
|
||||
}
|
||||
|
||||
// CheckServiceUpdateState returns the current update state for the specified service
|
||||
func (d *Daemon) CheckServiceUpdateState(service string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckServiceUpdateState(service string) func(*testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
service := d.GetService(c, service)
|
||||
if service.UpdateStatus == nil {
|
||||
return "", nil
|
||||
return "", ""
|
||||
}
|
||||
return service.UpdateStatus.State, nil
|
||||
return service.UpdateStatus.State, ""
|
||||
}
|
||||
}
|
||||
|
||||
// CheckPluginRunning returns the runtime state of the plugin
|
||||
func (d *Daemon) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckPluginRunning(plugin string) func(c *testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
apiclient := d.NewClientT(c)
|
||||
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
|
||||
if client.IsErrNotFound(err) {
|
||||
return false, check.Commentf("%v", err)
|
||||
return false, fmt.Sprintf("%v", err)
|
||||
}
|
||||
assert.NilError(c, err)
|
||||
return resp.Enabled, check.Commentf("%+v", resp)
|
||||
return resp.Enabled, fmt.Sprintf("%+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
// CheckPluginImage returns the runtime state of the plugin
|
||||
func (d *Daemon) CheckPluginImage(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckPluginImage(plugin string) func(c *testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
apiclient := d.NewClientT(c)
|
||||
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
|
||||
if client.IsErrNotFound(err) {
|
||||
return false, check.Commentf("%v", err)
|
||||
return false, fmt.Sprintf("%v", err)
|
||||
}
|
||||
assert.NilError(c, err)
|
||||
return resp.PluginReference, check.Commentf("%+v", resp)
|
||||
return resp.PluginReference, fmt.Sprintf("%+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
// CheckServiceTasks returns the number of tasks for the specified service
|
||||
func (d *Daemon) CheckServiceTasks(service string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckServiceTasks(service string) func(*testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
tasks := d.GetServiceTasks(c, service)
|
||||
return len(tasks), nil
|
||||
return len(tasks), ""
|
||||
}
|
||||
}
|
||||
|
||||
// CheckRunningTaskNetworks returns the number of times each network is referenced from a task.
|
||||
func (d *Daemon) CheckRunningTaskNetworks(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckRunningTaskNetworks(c *testing.T) (interface{}, string) {
|
||||
cli := d.NewClientT(c)
|
||||
defer cli.Close()
|
||||
|
||||
|
@ -118,11 +118,11 @@ func (d *Daemon) CheckRunningTaskNetworks(c *check.C) (interface{}, check.Commen
|
|||
result[network.Target]++
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return result, ""
|
||||
}
|
||||
|
||||
// CheckRunningTaskImages returns the times each image is running as a task.
|
||||
func (d *Daemon) CheckRunningTaskImages(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckRunningTaskImages(c *testing.T) (interface{}, string) {
|
||||
cli := d.NewClientT(c)
|
||||
defer cli.Close()
|
||||
|
||||
|
@ -142,11 +142,11 @@ func (d *Daemon) CheckRunningTaskImages(c *check.C) (interface{}, check.CommentI
|
|||
result[task.Spec.ContainerSpec.Image]++
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return result, ""
|
||||
}
|
||||
|
||||
// CheckNodeReadyCount returns the number of ready node on the swarm
|
||||
func (d *Daemon) CheckNodeReadyCount(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckNodeReadyCount(c *testing.T) (interface{}, string) {
|
||||
nodes := d.ListNodes(c)
|
||||
var readyCount int
|
||||
for _, node := range nodes {
|
||||
|
@ -154,28 +154,28 @@ func (d *Daemon) CheckNodeReadyCount(c *check.C) (interface{}, check.CommentInte
|
|||
readyCount++
|
||||
}
|
||||
}
|
||||
return readyCount, nil
|
||||
return readyCount, ""
|
||||
}
|
||||
|
||||
// CheckLocalNodeState returns the current swarm node state
|
||||
func (d *Daemon) CheckLocalNodeState(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckLocalNodeState(c *testing.T) (interface{}, string) {
|
||||
info := d.SwarmInfo(c)
|
||||
return info.LocalNodeState, nil
|
||||
return info.LocalNodeState, ""
|
||||
}
|
||||
|
||||
// CheckControlAvailable returns the current swarm control available
|
||||
func (d *Daemon) CheckControlAvailable(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckControlAvailable(c *testing.T) (interface{}, string) {
|
||||
info := d.SwarmInfo(c)
|
||||
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
||||
return info.ControlAvailable, nil
|
||||
return info.ControlAvailable, ""
|
||||
}
|
||||
|
||||
// CheckLeader returns whether there is a leader on the swarm or not
|
||||
func (d *Daemon) CheckLeader(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func (d *Daemon) CheckLeader(c *testing.T) (interface{}, string) {
|
||||
cli := d.NewClientT(c)
|
||||
defer cli.Close()
|
||||
|
||||
errList := check.Commentf("could not get node list")
|
||||
errList := "could not get node list"
|
||||
|
||||
ls, err := cli.NodeList(context.Background(), types.NodeListOptions{})
|
||||
if err != nil {
|
||||
|
@ -184,10 +184,10 @@ func (d *Daemon) CheckLeader(c *check.C) (interface{}, check.CommentInterface) {
|
|||
|
||||
for _, node := range ls {
|
||||
if node.ManagerStatus != nil && node.ManagerStatus.Leader {
|
||||
return nil, nil
|
||||
return nil, ""
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("no leader"), check.Commentf("could not find leader")
|
||||
return fmt.Errorf("no leader"), "could not find leader"
|
||||
}
|
||||
|
||||
// CmdRetryOutOfSequence tries the specified command against the current daemon
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) getDaemon(c *check.C, nodeID string) *daemon.Daemon {
|
||||
func (s *DockerSwarmSuite) getDaemon(c *testing.T, nodeID string) *daemon.Daemon {
|
||||
s.daemonsLock.Lock()
|
||||
defer s.daemonsLock.Unlock()
|
||||
for _, d := range s.daemons {
|
||||
|
@ -18,6 +19,6 @@ func (s *DockerSwarmSuite) getDaemon(c *check.C, nodeID string) *daemon.Daemon {
|
|||
}
|
||||
|
||||
// nodeCmd executes a command on a given node via the normal docker socket
|
||||
func (s *DockerSwarmSuite) nodeCmd(c *check.C, id string, args ...string) (string, error) {
|
||||
func (s *DockerSwarmSuite) nodeCmd(c *testing.T, id string, args ...string) (string, error) {
|
||||
return s.getDaemon(c, id).Cmd(args...)
|
||||
}
|
||||
|
|
|
@ -10,20 +10,20 @@ import (
|
|||
"net/http"
|
||||
"net/http/httputil"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/go-check/check"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/websocket"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
|
||||
func (s *DockerSuite) TestGetContainersAttachWebsocket(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
|
||||
|
||||
|
@ -76,7 +76,7 @@ func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
|
|||
}
|
||||
|
||||
// regression gh14320
|
||||
func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *testing.T) {
|
||||
resp, _, err := request.Post("/containers/doesnotexist/attach")
|
||||
assert.NilError(c, err)
|
||||
// connection will shutdown, err should be "persistent connection closed"
|
||||
|
@ -87,7 +87,7 @@ func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *check.C) {
|
|||
assert.Equal(c, string(content), expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *testing.T) {
|
||||
res, body, err := request.Get("/containers/doesnotexist/attach/ws")
|
||||
assert.Equal(c, res.StatusCode, http.StatusNotFound)
|
||||
assert.NilError(c, err)
|
||||
|
@ -97,7 +97,7 @@ func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(getErrorMessage(c, b), expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersAttach(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
expectSuccess := func(conn net.Conn, br *bufio.Reader, stream string, tty bool) {
|
||||
|
|
|
@ -11,18 +11,18 @@ import (
|
|||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakegit"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *testing.T) {
|
||||
testRequires(c, NotUserNamespace)
|
||||
|
||||
var testD string
|
||||
|
@ -53,7 +53,7 @@ RUN find /tmp/`
|
|||
assert.Assert(c, !strings.Contains(out, "baz"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *testing.T) {
|
||||
buffer := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buffer)
|
||||
defer tw.Close()
|
||||
|
@ -80,7 +80,7 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
|||
b.Close()
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *testing.T) {
|
||||
buffer := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buffer)
|
||||
defer tw.Close()
|
||||
|
@ -134,7 +134,7 @@ RUN echo 'right'
|
|||
assert.Assert(c, !strings.Contains(string(content), "wrong"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *testing.T) {
|
||||
git := fakegit.New(c, "repo", map[string]string{
|
||||
"dockerfile": `FROM busybox
|
||||
RUN echo from dockerfile`,
|
||||
|
@ -152,7 +152,7 @@ RUN echo from dockerfile`,
|
|||
assert.Assert(c, is.Contains(out, "from dockerfile"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *testing.T) {
|
||||
git := fakegit.New(c, "repo", map[string]string{
|
||||
"baz": `FROM busybox
|
||||
RUN echo from baz`,
|
||||
|
@ -173,7 +173,7 @@ RUN echo from Dockerfile`,
|
|||
assert.Assert(c, is.Contains(out, "from baz"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *testing.T) {
|
||||
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
|
||||
git := fakegit.New(c, "repo", map[string]string{
|
||||
"Dockerfile": `FROM busybox
|
||||
|
@ -195,7 +195,7 @@ RUN echo from dockerfile`,
|
|||
assert.Assert(c, is.Contains(out, "from Dockerfile"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *testing.T) {
|
||||
// Make sure that build context tars with entries of the form
|
||||
// x/./y don't cause caching false positives.
|
||||
|
||||
|
@ -254,7 +254,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
|||
assert.Assert(c, imageA != imageB)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildOnBuildWithCopy(c *testing.T) {
|
||||
dockerfile := `
|
||||
FROM ` + minimalBaseImage() + ` as onbuildbase
|
||||
ONBUILD COPY file /file
|
||||
|
@ -279,7 +279,7 @@ func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
|
|||
assert.Assert(c, is.Contains(string(out), "Successfully built"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildOnBuildCache(c *testing.T) {
|
||||
build := func(dockerfile string) []byte {
|
||||
ctx := fakecontext.New(c, "",
|
||||
fakecontext.WithDockerfile(dockerfile),
|
||||
|
@ -321,7 +321,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
|
|||
assert.Check(c, is.Equal(parentID, image.Parent))
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *testing.T) {
|
||||
client := testEnv.APIClient()
|
||||
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
@ -358,7 +358,7 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) {
|
|||
assert.Check(c, is.Contains(string(out), "Successfully built"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *testing.T) {
|
||||
buffer := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buffer)
|
||||
dt := []byte("contents")
|
||||
|
@ -402,7 +402,7 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) {
|
|||
assert.Check(c, is.Contains(string(out), "Successfully built"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildChownOnCopy(c *testing.T) {
|
||||
// new feature added in 1.31 - https://github.com/moby/moby/pull/34263
|
||||
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31"))
|
||||
dockerfile := `FROM busybox
|
||||
|
@ -432,7 +432,7 @@ func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) {
|
|||
assert.Check(c, is.Contains(string(out), "Successfully built"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildCopyCacheOnFileChange(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildCopyCacheOnFileChange(c *testing.T) {
|
||||
|
||||
dockerfile := `FROM busybox
|
||||
COPY file /file`
|
||||
|
@ -473,7 +473,7 @@ COPY file /file`
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAddCacheOnFileChange(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAddCacheOnFileChange(c *testing.T) {
|
||||
|
||||
dockerfile := `FROM busybox
|
||||
ADD file /file`
|
||||
|
@ -514,7 +514,7 @@ ADD file /file`
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildScratchCopy(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildScratchCopy(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerfile := `FROM scratch
|
||||
ADD Dockerfile /
|
||||
|
@ -543,7 +543,7 @@ type buildLine struct {
|
|||
}
|
||||
}
|
||||
|
||||
func getImageIDsFromBuild(c *check.C, output []byte) []string {
|
||||
func getImageIDsFromBuild(c *testing.T, output []byte) []string {
|
||||
var ids []string
|
||||
for _, line := range bytes.Split(output, []byte("\n")) {
|
||||
if len(line) == 0 {
|
||||
|
|
|
@ -4,15 +4,15 @@ package main
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestBuildWithRecycleBin(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildWithRecycleBin(c *testing.T) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
|
||||
dockerfile := "" +
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -23,7 +23,6 @@ import (
|
|||
networktypes "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
|
@ -32,13 +31,12 @@ import (
|
|||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIGetAll(c *testing.T) {
|
||||
startCount := getContainerCount(c)
|
||||
name := "getall"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
@ -54,11 +52,11 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
assert.Equal(c, len(containers), startCount+1)
|
||||
actual := containers[0].Names[0]
|
||||
c.Assert(actual, checker.Equals, "/"+name)
|
||||
assert.Equal(c, actual, "/"+name)
|
||||
}
|
||||
|
||||
// regression test for empty json field being omitted #13691
|
||||
func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
|
||||
startCount := getContainerCount(c)
|
||||
dockerCmd(c, "run", "busybox", "true")
|
||||
|
||||
|
@ -98,46 +96,7 @@ func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
type containerPs struct {
|
||||
Names []string
|
||||
Ports []types.Port
|
||||
}
|
||||
|
||||
// regression test for non-empty fields from #13901
|
||||
func (s *DockerSuite) TestContainerAPIPsOmitFields(c *check.C) {
|
||||
// Problematic for Windows porting due to networking not yet being passed back
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "pstest"
|
||||
port := 80
|
||||
runSleepingContainer(c, "--name", name, "--expose", strconv.Itoa(port))
|
||||
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
||||
options := types.ContainerListOptions{
|
||||
All: true,
|
||||
}
|
||||
containers, err := cli.ContainerList(context.Background(), options)
|
||||
assert.NilError(c, err)
|
||||
var foundContainer containerPs
|
||||
for _, c := range containers {
|
||||
for _, testName := range c.Names {
|
||||
if "/"+name == testName {
|
||||
foundContainer.Names = c.Names
|
||||
foundContainer.Ports = c.Ports
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.Assert(foundContainer.Ports, checker.HasLen, 1)
|
||||
c.Assert(foundContainer.Ports[0].PrivatePort, checker.Equals, uint16(port))
|
||||
c.Assert(foundContainer.Ports[0].PublicPort, checker.NotNil)
|
||||
c.Assert(foundContainer.Ports[0].IP, checker.NotNil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIGetExport(c *testing.T) {
|
||||
// Not supported on Windows as Windows does not support docker export
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "exportcontainer"
|
||||
|
@ -161,10 +120,10 @@ func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) {
|
|||
break
|
||||
}
|
||||
}
|
||||
c.Assert(found, checker.True, check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIGetChanges(c *testing.T) {
|
||||
// Not supported on Windows as Windows does not support docker diff (/containers/name/changes)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "changescontainer"
|
||||
|
@ -184,10 +143,10 @@ func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) {
|
|||
success = true
|
||||
}
|
||||
}
|
||||
c.Assert(success, checker.True, check.Commentf("/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 *check.C) {
|
||||
func (s *DockerSuite) TestGetContainerStats(c *testing.T) {
|
||||
var (
|
||||
name = "statscontainer"
|
||||
)
|
||||
|
@ -227,7 +186,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
|
||||
func (s *DockerSuite) TestGetContainerStatsRmRunning(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
|
@ -255,12 +214,12 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
|
|||
|
||||
// Now remove without `-f` and make sure we are still pulling stats
|
||||
_, _, err = dockerCmdWithError("rm", id)
|
||||
c.Assert(err, checker.Not(checker.IsNil), check.Commentf("rm should have failed but didn't"))
|
||||
assert.Assert(c, err != nil, "rm should have failed but didn't")
|
||||
_, err = buf.ReadTimeout(b, 2*time.Second)
|
||||
assert.NilError(c, err)
|
||||
|
||||
dockerCmd(c, "rm", "-f", id)
|
||||
c.Assert(<-chErr, checker.IsNil)
|
||||
assert.Assert(c, <-chErr == nil)
|
||||
}
|
||||
|
||||
// ChannelBuffer holds a chan of byte array that can be populate in a goroutine.
|
||||
|
@ -294,7 +253,7 @@ func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
|
|||
// regression test for gh13421
|
||||
// previous test was just checking one stat entry so it didn't fail (stats with
|
||||
// stream false always return one stat)
|
||||
func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
|
||||
func (s *DockerSuite) TestGetContainerStatsStream(c *testing.T) {
|
||||
name := "statscontainer"
|
||||
runSleepingContainer(c, "--name", name)
|
||||
|
||||
|
@ -335,7 +294,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
|
||||
func (s *DockerSuite) TestGetContainerStatsNoStream(c *testing.T) {
|
||||
name := "statscontainer"
|
||||
runSleepingContainer(c, "--name", name)
|
||||
|
||||
|
@ -375,7 +334,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
||||
func (s *DockerSuite) TestGetStoppedContainerStats(c *testing.T) {
|
||||
name := "statscontainer"
|
||||
dockerCmd(c, "create", "--name", name, "busybox", "ps")
|
||||
|
||||
|
@ -401,11 +360,11 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIPause(c *testing.T) {
|
||||
// Problematic on Windows as Windows does not support pause
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
getPaused := func(c *check.C) []string {
|
||||
getPaused := func(c *testing.T) []string {
|
||||
return strings.Fields(cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined())
|
||||
}
|
||||
|
||||
|
@ -429,10 +388,10 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
pausedContainers = getPaused(c)
|
||||
c.Assert(pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
|
||||
assert.Equal(c, len(pausedContainers), 0, "There should be no paused container.")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPITop(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPITop(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top")
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
@ -445,17 +404,17 @@ func (s *DockerSuite) TestContainerAPITop(c *check.C) {
|
|||
// sort by comm[andline] to make sure order stays the same in case of PID rollover
|
||||
top, err := cli.ContainerTop(context.Background(), id, []string{"aux", "--sort=comm"})
|
||||
assert.NilError(c, err)
|
||||
c.Assert(top.Titles, checker.HasLen, 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
|
||||
assert.Equal(c, len(top.Titles), 11, fmt.Sprintf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
|
||||
|
||||
if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" {
|
||||
c.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles)
|
||||
}
|
||||
c.Assert(top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
|
||||
c.Assert(top.Processes[0][10], checker.Equals, "/bin/sh -c top")
|
||||
c.Assert(top.Processes[1][10], checker.Equals, "top")
|
||||
assert.Equal(c, len(top.Processes), 2, fmt.Sprintf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
|
||||
assert.Equal(c, top.Processes[0][10], "/bin/sh -c top")
|
||||
assert.Equal(c, top.Processes[1][10], "top")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPITopWindows(c *testing.T) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
out := runSleepingContainer(c, "-d")
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
@ -486,7 +445,7 @@ func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) {
|
|||
assert.Assert(c, foundProcess, "expected to find %s: %v", expectedProcess, top.Processes)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICommit(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICommit(c *testing.T) {
|
||||
cName := "testapicommit"
|
||||
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
|
||||
|
||||
|
@ -502,13 +461,13 @@ func (s *DockerSuite) TestContainerAPICommit(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
cmd := inspectField(c, img.ID, "Config.Cmd")
|
||||
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
|
||||
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
|
||||
|
||||
// sanity check, make sure the image is what we think it is
|
||||
dockerCmd(c, "run", img.ID, "ls", "/test")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
|
||||
cName := "testapicommitwithconfig"
|
||||
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
|
||||
|
||||
|
@ -528,19 +487,19 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
label1 := inspectFieldMap(c, img.ID, "Config.Labels", "key1")
|
||||
c.Assert(label1, checker.Equals, "value1")
|
||||
assert.Equal(c, label1, "value1")
|
||||
|
||||
label2 := inspectFieldMap(c, img.ID, "Config.Labels", "key2")
|
||||
c.Assert(label2, checker.Equals, "value2")
|
||||
assert.Equal(c, label2, "value2")
|
||||
|
||||
cmd := inspectField(c, img.ID, "Config.Cmd")
|
||||
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
|
||||
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
|
||||
|
||||
// sanity check, make sure the image is what we think it is
|
||||
dockerCmd(c, "run", img.ID, "ls", "/test")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIBadPort(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIBadPort(c *testing.T) {
|
||||
// TODO Windows to Windows CI - Port this test
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -567,7 +526,7 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *check.C) {
|
|||
assert.ErrorContains(c, err, `invalid port specification: "aa80"`)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreate(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreate(c *testing.T) {
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
||||
|
@ -584,7 +543,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "/test")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *testing.T) {
|
||||
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
|
@ -596,7 +555,7 @@ func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *check.C) {
|
|||
assert.ErrorContains(c, err, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T) {
|
||||
// Container creation must fail if client specified configurations for more than one network
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
|
@ -617,26 +576,26 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) {
|
|||
_, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networkingConfig, "")
|
||||
msg := err.Error()
|
||||
// network name order in error message is not deterministic
|
||||
c.Assert(msg, checker.Contains, "Container cannot be connected to network endpoints")
|
||||
c.Assert(msg, checker.Contains, "net1")
|
||||
c.Assert(msg, checker.Contains, "net2")
|
||||
c.Assert(msg, checker.Contains, "net3")
|
||||
assert.Assert(c, strings.Contains(msg, "Container cannot be connected to network endpoints"))
|
||||
assert.Assert(c, strings.Contains(msg, "net1"))
|
||||
assert.Assert(c, strings.Contains(msg, "net2"))
|
||||
assert.Assert(c, strings.Contains(msg, "net3"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateBridgeNetworkMode(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateBridgeNetworkMode(c *testing.T) {
|
||||
// Windows does not support bridge
|
||||
testRequires(c, DaemonIsLinux)
|
||||
UtilCreateNetworkMode(c, "bridge")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateOtherNetworkModes(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateOtherNetworkModes(c *testing.T) {
|
||||
// Windows does not support these network modes
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
UtilCreateNetworkMode(c, "host")
|
||||
UtilCreateNetworkMode(c, "container:web1")
|
||||
}
|
||||
|
||||
func UtilCreateNetworkMode(c *check.C, networkMode containertypes.NetworkMode) {
|
||||
func UtilCreateNetworkMode(c *testing.T, networkMode containertypes.NetworkMode) {
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
}
|
||||
|
@ -655,10 +614,10 @@ func UtilCreateNetworkMode(c *check.C, networkMode containertypes.NetworkMode) {
|
|||
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.NetworkMode, checker.Equals, containertypes.NetworkMode(networkMode), check.Commentf("Mismatched NetworkMode"))
|
||||
assert.Equal(c, containerJSON.HostConfig.NetworkMode, containertypes.NetworkMode(networkMode), "Mismatched NetworkMode")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) {
|
||||
// TODO Windows to Windows CI. The CpuShares part could be ported.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := containertypes.Config{
|
||||
|
@ -686,17 +645,17 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
|
|||
assert.Equal(c, out, "512")
|
||||
|
||||
outCpuset := inspectField(c, containerJSON.ID, "HostConfig.CpusetCpus")
|
||||
c.Assert(outCpuset, checker.Equals, "0")
|
||||
assert.Equal(c, outCpuset, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIVerifyHeader(c *testing.T) {
|
||||
config := map[string]interface{}{
|
||||
"Image": "busybox",
|
||||
}
|
||||
|
||||
create := func(ct string) (*http.Response, io.ReadCloser, error) {
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil)
|
||||
assert.Assert(c, json.NewEncoder(jsonData).Encode(config) == nil)
|
||||
return request.Post("/containers/create", request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType(ct))
|
||||
}
|
||||
|
||||
|
@ -708,7 +667,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
body.Close()
|
||||
|
||||
|
@ -718,7 +677,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
body.Close()
|
||||
|
||||
|
@ -730,7 +689,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
|||
}
|
||||
|
||||
//Issue 14230. daemon should return 500 for invalid port syntax
|
||||
func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *testing.T) {
|
||||
config := `{
|
||||
"Image": "busybox",
|
||||
"HostConfig": {
|
||||
|
@ -748,15 +707,15 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b[:]), checker.Contains, "invalid port")
|
||||
assert.Assert(c, strings.Contains(string(b[:]), "invalid port"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *testing.T) {
|
||||
config := `{
|
||||
"Image": "busybox",
|
||||
"HostConfig": {
|
||||
|
@ -772,15 +731,15 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b[:]), checker.Contains, "invalid restart policy")
|
||||
assert.Assert(c, strings.Contains(string(b[:]), "invalid restart policy"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *testing.T) {
|
||||
config := `{
|
||||
"Image": "busybox",
|
||||
"HostConfig": {
|
||||
|
@ -796,15 +755,15 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b[:]), checker.Contains, "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 *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *testing.T) {
|
||||
config := `{
|
||||
"Image": "busybox",
|
||||
"HostConfig": {
|
||||
|
@ -820,15 +779,15 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be negative")
|
||||
assert.Assert(c, strings.Contains(string(b[:]), "maximum retry count cannot be negative"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *testing.T) {
|
||||
config := `{
|
||||
"Image": "busybox",
|
||||
"HostConfig": {
|
||||
|
@ -846,7 +805,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C)
|
|||
|
||||
// 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"
|
||||
func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIPostCreateNull(c *testing.T) {
|
||||
config := `{
|
||||
"Hostname":"",
|
||||
"Domainname":"",
|
||||
|
@ -880,17 +839,17 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
|
|||
ID string
|
||||
}
|
||||
var container createResp
|
||||
c.Assert(json.Unmarshal(b, &container), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal(b, &container) == nil)
|
||||
out := inspectField(c, container.ID, "HostConfig.CpusetCpus")
|
||||
assert.Equal(c, out, "")
|
||||
|
||||
outMemory := inspectField(c, container.ID, "HostConfig.Memory")
|
||||
c.Assert(outMemory, checker.Equals, "0")
|
||||
assert.Equal(c, outMemory, "0")
|
||||
outMemorySwap := inspectField(c, container.ID, "HostConfig.MemorySwap")
|
||||
c.Assert(outMemorySwap, checker.Equals, "0")
|
||||
assert.Equal(c, outMemorySwap, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *testing.T) {
|
||||
// TODO Windows: Port once memory is supported
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := `{
|
||||
|
@ -904,17 +863,17 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
|||
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
|
||||
assert.NilError(c, err)
|
||||
b, err2 := request.ReadBody(body)
|
||||
c.Assert(err2, checker.IsNil)
|
||||
assert.Assert(c, err2 == nil)
|
||||
|
||||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB")
|
||||
assert.Assert(c, strings.Contains(string(b), "Minimum memory limit allowed is 4MB"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRename(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh")
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -928,10 +887,10 @@ func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
name := inspectField(c, containerID, "Name")
|
||||
c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container"))
|
||||
assert.Equal(c, name, "/"+newName, "Failed to rename container")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIKill(c *testing.T) {
|
||||
name := "test-api-kill"
|
||||
runSleepingContainer(c, "-i", "--name", name)
|
||||
|
||||
|
@ -943,10 +902,10 @@ func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
state := inspectField(c, name, "State.Running")
|
||||
c.Assert(state, checker.Equals, "false", check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestart(c *testing.T) {
|
||||
name := "test-api-restart"
|
||||
runSleepingContainer(c, "-di", "--name", name)
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
|
@ -957,10 +916,10 @@ func (s *DockerSuite) TestContainerAPIRestart(c *check.C) {
|
|||
err = cli.ContainerRestart(context.Background(), name, &timeout)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
|
||||
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
|
||||
name := "test-api-restart-no-timeout-param"
|
||||
out := runSleepingContainer(c, "-di", "--name", name)
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -973,10 +932,10 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) {
|
|||
err = cli.ContainerRestart(context.Background(), name, nil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
|
||||
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIStart(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIStart(c *testing.T) {
|
||||
name := "testing-start"
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
|
@ -1002,7 +961,7 @@ func (s *DockerSuite) TestContainerAPIStart(c *check.C) {
|
|||
// TODO(tibor): figure out why this doesn't work on windows
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIStop(c *testing.T) {
|
||||
name := "test-api-stop"
|
||||
runSleepingContainer(c, "-i", "--name", name)
|
||||
timeout := 30 * time.Second
|
||||
|
@ -1013,7 +972,7 @@ func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
|
|||
|
||||
err = cli.ContainerStop(context.Background(), name, &timeout)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
||||
assert.Assert(c, waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second) == nil)
|
||||
|
||||
// second call to start should give 304
|
||||
// maybe add ContainerStartWithRaw to test it
|
||||
|
@ -1021,7 +980,7 @@ func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIWait(c *testing.T) {
|
||||
name := "test-api-wait"
|
||||
|
||||
sleepCmd := "/bin/sleep"
|
||||
|
@ -1040,11 +999,11 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
|
|||
case err = <-errC:
|
||||
assert.NilError(c, err)
|
||||
case waitres := <-waitresC:
|
||||
c.Assert(waitres.StatusCode, checker.Equals, int64(0))
|
||||
assert.Equal(c, waitres.StatusCode, int64(0))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
|
||||
name := "test-container-api-copy"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
|
||||
|
||||
|
@ -1057,7 +1016,7 @@ func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {
|
|||
assert.Equal(c, res.StatusCode, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICopyPre124(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
|
||||
name := "test-container-api-copy"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
|
||||
|
@ -1084,10 +1043,10 @@ func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) {
|
|||
break
|
||||
}
|
||||
}
|
||||
c.Assert(found, checker.True)
|
||||
assert.Assert(c, found)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
|
||||
name := "test-container-api-copy-resource-empty"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
|
||||
|
@ -1101,14 +1060,15 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *check.C) {
|
|||
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
} else {
|
||||
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
|
||||
assert.Assert(c, res.StatusCode != http.StatusOK)
|
||||
}
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b), checker.Matches, "Path cannot be empty\n")
|
||||
assert.Assert(c, is.Regexp("^Path cannot be empty\n$", string(b)))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
|
||||
name := "test-container-api-copy-resource-not-found"
|
||||
dockerCmd(c, "run", "--name", name, "busybox")
|
||||
|
@ -1126,10 +1086,11 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C)
|
|||
}
|
||||
b, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
|
||||
assert.Assert(c, is.Regexp("^Could not find the file /notexist in container "+name+"\n$", string(b)))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
|
||||
postData := types.CopyConfig{
|
||||
Resource: "/something",
|
||||
|
@ -1140,7 +1101,7 @@ func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *check.C) {
|
|||
assert.Equal(c, res.StatusCode, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDelete(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDelete(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -1156,7 +1117,7 @@ func (s *DockerSuite) TestContainerAPIDelete(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *testing.T) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -1165,7 +1126,7 @@ func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *check.C) {
|
|||
assert.ErrorContains(c, err, "No such container: doesnotexist")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDeleteForce(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteForce(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
@ -1182,7 +1143,7 @@ func (s *DockerSuite) TestContainerAPIDeleteForce(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
|
||||
// Windows does not support links
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
|
||||
|
@ -1193,10 +1154,10 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
|
|||
out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
|
||||
|
||||
id2 := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id2), checker.IsNil)
|
||||
assert.Assert(c, waitRun(id2) == nil)
|
||||
|
||||
links := inspectFieldJSON(c, id2, "HostConfig.Links")
|
||||
c.Assert(links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers"))
|
||||
assert.Equal(c, links, "[\"/tlink1:/tlink2/tlink1\"]", "expected to have links between containers")
|
||||
|
||||
removeOptions := types.ContainerRemoveOptions{
|
||||
RemoveLinks: true,
|
||||
|
@ -1210,10 +1171,10 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
linksPostRm := inspectFieldJSON(c, id2, "HostConfig.Links")
|
||||
c.Assert(linksPostRm, checker.Equals, "null", check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteConflict(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -1228,7 +1189,7 @@ func (s *DockerSuite) TestContainerAPIDeleteConflict(c *check.C) {
|
|||
assert.ErrorContains(c, err, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
|
||||
vol := "/testvolume"
|
||||
|
@ -1259,11 +1220,11 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
_, err = os.Stat(source)
|
||||
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("expected to get ErrNotExist error, got %v", err))
|
||||
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("expected to get ErrNotExist error, got %v", err))
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/docker/docker/issues/6231
|
||||
func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *testing.T) {
|
||||
|
||||
config := map[string]interface{}{
|
||||
"Image": "busybox",
|
||||
|
@ -1278,16 +1239,16 @@ func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
|
|||
req.ContentLength = -1
|
||||
return nil
|
||||
}))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error creating container with chunked encoding"))
|
||||
assert.Assert(c, err == nil, "error creating container with chunked encoding")
|
||||
defer resp.Body.Close()
|
||||
assert.Equal(c, resp.StatusCode, http.StatusCreated)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIPostContainerStop(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(containerID), checker.IsNil)
|
||||
assert.Assert(c, waitRun(containerID) == nil)
|
||||
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
|
@ -1295,11 +1256,11 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
|
|||
|
||||
err = cli.ContainerStop(context.Background(), containerID, nil)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
||||
assert.Assert(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second) == nil)
|
||||
}
|
||||
|
||||
// #14170
|
||||
func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *testing.T) {
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
Entrypoint: []string{"echo"},
|
||||
|
@ -1327,7 +1288,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *c
|
|||
}
|
||||
|
||||
// #14170
|
||||
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T) {
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"echo", "hello", "world"},
|
||||
|
@ -1356,7 +1317,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
|||
// regression #14318
|
||||
// for backward compatibility testing with and without CAP_ prefix
|
||||
// and with upper and lowercase
|
||||
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *testing.T) {
|
||||
// Windows doesn't support CapAdd/CapDrop
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := struct {
|
||||
|
@ -1385,7 +1346,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che
|
|||
}
|
||||
|
||||
// #14915
|
||||
func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only support 1.25 or later
|
||||
config := containertypes.Config{
|
||||
Image: "busybox",
|
||||
|
@ -1401,7 +1362,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) {
|
|||
// 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
|
||||
// directory outside of the volume.
|
||||
func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(c *check.C) {
|
||||
func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(c *testing.T) {
|
||||
// Windows does not support read-only rootfs
|
||||
// Requires local volume mount bind.
|
||||
// --read-only + userns has remount issues
|
||||
|
@ -1427,7 +1388,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
|
|||
assert.ErrorContains(c, err, "container rootfs is marked read-only")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T) {
|
||||
// Not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -1460,7 +1421,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C)
|
|||
assert.ErrorContains(c, err, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) {
|
||||
// ShmSize is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := containertypes.Config{
|
||||
|
@ -1478,7 +1439,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *check.C) {
|
|||
assert.ErrorContains(c, err, "SHM size can not be less than 0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testing.T) {
|
||||
// ShmSize is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
var defaultSHMSize int64 = 67108864
|
||||
|
@ -1497,7 +1458,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
|
|||
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, defaultSHMSize)
|
||||
assert.Equal(c, containerJSON.HostConfig.ShmSize, defaultSHMSize)
|
||||
|
||||
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
|
||||
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
|
||||
|
@ -1506,7 +1467,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) {
|
||||
// ShmSize is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := containertypes.Config{
|
||||
|
@ -1524,7 +1485,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
|
|||
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(67108864))
|
||||
assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(67108864))
|
||||
|
||||
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
|
||||
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
|
||||
|
@ -1533,7 +1494,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) {
|
||||
// ShmSize is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := containertypes.Config{
|
||||
|
@ -1555,7 +1516,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
|
|||
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(1073741824))
|
||||
assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(1073741824))
|
||||
|
||||
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
|
||||
shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`)
|
||||
|
@ -1564,7 +1525,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *testing.T) {
|
||||
// Swappiness is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
config := containertypes.Config{
|
||||
|
@ -1582,14 +1543,14 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
|
|||
assert.NilError(c, err)
|
||||
|
||||
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.31") {
|
||||
c.Assert(*containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1))
|
||||
assert.Equal(c, *containerJSON.HostConfig.MemorySwappiness, int64(-1))
|
||||
} else {
|
||||
c.Assert(containerJSON.HostConfig.MemorySwappiness, check.IsNil)
|
||||
assert.Assert(c, containerJSON.HostConfig.MemorySwappiness == nil)
|
||||
}
|
||||
}
|
||||
|
||||
// check validation is done daemon side and not only in cli
|
||||
func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *check.C) {
|
||||
func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *testing.T) {
|
||||
// OomScoreAdj is not supported on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -1623,7 +1584,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che
|
|||
}
|
||||
|
||||
// test case for #22210 where an empty container name caused panic.
|
||||
func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -1632,7 +1593,7 @@ func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *check.C) {
|
|||
assert.ErrorContains(c, err, "No such container")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) {
|
||||
// Problematic on Windows as Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -1654,7 +1615,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
|||
err = cli.ContainerStart(context.Background(), name, types.ContainerStartOptions{})
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
type b struct {
|
||||
stats types.ContainerStats
|
||||
|
@ -1676,12 +1637,12 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
|||
case <-time.After(2 * time.Second):
|
||||
c.Fatal("stream was not closed after container was removed")
|
||||
case sr := <-bc:
|
||||
c.Assert(sr.err, checker.IsNil)
|
||||
assert.Assert(c, sr.err == nil)
|
||||
sr.stats.Body.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) {
|
||||
type testCase struct {
|
||||
config containertypes.Config
|
||||
hostConfig containertypes.HostConfig
|
||||
|
@ -1972,7 +1933,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
|
||||
testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon)
|
||||
// also with data in the host side
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
|
@ -2003,7 +1964,7 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *check.C) {
|
|||
}
|
||||
|
||||
// Test Mounts comes out as expected for the MountPoint
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) {
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
destPath := prefix + slash + "foo"
|
||||
|
||||
|
@ -2092,7 +2053,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
defer os.RemoveAll(tmpDir3)
|
||||
|
||||
c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
|
||||
assert.Assert(c, mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared") == nil)
|
||||
|
||||
cases = append(cases, []testCase{
|
||||
{
|
||||
|
@ -2217,7 +2178,7 @@ func containerExit(apiclient client.APIClient, name string) func(poll.LogT) poll
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
type testCase struct {
|
||||
cfg mounttypes.Mount
|
||||
|
@ -2259,7 +2220,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
out, _ := dockerCmd(c, "start", "-a", cName)
|
||||
for _, option := range x.expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2267,7 +2228,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
|||
// Regression test for #33334
|
||||
// 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.
|
||||
func (s *DockerSuite) TestContainerKillCustomStopSignal(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerKillCustomStopSignal(c *testing.T) {
|
||||
id := strings.TrimSpace(runSleepingContainer(c, "--stop-signal=SIGTERM", "--restart=always"))
|
||||
res, _, err := request.Post("/containers/" + id + "/kill")
|
||||
assert.NilError(c, err)
|
||||
|
|
|
@ -8,17 +8,17 @@ import (
|
|||
"io/ioutil"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *check.C) {
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsWindowsAtLeastBuild(16299)) // Named pipe support was added in RS3
|
||||
|
||||
// Create a host pipe to map into the container
|
||||
|
|
|
@ -8,14 +8,14 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) {
|
||||
func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -31,7 +31,7 @@ func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) {
|
|||
}
|
||||
|
||||
// Part of #14845
|
||||
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
||||
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
|
||||
name := "exec_resize_test"
|
||||
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -16,12 +17,12 @@ import (
|
|||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
// Regression test for #9414
|
||||
func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPICreateNoCmd(c *testing.T) {
|
||||
name := "exec_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
|
||||
|
@ -37,7 +38,7 @@ func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) {
|
|||
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 *check.C) {
|
||||
func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *testing.T) {
|
||||
name := "exec_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
|
||||
|
@ -58,7 +59,7 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(getErrorMessage(c, b), "Content-Type specified"), "Expected message when creating exec command with invalid Content-Type specified")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecAPICreateContainerPaused(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPICreateContainerPaused(c *testing.T) {
|
||||
// Not relevant on Windows as Windows containers cannot be paused
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "exec_create_test"
|
||||
|
@ -77,7 +78,7 @@ func (s *DockerSuite) TestExecAPICreateContainerPaused(c *check.C) {
|
|||
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 *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStart(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI
|
||||
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
||||
|
||||
|
@ -104,7 +105,7 @@ func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|||
startExec(c, id, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
||||
|
||||
|
@ -114,7 +115,7 @@ func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *check.C) {
|
|||
assert.Assert(c, resp.Header.Get("Server") != "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
|
||||
runSleepingContainer(c, "-d", "--name", "test")
|
||||
id := createExec(c, "test")
|
||||
|
@ -123,13 +124,13 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
comment := check.Commentf("response body: %s", b)
|
||||
comment := fmt.Sprintf("response body: %s", b)
|
||||
assert.NilError(c, err, comment)
|
||||
assert.Equal(c, resp.StatusCode, http.StatusOK, comment)
|
||||
}
|
||||
|
||||
// #19362
|
||||
func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *testing.T) {
|
||||
runSleepingContainer(c, "-d", "--name", "test")
|
||||
execID := createExec(c, "test")
|
||||
startExec(c, execID, http.StatusOK)
|
||||
|
@ -139,7 +140,7 @@ func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *check.C) {
|
|||
}
|
||||
|
||||
// #20638
|
||||
func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartWithDetach(c *testing.T) {
|
||||
name := "foo"
|
||||
runSleepingContainer(c, "-d", "-t", "--name", name)
|
||||
|
||||
|
@ -159,7 +160,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
b, err := request.ReadBody(body)
|
||||
comment := check.Commentf("response body: %s", b)
|
||||
comment := fmt.Sprintf("response body: %s", b)
|
||||
assert.NilError(c, err, comment)
|
||||
|
||||
resp, _, err := request.Get("/_ping")
|
||||
|
@ -170,7 +171,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
|||
}
|
||||
|
||||
// #30311
|
||||
func (s *DockerSuite) TestExecAPIStartValidCommand(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartValidCommand(c *testing.T) {
|
||||
name := "exec_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
|
||||
|
@ -186,7 +187,7 @@ func (s *DockerSuite) TestExecAPIStartValidCommand(c *check.C) {
|
|||
}
|
||||
|
||||
// #30311
|
||||
func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *testing.T) {
|
||||
name := "exec_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
|
||||
|
@ -204,7 +205,7 @@ func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *check.C) {
|
|||
assert.Assert(c, inspectJSON.ExecIDs == nil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecStateCleanup(c *check.C) {
|
||||
func (s *DockerSuite) TestExecStateCleanup(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
|
||||
// This test checks accidental regressions. Not part of stable API.
|
||||
|
@ -215,10 +216,10 @@ func (s *DockerSuite) TestExecStateCleanup(c *check.C) {
|
|||
|
||||
stateDir := "/var/run/docker/containerd/" + cid
|
||||
|
||||
checkReadDir := func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
checkReadDir := func(c *testing.T) (interface{}, string) {
|
||||
fi, err := ioutil.ReadDir(stateDir)
|
||||
assert.NilError(c, err)
|
||||
return len(fi), nil
|
||||
return len(fi), ""
|
||||
}
|
||||
|
||||
fi, err := ioutil.ReadDir(stateDir)
|
||||
|
@ -229,13 +230,13 @@ func (s *DockerSuite) TestExecStateCleanup(c *check.C) {
|
|||
startExec(c, id, http.StatusOK)
|
||||
waitForExec(c, id)
|
||||
|
||||
waitAndAssert(c, 5*time.Second, checkReadDir, checker.Equals, len(fi))
|
||||
poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
|
||||
|
||||
id = createExecCmd(c, name, "invalid")
|
||||
startExec(c, id, http.StatusBadRequest)
|
||||
waitForExec(c, id)
|
||||
|
||||
waitAndAssert(c, 5*time.Second, checkReadDir, checker.Equals, len(fi))
|
||||
poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
|
||||
|
||||
dockerCmd(c, "stop", name)
|
||||
_, err = os.Stat(stateDir)
|
||||
|
@ -243,11 +244,11 @@ func (s *DockerSuite) TestExecStateCleanup(c *check.C) {
|
|||
assert.Assert(c, os.IsNotExist(err))
|
||||
}
|
||||
|
||||
func createExec(c *check.C, name string) string {
|
||||
func createExec(c *testing.T, name string) string {
|
||||
return createExecCmd(c, name, "true")
|
||||
}
|
||||
|
||||
func createExecCmd(c *check.C, name string, cmd string) string {
|
||||
func createExecCmd(c *testing.T, name string, cmd string) string {
|
||||
_, reader, err := request.Post(fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}}))
|
||||
assert.NilError(c, err)
|
||||
b, err := ioutil.ReadAll(reader)
|
||||
|
@ -260,7 +261,7 @@ func createExecCmd(c *check.C, name string, cmd string) string {
|
|||
return createResp.ID
|
||||
}
|
||||
|
||||
func startExec(c *check.C, id string, code int) {
|
||||
func startExec(c *testing.T, id string, code int) {
|
||||
resp, body, err := request.Post(fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -269,7 +270,7 @@ func startExec(c *check.C, id string, code int) {
|
|||
assert.Equal(c, resp.StatusCode, code, "response body: %s", b)
|
||||
}
|
||||
|
||||
func inspectExec(c *check.C, id string, out interface{}) {
|
||||
func inspectExec(c *testing.T, id string, out interface{}) {
|
||||
resp, body, err := request.Get(fmt.Sprintf("/exec/%s/json", id))
|
||||
assert.NilError(c, err)
|
||||
defer body.Close()
|
||||
|
@ -278,7 +279,7 @@ func inspectExec(c *check.C, id string, out interface{}) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func waitForExec(c *check.C, id string) {
|
||||
func waitForExec(c *testing.T, id string) {
|
||||
timeout := time.After(60 * time.Second)
|
||||
var execJSON struct{ Running bool }
|
||||
for {
|
||||
|
@ -295,7 +296,7 @@ func waitForExec(c *check.C, id string) {
|
|||
}
|
||||
}
|
||||
|
||||
func inspectContainer(c *check.C, id string, out interface{}) {
|
||||
func inspectContainer(c *testing.T, id string, out interface{}) {
|
||||
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/json", id))
|
||||
assert.NilError(c, err)
|
||||
defer body.Close()
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
@ -15,11 +16,10 @@ import (
|
|||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestAPIImagesFilter(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesFilter(c *testing.T) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -57,7 +57,7 @@ func (s *DockerSuite) TestAPIImagesFilter(c *check.C) {
|
|||
assert.Equal(c, len(images[0].RepoTags), 1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
v, err := kernel.GetKernelVersion()
|
||||
assert.NilError(c, err)
|
||||
|
@ -87,7 +87,7 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(string(inspectOut)), id, "load did not work properly")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesDelete(c *testing.T) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -111,7 +111,7 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesHistory(c *testing.T) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -137,7 +137,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
|||
assert.Assert(c, found)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIImagesImportBadSrc(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesImportBadSrc(c *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
v, err := kernel.GetKernelVersion()
|
||||
assert.NilError(c, err)
|
||||
|
@ -172,7 +172,7 @@ func (s *DockerSuite) TestAPIImagesImportBadSrc(c *check.C) {
|
|||
}
|
||||
|
||||
// #14846
|
||||
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
|
||||
res, b, err := request.Get("/images/search?term=test", request.JSON)
|
||||
|
@ -184,7 +184,7 @@ func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
|||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *testing.T) {
|
||||
apiclient := testEnv.APIClient()
|
||||
defer apiclient.Close()
|
||||
|
||||
|
|
|
@ -4,16 +4,16 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions/v1p20"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIContainerResponse(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIContainerResponse(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -57,7 +57,7 @@ func (s *DockerSuite) TestInspectAPIContainerResponse(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
|
||||
// No legacy implications for Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
@ -80,7 +80,7 @@ func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -104,7 +104,7 @@ func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *check.C) {
|
|||
assert.Assert(c, ok, "API version 1.25 expected to include VolumeDriver in 'HostConfig'")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIImageResponse(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIImageResponse(c *testing.T) {
|
||||
dockerCmd(c, "tag", "busybox:latest", "busybox:mytag")
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
|
@ -119,7 +119,7 @@ func (s *DockerSuite) TestInspectAPIImageResponse(c *check.C) {
|
|||
}
|
||||
|
||||
// #17131, #17139, #17173
|
||||
func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
|
||||
// Not relevant on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
@ -143,7 +143,7 @@ func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
|
||||
// Not relevant on Windows, and besides it doesn't have any bridge network settings
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
|
@ -160,7 +160,7 @@ func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *check.C) {
|
|||
assert.Assert(c, len(settings.IPAddress) != 0)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings121(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) {
|
||||
// Windows doesn't have any bridge network settings
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
|
|
|
@ -10,17 +10,17 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIWithStdout(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done")
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
@ -56,7 +56,7 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
|
||||
name := "logs_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
|
@ -68,7 +68,7 @@ func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *check.C) {
|
|||
}
|
||||
|
||||
// Regression test for #12704
|
||||
func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *testing.T) {
|
||||
name := "logs_test"
|
||||
t0 := time.Now()
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
|
||||
|
@ -83,14 +83,14 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *testing.T) {
|
||||
name := "nonExistentContainer"
|
||||
resp, _, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, resp.StatusCode, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "logsuntilfuturefollow"
|
||||
dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done")
|
||||
|
@ -147,7 +147,7 @@ func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsAPIUntil(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIUntil(c *testing.T) {
|
||||
testRequires(c, MinimumAPIVersion("1.34"))
|
||||
name := "logsuntil"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")
|
||||
|
@ -157,7 +157,7 @@ func (s *DockerSuite) TestLogsAPIUntil(c *check.C) {
|
|||
c.Fatal(err)
|
||||
}
|
||||
|
||||
extractBody := func(c *check.C, cfg types.ContainerLogsOptions) []string {
|
||||
extractBody := func(c *testing.T, cfg types.ContainerLogsOptions) []string {
|
||||
reader, err := client.ContainerLogs(context.Background(), name, cfg)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -185,7 +185,7 @@ func (s *DockerSuite) TestLogsAPIUntil(c *check.C) {
|
|||
assert.Assert(c, !strings.Contains(logsString, "log3"), "unexpected log message returned, until=%v", until)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsAPIUntilDefaultValue(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsAPIUntilDefaultValue(c *testing.T) {
|
||||
name := "logsuntildefaultval"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done")
|
||||
|
||||
|
@ -194,7 +194,7 @@ func (s *DockerSuite) TestLogsAPIUntilDefaultValue(c *check.C) {
|
|||
c.Fatal(err)
|
||||
}
|
||||
|
||||
extractBody := func(c *check.C, cfg types.ContainerLogsOptions) []string {
|
||||
extractBody := func(c *testing.T, cfg types.ContainerLogsOptions) []string {
|
||||
reader, err := client.ContainerLogs(context.Background(), name, cfg)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
|
|
@ -7,17 +7,17 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkGetDefaults(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkGetDefaults(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// By default docker daemon creates 3 networks. check if they are present
|
||||
defaults := []string{"bridge", "host", "none"}
|
||||
|
@ -26,7 +26,7 @@ func (s *DockerSuite) TestAPINetworkGetDefaults(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testcheckduplicate"
|
||||
configOnCheck := types.NetworkCreateRequest{
|
||||
|
@ -64,13 +64,13 @@ func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *check.C) {
|
|||
createNetwork(c, configNotCheck, http.StatusCreated)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkFilter(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkFilter(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
nr := getNetworkResource(c, getNetworkIDByName(c, "bridge"))
|
||||
assert.Equal(c, nr.Name, "bridge")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkInspectBridge(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkInspectBridge(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// Inspect default bridge network
|
||||
nr := getNetworkResource(c, "bridge")
|
||||
|
@ -96,7 +96,7 @@ func (s *DockerSuite) TestAPINetworkInspectBridge(c *check.C) {
|
|||
assert.Equal(c, ip.String(), containerIP)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkInspectUserDefinedNetwork(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkInspectUserDefinedNetwork(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// IPAM configuration inspect
|
||||
ipam := &network.IPAM{
|
||||
|
@ -127,7 +127,7 @@ func (s *DockerSuite) TestAPINetworkInspectUserDefinedNetwork(c *check.C) {
|
|||
assert.Assert(c, !isNetworkAvailable(c, "br0"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// Create test network
|
||||
name := "testnetwork"
|
||||
|
@ -169,7 +169,7 @@ func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *check.C) {
|
|||
deleteNetwork(c, nr.ID, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *check.C) {
|
||||
func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// test0 bridge network
|
||||
ipam0 := &network.IPAM{
|
||||
|
@ -238,14 +238,14 @@ func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPICreateDeletePredefinedNetworks(c *check.C) {
|
||||
func (s *DockerSuite) TestAPICreateDeletePredefinedNetworks(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, SwarmInactive)
|
||||
createDeletePredefinedNetwork(c, "bridge")
|
||||
createDeletePredefinedNetwork(c, "none")
|
||||
createDeletePredefinedNetwork(c, "host")
|
||||
}
|
||||
|
||||
func createDeletePredefinedNetwork(c *check.C, name string) {
|
||||
func createDeletePredefinedNetwork(c *testing.T, name string) {
|
||||
// Create pre-defined network
|
||||
config := types.NetworkCreateRequest{
|
||||
Name: name,
|
||||
|
@ -267,7 +267,7 @@ func createDeletePredefinedNetwork(c *check.C, name string) {
|
|||
deleteNetwork(c, name, false)
|
||||
}
|
||||
|
||||
func isNetworkAvailable(c *check.C, name string) bool {
|
||||
func isNetworkAvailable(c *testing.T, name string) bool {
|
||||
resp, body, err := request.Get("/networks")
|
||||
assert.NilError(c, err)
|
||||
defer resp.Body.Close()
|
||||
|
@ -285,7 +285,7 @@ func isNetworkAvailable(c *check.C, name string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func getNetworkIDByName(c *check.C, name string) string {
|
||||
func getNetworkIDByName(c *testing.T, name string) string {
|
||||
var (
|
||||
v = url.Values{}
|
||||
filterArgs = filters.NewArgs()
|
||||
|
@ -314,7 +314,7 @@ func getNetworkIDByName(c *check.C, name string) string {
|
|||
return res
|
||||
}
|
||||
|
||||
func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
||||
func getNetworkResource(c *testing.T, id string) *types.NetworkResource {
|
||||
_, obj, err := request.Get("/networks/" + id)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -325,7 +325,7 @@ func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
|||
return &nr
|
||||
}
|
||||
|
||||
func createNetwork(c *check.C, config types.NetworkCreateRequest, expectedStatusCode int) string {
|
||||
func createNetwork(c *testing.T, config types.NetworkCreateRequest, expectedStatusCode int) string {
|
||||
resp, body, err := request.Post("/networks/create", request.JSONBody(config))
|
||||
assert.NilError(c, err)
|
||||
defer resp.Body.Close()
|
||||
|
@ -346,7 +346,7 @@ func createNetwork(c *check.C, config types.NetworkCreateRequest, expectedStatus
|
|||
return ""
|
||||
}
|
||||
|
||||
func connectNetwork(c *check.C, nid, cid string) {
|
||||
func connectNetwork(c *testing.T, nid, cid string) {
|
||||
config := types.NetworkConnect{
|
||||
Container: cid,
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ func connectNetwork(c *check.C, nid, cid string) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func disconnectNetwork(c *check.C, nid, cid string) {
|
||||
func disconnectNetwork(c *testing.T, nid, cid string) {
|
||||
config := types.NetworkConnect{
|
||||
Container: cid,
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ func disconnectNetwork(c *check.C, nid, cid string) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func deleteNetwork(c *check.C, id string, shouldSucceed bool) {
|
||||
func deleteNetwork(c *testing.T, id string, shouldSucceed bool) {
|
||||
resp, _, err := request.Delete("/networks/" + id)
|
||||
assert.NilError(c, err)
|
||||
defer resp.Body.Close()
|
||||
|
|
|
@ -10,19 +10,19 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
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 *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done")
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -62,7 +62,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *check.C) {
|
|||
assert.Assert(c, cpuPercent != 0.0, "docker stats with no-stream get cpu usage failed: was %v", cpuPercent)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
|
@ -97,7 +97,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIStatsNetworkStats(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsNetworkStats(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
|
||||
out := runSleepingContainer(c)
|
||||
|
@ -162,7 +162,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStats(c *check.C) {
|
|||
assert.Assert(c, postRxPackets >= expRxPkts, "Reported less RxPackets than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) {
|
||||
// Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
|
@ -187,7 +187,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *check.C) {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
||||
func getNetworkStats(c *testing.T, id string) map[string]types.NetworkStats {
|
||||
var st *types.StatsJSON
|
||||
|
||||
_, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
||||
|
@ -204,7 +204,7 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
|||
// container with id using an API call with version apiVersion. Since the
|
||||
// stats result type differs between API versions, we simply return
|
||||
// map[string]interface{}.
|
||||
func getVersionedStats(c *check.C, id string, apiVersion string) map[string]interface{} {
|
||||
func getVersionedStats(c *testing.T, id string, apiVersion string) map[string]interface{} {
|
||||
stats := make(map[string]interface{})
|
||||
|
||||
_, body, err := request.Get(fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id))
|
||||
|
@ -257,7 +257,7 @@ func jsonBlobHasGTE121NetworkStats(blob map[string]interface{}) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIStatsContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsContainerNotFound(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
|
@ -271,7 +271,7 @@ func (s *DockerSuite) TestAPIStatsContainerNotFound(c *check.C) {
|
|||
assert.ErrorContains(c, err, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
out1 := runSleepingContainer(c)
|
||||
|
|
|
@ -3,21 +3,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
d3 := s.AddDaemon(c, true, false)
|
||||
|
||||
nodes := d1.ListNodes(c)
|
||||
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
||||
assert.Equal(c, len(nodes), 3, fmt.Sprintf("nodes: %#v", nodes))
|
||||
|
||||
loop0:
|
||||
for _, n := range nodes {
|
||||
|
@ -30,7 +33,7 @@ loop0:
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
nodes := d.ListNodes(c)
|
||||
|
@ -40,17 +43,17 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) {
|
|||
})
|
||||
|
||||
n := d.GetNode(c, nodes[0].ID)
|
||||
c.Assert(n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause)
|
||||
assert.Equal(c, n.Spec.Availability, swarm.NodeAvailabilityPause)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
_ = s.AddDaemon(c, true, false)
|
||||
|
||||
nodes := d1.ListNodes(c)
|
||||
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
||||
assert.Equal(c, len(nodes), 3, fmt.Sprintf("nodes: %#v", nodes))
|
||||
|
||||
// Getting the info so we can take the NodeID
|
||||
d2Info := d2.SwarmInfo(c)
|
||||
|
@ -59,7 +62,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
|
|||
d1.RemoveNode(c, d2Info.NodeID, true)
|
||||
|
||||
nodes = d1.ListNodes(c)
|
||||
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
||||
assert.Equal(c, len(nodes), 2, fmt.Sprintf("nodes: %#v", nodes))
|
||||
|
||||
// Restart the node that was removed
|
||||
d2.RestartNode(c)
|
||||
|
@ -69,10 +72,10 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
|
|||
|
||||
// Make sure the node didn't rejoin
|
||||
nodes = d1.ListNodes(c)
|
||||
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
||||
assert.Equal(c, len(nodes), 2, fmt.Sprintf("nodes: %#v", nodes))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
|
||||
|
@ -82,16 +85,16 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
|||
instances := 2
|
||||
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// drain d2, all containers should move to d1
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
||||
})
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// set d2 back to active
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
|
@ -100,15 +103,15 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
|||
|
||||
instances = 1
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout*2))
|
||||
|
||||
instances = 2
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
|
||||
// drained node first so we don't get any old containers
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout*2))
|
||||
|
||||
d2ContainerCount := len(d2.ActiveContainers(c))
|
||||
|
||||
|
@ -119,7 +122,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
|||
|
||||
instances = 4
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances-d2ContainerCount)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, d2ContainerCount)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances-d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -16,10 +17,10 @@ import (
|
|||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/go-check/check"
|
||||
"golang.org/x/sys/unix"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func setPortConfig(portConfig []swarm.PortConfig) testdaemon.ServiceConstructor {
|
||||
|
@ -31,13 +32,13 @@ func setPortConfig(portConfig []swarm.PortConfig) testdaemon.ServiceConstructor
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
// Create a service with a port mapping of 8080:8081.
|
||||
portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
|
||||
serviceID := d.CreateService(c, simpleTestService, setInstances(1), setPortConfig(portConfig))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Update the service: changed the port mapping from 8080:8081 to 8082:8083.
|
||||
updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
|
||||
|
@ -52,7 +53,7 @@ func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *check.C) {
|
|||
assert.Equal(c, updatedService.Spec.EndpointSpec.Ports[0].PublishedPort, uint32(8082))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesEmptyList(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesEmptyList(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
services := d.ListServices(c)
|
||||
|
@ -60,12 +61,12 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesEmptyList(c *check.C) {
|
|||
assert.Assert(c, len(services) == 0, "services: %#v", services)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
client := d.NewClientT(c)
|
||||
defer client.Close()
|
||||
|
@ -87,13 +88,13 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *check.C) {
|
|||
service := d.GetService(c, id)
|
||||
instances = 5
|
||||
d.UpdateService(c, service, setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d.RemoveService(c, service.ID)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
d3 := s.AddDaemon(c, true, false)
|
||||
|
@ -103,50 +104,50 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *check.C) {
|
|||
instances := 9
|
||||
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d3.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// reconciliation on d2 node down
|
||||
d2.Stop(c)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// test downscaling
|
||||
instances = 5
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesCreateGlobal(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesCreateGlobal(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
d3 := s.AddDaemon(c, true, false)
|
||||
|
||||
d1.CreateService(c, simpleTestService, setGlobalMode)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d3.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d4 := s.AddDaemon(c, true, false)
|
||||
d5 := s.AddDaemon(c, true, false)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d4.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d5.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d4.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d5.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
|
||||
const nodeCount = 3
|
||||
var daemons [nodeCount]*daemon.Daemon
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
daemons[i] = s.AddDaemon(c, true, i == 0)
|
||||
}
|
||||
// wait for nodes ready
|
||||
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
|
||||
|
||||
// service image at start
|
||||
image1 := "busybox:latest"
|
||||
|
@ -166,24 +167,20 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *check.C) {
|
|||
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
service := daemons[0].GetService(c, id)
|
||||
daemons[0].UpdateService(c, service, setImage(image2))
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 3nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Roll back to the previous version. This uses the CLI because
|
||||
// rollback used to be a client-side operation.
|
||||
|
@ -191,15 +188,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *check.C) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
// service image at start
|
||||
|
@ -223,7 +219,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
|||
|
||||
checkStartingTasks := func(expected int) []swarm.Task {
|
||||
var startingTasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks := d.GetServiceTasks(c, id)
|
||||
startingTasks = nil
|
||||
for _, t := range tasks {
|
||||
|
@ -231,8 +227,8 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
|||
startingTasks = append(startingTasks, t)
|
||||
}
|
||||
}
|
||||
return startingTasks, nil
|
||||
}, checker.HasLen, expected)
|
||||
return startingTasks, ""
|
||||
}, checker.HasLen(expected)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
return startingTasks
|
||||
}
|
||||
|
@ -245,8 +241,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
|||
}
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
service := d.GetService(c, id)
|
||||
|
@ -257,42 +252,36 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
|||
// The old tasks should be running, and the new ones should be starting.
|
||||
startingTasks := checkStartingTasks(parallelism)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
|
||||
// The old tasks should be running, and the new ones should be starting.
|
||||
startingTasks = checkStartingTasks(parallelism)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 3nd batch
|
||||
|
||||
// The old tasks should be running, and the new ones should be starting.
|
||||
startingTasks = checkStartingTasks(1)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Roll back to the previous version. This uses the CLI because
|
||||
// rollback is a client-side operation.
|
||||
|
@ -300,22 +289,21 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
|
||||
const nodeCount = 3
|
||||
var daemons [nodeCount]*daemon.Daemon
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
daemons[i] = s.AddDaemon(c, true, i == 0)
|
||||
}
|
||||
// wait for nodes ready
|
||||
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
|
||||
|
||||
// service image at start
|
||||
image1 := "busybox:latest"
|
||||
|
@ -327,15 +315,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *check.C) {
|
|||
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
service := daemons[0].GetService(c, id)
|
||||
daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1))
|
||||
|
||||
// should update 2 tasks and then pause
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceUpdateState(id), checker.Equals, swarm.UpdateStatePaused)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceUpdateState(id), checker.Equals(swarm.UpdateStatePaused)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
v, _ := daemons[0].CheckServiceRunningTasks(id)(c)
|
||||
assert.Assert(c, v == instances-2)
|
||||
|
||||
|
@ -344,25 +331,25 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *check.C) {
|
|||
out, err := daemons[0].Cmd("service", "update", "--detach", "--rollback", id)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
|
||||
const nodeCount = 3
|
||||
var daemons [nodeCount]*daemon.Daemon
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
daemons[i] = s.AddDaemon(c, true, i == 0)
|
||||
}
|
||||
// wait for nodes ready
|
||||
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
|
||||
|
||||
// create service
|
||||
constraints := []string{"node.role==worker"}
|
||||
instances := 3
|
||||
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// validate tasks are running on worker nodes
|
||||
tasks := daemons[0].GetServiceTasks(c, id)
|
||||
for _, task := range tasks {
|
||||
|
@ -376,7 +363,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) {
|
|||
constraints = []string{"node.role!=worker"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
// validate tasks are running on manager nodes
|
||||
for _, task := range tasks {
|
||||
|
@ -390,7 +377,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) {
|
|||
constraints = []string{"node.role==nosuchrole"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks created
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// let scheduler try
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
// validate tasks are not assigned to any node
|
||||
|
@ -400,14 +387,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
|
||||
const nodeCount = 3
|
||||
var daemons [nodeCount]*daemon.Daemon
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
daemons[i] = s.AddDaemon(c, true, i == 0)
|
||||
}
|
||||
// wait for nodes ready
|
||||
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
|
||||
nodes := daemons[0].ListNodes(c)
|
||||
assert.Equal(c, len(nodes), nodeCount)
|
||||
|
||||
|
@ -430,7 +417,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
|||
constraints := []string{"node.labels.security==high"}
|
||||
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
tasks := daemons[0].GetServiceTasks(c, id)
|
||||
// validate all tasks are running on nodes[0]
|
||||
for _, task := range tasks {
|
||||
|
@ -443,7 +430,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
|||
constraints = []string{"node.labels.security!=high"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
// validate all tasks are NOT running on nodes[0]
|
||||
for _, task := range tasks {
|
||||
|
@ -455,7 +442,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
|||
constraints = []string{"node.labels.security==medium"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks created
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// let scheduler try
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
|
@ -473,7 +460,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
|||
}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// wait for tasks created
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// let scheduler try
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
|
@ -488,21 +475,21 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
|||
}
|
||||
})
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
for _, task := range tasks {
|
||||
assert.Assert(c, task.NodeID == nodes[1].ID)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *testing.T) {
|
||||
const nodeCount = 3
|
||||
var daemons [nodeCount]*daemon.Daemon
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
daemons[i] = s.AddDaemon(c, true, i == 0)
|
||||
}
|
||||
// wait for nodes ready
|
||||
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
|
||||
nodes := daemons[0].ListNodes(c)
|
||||
assert.Equal(c, len(nodes), nodeCount)
|
||||
|
||||
|
@ -525,7 +512,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *check.C) {
|
|||
prefs := []swarm.PlacementPreference{{Spread: &swarm.SpreadOver{SpreadDescriptor: "node.labels.rack"}}}
|
||||
id := daemons[0].CreateService(c, simpleTestService, setPlacementPrefs(prefs), setInstances(instances))
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
tasks := daemons[0].GetServiceTasks(c, id)
|
||||
// validate all tasks are running on nodes[0]
|
||||
tasksOnNode := make(map[string]int)
|
||||
|
@ -537,7 +524,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *check.C) {
|
|||
assert.Assert(c, tasksOnNode[nodes[2].ID] == 1)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -550,7 +537,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) {
|
|||
instances := 9
|
||||
d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
getContainers := func() map[string]*daemon.Daemon {
|
||||
m := make(map[string]*daemon.Daemon)
|
||||
|
@ -572,7 +559,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) {
|
|||
_, err := containers[toRemove].Cmd("stop", toRemove)
|
||||
assert.NilError(c, err)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containers2 := getContainers()
|
||||
assert.Assert(c, len(containers2) == instances)
|
||||
|
@ -598,7 +585,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) {
|
|||
|
||||
time.Sleep(time.Second) // give some time to handle the signal
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containers2 = getContainers()
|
||||
assert.Assert(c, len(containers2) == instances)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudflare/cfssl/csr"
|
||||
|
@ -26,15 +27,15 @@ import (
|
|||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/docker/swarmkit/ca"
|
||||
"github.com/go-check/check"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
var defaultReconciliationTimeout = 30 * time.Second
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmInit(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmInit(c *testing.T) {
|
||||
// todo: should find a better way to verify that components are running than /info
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
info := d1.SwarmInfo(c)
|
||||
|
@ -80,7 +81,7 @@ func (s *DockerSwarmSuite) TestAPISwarmInit(c *check.C) {
|
|||
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, false, false)
|
||||
d1.SwarmInit(c, swarm.InitRequest{})
|
||||
|
||||
|
@ -158,7 +159,7 @@ func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *check.C) {
|
|||
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestUpdateSwarmAddExternalCA(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestUpdateSwarmAddExternalCA(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, false, false)
|
||||
d1.SwarmInit(c, swarm.InitRequest{})
|
||||
d1.UpdateSwarm(c, func(s *swarm.Spec) {
|
||||
|
@ -180,7 +181,7 @@ func (s *DockerSwarmSuite) TestUpdateSwarmAddExternalCA(c *check.C) {
|
|||
assert.Equal(c, info.Cluster.Spec.CAConfig.ExternalCAs[1].CACert, "cacert")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, false, false)
|
||||
splitToken := strings.Split(d1.JoinTokens(c).Worker, "-")
|
||||
|
@ -195,7 +196,7 @@ func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *check.C) {
|
|||
assert.ErrorContains(c, err, "remote CA does not match fingerprint")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, false, false)
|
||||
d1.SwarmInit(c, swarm.InitRequest{})
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
|
@ -208,13 +209,13 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
|||
n.Spec.Role = swarm.NodeRoleManager
|
||||
})
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
n.Spec.Role = swarm.NodeRoleWorker
|
||||
})
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.False)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.False()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Wait for the role to change to worker in the cert. This is partially
|
||||
// done because it's something worth testing in its own right, and
|
||||
|
@ -222,17 +223,17 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
|||
// back to manager quickly might cause the node to pause for awhile
|
||||
// while waiting for the role to change to worker, and the test can
|
||||
// time out during this interval.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
certBytes, err := ioutil.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
|
||||
if err != nil {
|
||||
return "", check.Commentf("error: %v", err)
|
||||
return "", fmt.Sprintf("error: %v", err)
|
||||
}
|
||||
certs, err := helpers.ParseCertificatesPEM(certBytes)
|
||||
if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
|
||||
return certs[0].Subject.OrganizationalUnit[0], nil
|
||||
return certs[0].Subject.OrganizationalUnit[0], ""
|
||||
}
|
||||
return "", check.Commentf("could not get organizational unit from certificate")
|
||||
}, checker.Equals, "swarm-worker")
|
||||
return "", "could not get organizational unit from certificate"
|
||||
}, checker.Equals("swarm-worker")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Demoting last node should fail
|
||||
node := d1.GetNode(c, d1.NodeID())
|
||||
|
@ -262,10 +263,10 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
|||
n.Spec.Role = swarm.NodeRoleManager
|
||||
})
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *testing.T) {
|
||||
// add three managers, one of these is leader
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, true)
|
||||
|
@ -290,7 +291,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
|
||||
if runtime.GOARCH == "s390x" {
|
||||
c.Skip("Disabled on s390x")
|
||||
}
|
||||
|
@ -316,7 +317,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
|||
)
|
||||
var lastErr error
|
||||
checkLeader := func(nodes ...*daemon.Daemon) checkF {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
// clear these out before each run
|
||||
leader = nil
|
||||
followers = nil
|
||||
|
@ -329,7 +330,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
|||
return false
|
||||
})
|
||||
if n == nil {
|
||||
return false, check.Commentf("failed to get node: %v", lastErr)
|
||||
return false, fmt.Sprintf("failed to get node: %v", lastErr)
|
||||
}
|
||||
if n.ManagerStatus.Leader {
|
||||
leader = d
|
||||
|
@ -339,16 +340,16 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
|||
}
|
||||
|
||||
if leader == nil {
|
||||
return false, check.Commentf("no leader elected")
|
||||
return false, "no leader elected"
|
||||
}
|
||||
|
||||
return true, check.Commentf("elected %v", leader.ID())
|
||||
return true, fmt.Sprintf("elected %v", leader.ID())
|
||||
}
|
||||
}
|
||||
|
||||
// wait for an election to occur
|
||||
c.Logf("Waiting for election to occur...")
|
||||
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d2, d3), checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, checkLeader(d2, d3), checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// assert that we have a new leader
|
||||
assert.Assert(c, leader != nil)
|
||||
|
@ -361,7 +362,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
|||
|
||||
// wait for possible election
|
||||
c.Logf("Waiting for possible election...")
|
||||
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d1, d2, d3), checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, checkLeader(d1, d2, d3), checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// pick out the leader and the followers again
|
||||
|
||||
// verify that we still only have 1 leader and 2 followers
|
||||
|
@ -371,7 +372,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
|||
assert.Equal(c, leader.NodeID(), stableleader.NodeID())
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) {
|
||||
if runtime.GOARCH == "s390x" {
|
||||
c.Skip("Disabled on s390x")
|
||||
}
|
||||
|
@ -388,7 +389,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
|
|||
d2.Stop(c)
|
||||
|
||||
// make sure there is a leader
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckLeader, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
||||
s.Spec.Name = "top1"
|
||||
|
@ -403,22 +404,22 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
|
|||
defer cli.Close()
|
||||
|
||||
// d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen
|
||||
waitAndAssert(c, defaultReconciliationTimeout*2, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
_, err := cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{})
|
||||
return err.Error(), nil
|
||||
}, checker.Contains, "Make sure more than half of the managers are online.")
|
||||
return err.Error(), ""
|
||||
}, checker.Contains("Make sure more than half of the managers are online.")), poll.WithTimeout(defaultReconciliationTimeout*2))
|
||||
|
||||
d2.StartNode(c)
|
||||
|
||||
// make sure there is a leader
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckLeader, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
||||
s.Spec.Name = "top3"
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
|
@ -428,12 +429,12 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) {
|
|||
assert.NilError(c, err, id)
|
||||
id = strings.TrimSpace(id)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances+1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances+1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
assert.ErrorContains(c, d.SwarmLeave(c, false), "")
|
||||
assert.NilError(c, d.SwarmLeave(c, true))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
id2, err := d.Cmd("ps", "-q")
|
||||
assert.NilError(c, err, id2)
|
||||
|
@ -441,7 +442,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) {
|
|||
}
|
||||
|
||||
// #23629
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, false, false)
|
||||
|
@ -462,7 +463,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) {
|
|||
|
||||
assert.NilError(c, d2.SwarmLeave(c, true))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
id2, err := d2.Cmd("ps", "-q")
|
||||
assert.NilError(c, err, id2)
|
||||
|
@ -470,7 +471,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) {
|
|||
}
|
||||
|
||||
// #23705
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
d := s.AddDaemon(c, false, false)
|
||||
client := d.NewClientT(c)
|
||||
|
@ -480,7 +481,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) {
|
|||
})
|
||||
assert.ErrorContains(c, err, "Timeout was reached")
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStatePending)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStatePending)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d.RestartNode(c)
|
||||
|
||||
|
@ -488,7 +489,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) {
|
|||
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
|
@ -515,17 +516,17 @@ func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *check.C) {
|
|||
d3.GetService(c, id)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
containers := d.ActiveContainers(c)
|
||||
instances = 4
|
||||
d.UpdateService(c, d.GetService(c, id), setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
containers2 := d.ActiveContainers(c)
|
||||
|
||||
loop0:
|
||||
|
@ -539,7 +540,7 @@ loop0:
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *testing.T) {
|
||||
d := s.AddDaemon(c, false, false)
|
||||
req := swarm.InitRequest{
|
||||
ListenAddr: "",
|
||||
|
@ -557,20 +558,20 @@ func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
|||
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// drain d2, all containers should move to d1
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
||||
})
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d2.Stop(c)
|
||||
|
||||
|
@ -579,7 +580,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|
|||
Spec: swarm.Spec{},
|
||||
})
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d3 := s.AddDaemon(c, true, true)
|
||||
info := d3.SwarmInfo(c)
|
||||
|
@ -589,7 +590,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|
|||
instances = 4
|
||||
d3.UpdateService(c, d3.GetService(c, id), setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
func simpleTestService(s *swarm.Service) {
|
||||
|
@ -728,7 +729,7 @@ func setGlobalMode(s *swarm.Service) {
|
|||
}
|
||||
}
|
||||
|
||||
func checkClusterHealth(c *check.C, cl []*daemon.Daemon, managerCount, workerCount int) {
|
||||
func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerCount int) {
|
||||
var totalMCount, totalWCount int
|
||||
|
||||
for _, d := range cl {
|
||||
|
@ -737,13 +738,13 @@ func checkClusterHealth(c *check.C, cl []*daemon.Daemon, managerCount, workerCou
|
|||
)
|
||||
|
||||
// check info in a waitAndAssert, because if the cluster doesn't have a leader, `info` will return an error
|
||||
checkInfo := func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
checkInfo := func(c *testing.T) (interface{}, string) {
|
||||
client := d.NewClientT(c)
|
||||
daemonInfo, err := client.Info(context.Background())
|
||||
info = daemonInfo.Swarm
|
||||
return err, check.Commentf("cluster not ready in time")
|
||||
return err, "cluster not ready in time"
|
||||
}
|
||||
waitAndAssert(c, defaultReconciliationTimeout, checkInfo, checker.IsNil)
|
||||
poll.WaitOn(c, pollCheck(c, checkInfo, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
if !info.ControlAvailable {
|
||||
totalWCount++
|
||||
continue
|
||||
|
@ -754,25 +755,25 @@ func checkClusterHealth(c *check.C, cl []*daemon.Daemon, managerCount, workerCou
|
|||
var mCount, wCount int
|
||||
|
||||
for _, n := range d.ListNodes(c) {
|
||||
waitReady := func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
waitReady := func(c *testing.T) (interface{}, string) {
|
||||
if n.Status.State == swarm.NodeStateReady {
|
||||
return true, nil
|
||||
return true, ""
|
||||
}
|
||||
nn := d.GetNode(c, n.ID)
|
||||
n = *nn
|
||||
return n.Status.State == swarm.NodeStateReady, check.Commentf("state of node %s, reported by %s", n.ID, d.NodeID())
|
||||
return n.Status.State == swarm.NodeStateReady, fmt.Sprintf("state of node %s, reported by %s", n.ID, d.NodeID())
|
||||
}
|
||||
waitAndAssert(c, defaultReconciliationTimeout, waitReady, checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, waitReady, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
waitActive := func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
waitActive := func(c *testing.T) (interface{}, string) {
|
||||
if n.Spec.Availability == swarm.NodeAvailabilityActive {
|
||||
return true, nil
|
||||
return true, ""
|
||||
}
|
||||
nn := d.GetNode(c, n.ID)
|
||||
n = *nn
|
||||
return n.Spec.Availability == swarm.NodeAvailabilityActive, check.Commentf("availability of node %s, reported by %s", n.ID, d.NodeID())
|
||||
return n.Spec.Availability == swarm.NodeAvailabilityActive, fmt.Sprintf("availability of node %s, reported by %s", n.ID, d.NodeID())
|
||||
}
|
||||
waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True)
|
||||
poll.WaitOn(c, pollCheck(c, waitActive, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
if n.Spec.Role == swarm.NodeRoleManager {
|
||||
assert.Assert(c, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID())
|
||||
|
@ -793,7 +794,7 @@ func checkClusterHealth(c *check.C, cl []*daemon.Daemon, managerCount, workerCou
|
|||
assert.Equal(c, totalWCount, workerCount)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *testing.T) {
|
||||
mCount, wCount := 5, 1
|
||||
|
||||
var nodes []*daemon.Daemon
|
||||
|
@ -858,12 +859,12 @@ func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) {
|
|||
checkClusterHealth(c, nodes, mCount, wCount)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
instances := 2
|
||||
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
service := d.GetService(c, id)
|
||||
instances = 5
|
||||
|
@ -873,18 +874,18 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) {
|
|||
defer cli.Close()
|
||||
_, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
|
||||
assert.NilError(c, err)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
// Unlocking an unlocked swarm results in an error
|
||||
func (s *DockerSwarmSuite) TestAPISwarmUnlockNotLocked(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmUnlockNotLocked(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
err := d.SwarmUnlock(c, swarm.UnlockRequest{UnlockKey: "wrong-key"})
|
||||
assert.ErrorContains(c, err, "swarm is not locked")
|
||||
}
|
||||
|
||||
// #29885
|
||||
func (s *DockerSwarmSuite) TestAPISwarmErrorHandling(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmErrorHandling(c *testing.T) {
|
||||
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", defaultSwarmPort))
|
||||
assert.NilError(c, err)
|
||||
defer ln.Close()
|
||||
|
@ -899,7 +900,7 @@ func (s *DockerSwarmSuite) TestAPISwarmErrorHandling(c *check.C) {
|
|||
// Test case for 30242, where duplicate networks, with different drivers `bridge` and `overlay`,
|
||||
// caused both scopes to be `swarm` for `docker network inspect` and `docker network ls`.
|
||||
// This test makes sure the fixes correctly output scopes instead.
|
||||
func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
cli := d.NewClientT(c)
|
||||
defer cli.Close()
|
||||
|
@ -929,7 +930,7 @@ func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
|
|||
}
|
||||
|
||||
// Test case for 30178
|
||||
func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *testing.T) {
|
||||
// Issue #36386 can be a independent one, which is worth further investigation.
|
||||
c.Skip("Root cause of Issue #36386 is needed")
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
@ -948,7 +949,7 @@ func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
|
|||
}
|
||||
})
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containers := d.ActiveContainers(c)
|
||||
|
||||
|
@ -956,7 +957,7 @@ func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *testing.T) {
|
||||
m := s.AddDaemon(c, true, true)
|
||||
w := s.AddDaemon(c, true, false)
|
||||
|
||||
|
@ -1025,7 +1026,7 @@ func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "test-scoped-network"
|
||||
|
|
|
@ -7,21 +7,21 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestAPIOptionsRoute(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIOptionsRoute(c *testing.T) {
|
||||
resp, _, err := request.Do("/", request.Method(http.MethodOptions))
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIGetEnabledCORS(c *testing.T) {
|
||||
res, body, err := request.Get("/version")
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
@ -33,7 +33,7 @@ func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
|
|||
//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 *check.C) {
|
||||
func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *testing.T) {
|
||||
if testEnv.OSType != runtime.GOOS {
|
||||
c.Skip("Daemon platform doesn't match test platform")
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(string(content)), expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIErrorJSON(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIErrorJSON(c *testing.T) {
|
||||
httpResp, body, err := request.Post("/containers/create", request.JSONBody(struct{}{}))
|
||||
assert.NilError(c, err)
|
||||
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
|
||||
|
@ -71,7 +71,7 @@ func (s *DockerSuite) TestAPIErrorJSON(c *check.C) {
|
|||
assert.Equal(c, getErrorMessage(c, b), "Config cannot be empty in order to create a container")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIErrorPlainText(c *testing.T) {
|
||||
// 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
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -88,7 +88,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(string(b)), "Config cannot be empty in order to create a container")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *testing.T) {
|
||||
// 404 is a different code path to normal errors, so test separately
|
||||
httpResp, body, err := request.Get("/notfound", request.JSON)
|
||||
assert.NilError(c, err)
|
||||
|
@ -99,7 +99,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
|
|||
assert.Equal(c, getErrorMessage(c, b), "page not found")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *check.C) {
|
||||
func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *testing.T) {
|
||||
httpResp, body, err := request.Get("/v1.23/notfound", request.JSON)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, httpResp.StatusCode, http.StatusNotFound)
|
||||
|
|
|
@ -8,17 +8,17 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
const attachWait = 5 * time.Second
|
||||
|
||||
func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachMultipleAndRestart(c *testing.T) {
|
||||
endGroup := &sync.WaitGroup{}
|
||||
startGroup := &sync.WaitGroup{}
|
||||
endGroup.Add(3)
|
||||
|
@ -88,7 +88,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachTTYWithoutStdin(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
||||
// TODO @jhowardmsft. 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.
|
||||
// On Windows, docker run -d -ti busybox causes the container to exit immediately.
|
||||
|
@ -133,7 +133,7 @@ func (s *DockerSuite) TestAttachTTYWithoutStdin(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachDisconnect(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -147,7 +147,7 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
|||
stdout, err := cmd.StdoutPipe()
|
||||
assert.NilError(c, err)
|
||||
defer stdout.Close()
|
||||
c.Assert(cmd.Start(), check.IsNil)
|
||||
assert.Assert(c, cmd.Start() == nil)
|
||||
defer func() {
|
||||
cmd.Process.Kill()
|
||||
cmd.Wait()
|
||||
|
@ -157,16 +157,16 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
out, err = bufio.NewReader(stdout).ReadString('\n')
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
|
||||
assert.Equal(c, strings.TrimSpace(out), "hello")
|
||||
|
||||
c.Assert(stdin.Close(), check.IsNil)
|
||||
assert.Assert(c, stdin.Close() == nil)
|
||||
|
||||
// Expect container to still be running after stdin is closed
|
||||
running := inspectField(c, id, "State.Running")
|
||||
c.Assert(running, check.Equals, "true")
|
||||
assert.Equal(c, running, "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachPausedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachPausedContainer(c *testing.T) {
|
||||
testRequires(c, IsPausable)
|
||||
runSleepingContainer(c, "-d", "--name=test")
|
||||
dockerCmd(c, "pause", "test")
|
||||
|
|
|
@ -4,18 +4,19 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// #9860 Make sure attach ends when container ends (with no errors)
|
||||
func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`)
|
||||
|
@ -51,14 +52,14 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
|
|||
case err := <-errChan:
|
||||
tty.Close()
|
||||
out, _ := ioutil.ReadAll(pty)
|
||||
c.Assert(err, check.IsNil, check.Commentf("out: %v", string(out)))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", string(out)))
|
||||
case <-time.After(attachWait):
|
||||
c.Fatal("timed out without attach returning")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachAfterDetach(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachAfterDetach(c *testing.T) {
|
||||
name := "detachtest"
|
||||
|
||||
cpty, tty, err := pty.Open()
|
||||
|
@ -74,7 +75,7 @@ func (s *DockerSuite) TestAttachAfterDetach(c *check.C) {
|
|||
close(cmdExit)
|
||||
}()
|
||||
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
cpty.Write([]byte{16})
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
@ -123,7 +124,7 @@ func (s *DockerSuite) TestAttachAfterDetach(c *check.C) {
|
|||
}
|
||||
|
||||
// TestAttachDetach checks that attach in tty mode can be detached using the long container ID
|
||||
func (s *DockerSuite) TestAttachDetach(c *check.C) {
|
||||
func (s *DockerSuite) TestAttachDetach(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat")
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,19 +13,18 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *testing.T) {
|
||||
testRequires(c, cpuCfsQuota)
|
||||
name := "testbuildresourceconstraints"
|
||||
buildLabel := "DockerSuite.TestBuildResourceConstraintsAreUsed"
|
||||
|
@ -56,16 +55,16 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|||
|
||||
var c1 hostConfig
|
||||
err := json.Unmarshal([]byte(cfg), &c1)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(cfg))
|
||||
assert.Assert(c, err == nil, cfg)
|
||||
|
||||
c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
|
||||
c.Assert(c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap"))
|
||||
c.Assert(c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus"))
|
||||
c.Assert(c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems"))
|
||||
c.Assert(c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares"))
|
||||
c.Assert(c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota"))
|
||||
c.Assert(c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits"))
|
||||
c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
|
||||
assert.Equal(c, c1.Memory, int64(64*1024*1024), "resource constraints not set properly for Memory")
|
||||
assert.Equal(c, c1.MemorySwap, int64(-1), "resource constraints not set properly for MemorySwap")
|
||||
assert.Equal(c, c1.CpusetCpus, "0", "resource constraints not set properly for CpusetCpus")
|
||||
assert.Equal(c, c1.CpusetMems, "0", "resource constraints not set properly for CpusetMems")
|
||||
assert.Equal(c, c1.CPUShares, int64(100), "resource constraints not set properly for CPUShares")
|
||||
assert.Equal(c, c1.CPUQuota, int64(8000), "resource constraints not set properly for CPUQuota")
|
||||
assert.Equal(c, c1.Ulimits[0].Name, "nofile", "resource constraints not set properly for Ulimits")
|
||||
assert.Equal(c, c1.Ulimits[0].Hard, int64(42), "resource constraints not set properly for Ulimits")
|
||||
|
||||
// Make sure constraints aren't saved to image
|
||||
cli.DockerCmd(c, "run", "--name=test", name)
|
||||
|
@ -74,18 +73,18 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|||
|
||||
var c2 hostConfig
|
||||
err = json.Unmarshal([]byte(cfg), &c2)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(cfg))
|
||||
assert.Assert(c, err == nil, cfg)
|
||||
|
||||
c.Assert(c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory"))
|
||||
c.Assert(c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap"))
|
||||
c.Assert(c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus"))
|
||||
c.Assert(c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems"))
|
||||
c.Assert(c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares"))
|
||||
c.Assert(c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota"))
|
||||
c.Assert(c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits"))
|
||||
assert.Assert(c, c2.Memory != int64(64*1024*1024), "resource leaked from build for Memory")
|
||||
assert.Assert(c, c2.MemorySwap != int64(-1), "resource leaked from build for MemorySwap")
|
||||
assert.Assert(c, c2.CpusetCpus != "0", "resource leaked from build for CpusetCpus")
|
||||
assert.Assert(c, c2.CpusetMems != "0", "resource leaked from build for CpusetMems")
|
||||
assert.Assert(c, c2.CPUShares != int64(100), "resource leaked from build for CPUShares")
|
||||
assert.Assert(c, c2.CPUQuota != int64(8000), "resource leaked from build for CPUQuota")
|
||||
assert.Assert(c, c2.Ulimits == nil, "resource leaked from build for Ulimits")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildAddChangeOwnership(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testbuildaddown"
|
||||
|
||||
|
@ -131,7 +130,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
|
|||
// TODO(buildkit): this test needs to be rewritten for buildkit.
|
||||
// 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.
|
||||
func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildCancellationKillsSleep(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, TODOBuildkit)
|
||||
name := "testbuildcancellation"
|
||||
|
||||
|
|
|
@ -7,14 +7,13 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution/manifest/schema1"
|
||||
"github.com/docker/distribution/manifest/schema2"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
|
@ -27,11 +26,11 @@ var (
|
|||
digestRegex = regexp.MustCompile("Digest: ([\\S]+)")
|
||||
)
|
||||
|
||||
func setupImage(c *check.C) (digest.Digest, error) {
|
||||
func setupImage(c *testing.T) (digest.Digest, error) {
|
||||
return setupImageWithTag(c, "latest")
|
||||
}
|
||||
|
||||
func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
||||
func setupImageWithTag(c *testing.T, tag string) (digest.Digest, error) {
|
||||
containerName := "busyboxbydigest"
|
||||
|
||||
// new file is committed because this layer is used for detecting malicious
|
||||
|
@ -59,7 +58,7 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
|||
return digest.Digest(pushDigest), nil
|
||||
}
|
||||
|
||||
func testPullByTagDisplaysDigest(c *check.C) {
|
||||
func testPullByTagDisplaysDigest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
@ -73,18 +72,18 @@ func testPullByTagDisplaysDigest(c *check.C) {
|
|||
pullDigest := matches[1]
|
||||
|
||||
// make sure the pushed and pull digests match
|
||||
c.Assert(pushDigest.String(), checker.Equals, pullDigest)
|
||||
assert.Equal(c, pushDigest.String(), pullDigest)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *testing.T) {
|
||||
testPullByTagDisplaysDigest(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByTagDisplaysDigest(c *testing.T) {
|
||||
testPullByTagDisplaysDigest(c)
|
||||
}
|
||||
|
||||
func testPullByDigest(c *check.C) {
|
||||
func testPullByDigest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
@ -99,35 +98,35 @@ func testPullByDigest(c *check.C) {
|
|||
pullDigest := matches[1]
|
||||
|
||||
// make sure the pushed and pull digests match
|
||||
c.Assert(pushDigest.String(), checker.Equals, pullDigest)
|
||||
assert.Equal(c, pushDigest.String(), pullDigest)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullByDigest(c *testing.T) {
|
||||
testPullByDigest(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByDigest(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByDigest(c *testing.T) {
|
||||
testPullByDigest(c)
|
||||
}
|
||||
|
||||
func testPullByDigestNoFallback(c *check.C) {
|
||||
func testPullByDigestNoFallback(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// pull from the registry using the <name>@<digest> reference
|
||||
imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName)
|
||||
out, _, err := dockerCmdWithError("pull", imageReference)
|
||||
c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("manifest for %s not found", imageReference), check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
|
||||
assert.Assert(c, err != nil, "expected non-zero exit status and correct error message when pulling non-existing image")
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("manifest for %s not found", imageReference)), "expected non-zero exit status and correct error message when pulling non-existing image")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *testing.T) {
|
||||
testPullByDigestNoFallback(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByDigestNoFallback(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullByDigestNoFallback(c *testing.T) {
|
||||
testPullByDigestNoFallback(c)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestCreateByDigest(c *testing.T) {
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -140,7 +139,7 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
|
|||
assert.Equal(c, res, imageReference)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) {
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -151,14 +150,14 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
|
|||
|
||||
foundRegex := regexp.MustCompile("found=([^\n]+)")
|
||||
matches := foundRegex.FindStringSubmatch(out)
|
||||
c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
|
||||
c.Assert(matches[1], checker.Equals, "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
|
||||
assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out))
|
||||
assert.Equal(c, matches[1], "1", fmt.Sprintf("Expected %q, got %q", "1", matches[1]))
|
||||
|
||||
res := inspectField(c, containerName, "Config.Image")
|
||||
assert.Equal(c, res, imageReference)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *testing.T) {
|
||||
digest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -180,7 +179,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
|
|||
assert.ErrorContains(c, err, "No such object")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestBuildByDigest(c *testing.T) {
|
||||
digest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -205,7 +204,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
|||
assert.Equal(c, res, imageID)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestTagByDigest(c *testing.T) {
|
||||
digest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -224,7 +223,7 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
|
|||
assert.Equal(c, tagID, expectedID)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *testing.T) {
|
||||
digest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -234,10 +233,10 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
|
|||
dockerCmd(c, "pull", imageReference)
|
||||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
c.Assert(out, checker.Not(checker.Contains), "DIGEST", check.Commentf("list output should not have contained DIGEST header"))
|
||||
assert.Assert(c, !strings.Contains(out, "DIGEST"), "list output should not have contained DIGEST header")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
|
||||
|
||||
// setup image1
|
||||
digest1, err := setupImageWithTag(c, "tag1")
|
||||
|
@ -253,7 +252,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
|||
|
||||
// make sure repo shown, tag=<none>, digest = $digest1
|
||||
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
|
||||
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
||||
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
|
||||
// setup image2
|
||||
digest2, err := setupImageWithTag(c, "tag2")
|
||||
//error setting up image
|
||||
|
@ -271,11 +270,11 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
|||
out, _ = dockerCmd(c, "images", "--digests")
|
||||
|
||||
// make sure repo shown, tag=<none>, digest = $digest1
|
||||
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
||||
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
|
||||
|
||||
// make sure repo shown, tag=<none>, digest = $digest2
|
||||
re2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`)
|
||||
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
||||
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
|
||||
|
||||
// pull tag1
|
||||
dockerCmd(c, "pull", repoName+":tag1")
|
||||
|
@ -285,9 +284,9 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
|||
|
||||
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
|
||||
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`)
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
|
||||
// make sure image 2 has repo, <none>, digest
|
||||
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
||||
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
|
||||
|
||||
// pull tag 2
|
||||
dockerCmd(c, "pull", repoName+":tag2")
|
||||
|
@ -296,25 +295,25 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
|||
out, _ = dockerCmd(c, "images", "--digests")
|
||||
|
||||
// make sure image 1 has repo, tag, digest
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
|
||||
|
||||
// make sure image 2 has repo, tag, digest
|
||||
reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*tag2\s*` + digest2.String() + `\s`)
|
||||
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
|
||||
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
|
||||
|
||||
// list images
|
||||
out, _ = dockerCmd(c, "images", "--digests")
|
||||
|
||||
// make sure image 1 has repo, tag, digest
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
|
||||
// make sure image 2 has repo, tag, digest
|
||||
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
|
||||
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
|
||||
// make sure busybox has tag, but not digest
|
||||
busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*<none>\s`)
|
||||
c.Assert(busyboxRe.MatchString(out), checker.True, check.Commentf("expected %q: %s", busyboxRe.String(), out))
|
||||
assert.Assert(c, busyboxRe.MatchString(out), fmt.Sprintf("expected %q: %s", busyboxRe.String(), out))
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
|
||||
// setup image1
|
||||
digest1, err := setupImageWithTag(c, "dangle1")
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
@ -329,7 +328,7 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
|
|||
|
||||
// make sure repo shown, tag=<none>, digest = $digest1
|
||||
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
|
||||
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
||||
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
|
||||
// setup image2
|
||||
digest2, err := setupImageWithTag(c, "dangle2")
|
||||
//error setting up image
|
||||
|
@ -347,11 +346,11 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
|
|||
out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
|
||||
|
||||
// make sure repo shown, tag=<none>, digest = $digest1
|
||||
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
||||
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
|
||||
|
||||
// make sure repo shown, tag=<none>, digest = $digest2
|
||||
re2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`)
|
||||
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
||||
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
|
||||
|
||||
// pull dangle1 tag
|
||||
dockerCmd(c, "pull", repoName+":dangle1")
|
||||
|
@ -361,9 +360,9 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
|
|||
|
||||
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
|
||||
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`)
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, !reWithDigest1.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest1.String(), out))
|
||||
// make sure image 2 has repo, <none>, digest
|
||||
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
||||
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
|
||||
|
||||
// pull dangle2 tag
|
||||
dockerCmd(c, "pull", repoName+":dangle2")
|
||||
|
@ -372,24 +371,24 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
|
|||
out, _ = dockerCmd(c, "images", "--digests")
|
||||
|
||||
// make sure image 1 has repo, tag, digest
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
|
||||
|
||||
// make sure image 2 has repo, tag, digest
|
||||
reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*dangle2\s*` + digest2.String() + `\s`)
|
||||
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
|
||||
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
|
||||
|
||||
// list images, no longer dangling, should not match
|
||||
out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
|
||||
|
||||
// make sure image 1 has repo, tag, digest
|
||||
c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
|
||||
assert.Assert(c, !reWithDigest1.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest1.String(), out))
|
||||
// make sure image 2 has repo, tag, digest
|
||||
c.Assert(reWithDigest2.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest2.String(), out))
|
||||
assert.Assert(c, !reWithDigest2.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest2.String(), out))
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
|
||||
digest, err := setupImage(c)
|
||||
c.Assert(err, check.IsNil, check.Commentf("error setting up image"))
|
||||
assert.Assert(c, err == nil, "error setting up image")
|
||||
|
||||
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
||||
|
||||
|
@ -401,12 +400,12 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
|
|||
var imageJSON []types.ImageInspect
|
||||
err = json.Unmarshal([]byte(out), &imageJSON)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(imageJSON, checker.HasLen, 1)
|
||||
c.Assert(imageJSON[0].RepoDigests, checker.HasLen, 1)
|
||||
assert.Equal(c, len(imageJSON), 1)
|
||||
assert.Equal(c, len(imageJSON[0].RepoDigests), 1)
|
||||
assert.Check(c, is.Contains(imageJSON[0].RepoDigests, imageReference))
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *testing.T) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
||||
digest, err := setupImage(c)
|
||||
|
@ -442,7 +441,7 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c
|
|||
checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageReference, expectedIDs)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *testing.T) {
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -461,7 +460,7 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C)
|
|||
assert.ErrorContains(c, err, "", "image should have been deleted")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *testing.T) {
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -488,7 +487,7 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *check.C) {
|
|||
assert.ErrorContains(c, err, "", "image should have been deleted")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *testing.T) {
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
||||
|
@ -525,7 +524,7 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *check.
|
|||
// TestPullFailsWithAlteredManifest tests that a `docker pull` fails when
|
||||
// we have modified a manifest blob and its digest cannot be verified.
|
||||
// This is the schema2 version of the test.
|
||||
func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
manifestDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
@ -556,7 +555,7 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
|||
// Pull from the registry using the <name>@<digest> reference.
|
||||
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
||||
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
||||
c.Assert(exitStatus, checker.Not(check.Equals), 0)
|
||||
assert.Assert(c, exitStatus != 0)
|
||||
|
||||
expectedErrorMsg := fmt.Sprintf("manifest verification failed for digest %s", manifestDigest)
|
||||
assert.Assert(c, is.Contains(out, expectedErrorMsg))
|
||||
|
@ -565,17 +564,17 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
|||
// TestPullFailsWithAlteredManifest tests that a `docker pull` fails when
|
||||
// we have modified a manifest blob and its digest cannot be verified.
|
||||
// This is the schema1 version of the test.
|
||||
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
manifestDigest, err := setupImage(c)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
||||
assert.Assert(c, err == nil, "error setting up image")
|
||||
|
||||
// Load the target manifest blob.
|
||||
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
|
||||
|
||||
var imgManifest schema1.Manifest
|
||||
err = json.Unmarshal(manifestBlob, &imgManifest)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("unable to decode image manifest from blob"))
|
||||
assert.Assert(c, err == nil, "unable to decode image manifest from blob")
|
||||
|
||||
// Change a layer in the manifest.
|
||||
imgManifest.FSLayers[0] = schema1.FSLayer{
|
||||
|
@ -588,7 +587,7 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C
|
|||
defer undo()
|
||||
|
||||
alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON"))
|
||||
assert.Assert(c, err == nil, "unable to encode altered image manifest to JSON")
|
||||
|
||||
s.reg.WriteBlobContents(c, manifestDigest, alteredManifestBlob)
|
||||
|
||||
|
@ -598,26 +597,26 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C
|
|||
// Pull from the registry using the <name>@<digest> reference.
|
||||
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
||||
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
||||
c.Assert(exitStatus, checker.Not(check.Equals), 0)
|
||||
assert.Assert(c, exitStatus != 0)
|
||||
|
||||
expectedErrorMsg := fmt.Sprintf("image verification failed for digest %s", manifestDigest)
|
||||
c.Assert(out, checker.Contains, expectedErrorMsg)
|
||||
assert.Assert(c, strings.Contains(out, expectedErrorMsg))
|
||||
}
|
||||
|
||||
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when
|
||||
// we have modified a layer blob and its digest cannot be verified.
|
||||
// This is the schema2 version of the test.
|
||||
func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
manifestDigest, err := setupImage(c)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.Assert(c, err == nil)
|
||||
|
||||
// Load the target manifest blob.
|
||||
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
|
||||
|
||||
var imgManifest schema2.Manifest
|
||||
err = json.Unmarshal(manifestBlob, &imgManifest)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.Assert(c, err == nil)
|
||||
|
||||
// Next, get the digest of one of the layers from the manifest.
|
||||
targetLayerDigest := imgManifest.Layers[0].Digest
|
||||
|
@ -641,26 +640,26 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
|||
// Pull from the registry using the <name>@<digest> reference.
|
||||
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
||||
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
||||
c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
|
||||
assert.Assert(c, exitStatus != 0, "expected a non-zero exit status")
|
||||
|
||||
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
|
||||
c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
|
||||
assert.Assert(c, strings.Contains(out, expectedErrorMsg), fmt.Sprintf("expected error message in output: %s", out))
|
||||
}
|
||||
|
||||
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when
|
||||
// we have modified a layer blob and its digest cannot be verified.
|
||||
// This is the schema1 version of the test.
|
||||
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
manifestDigest, err := setupImage(c)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.Assert(c, err == nil)
|
||||
|
||||
// Load the target manifest blob.
|
||||
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
|
||||
|
||||
var imgManifest schema1.Manifest
|
||||
err = json.Unmarshal(manifestBlob, &imgManifest)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.Assert(c, err == nil)
|
||||
|
||||
// Next, get the digest of one of the layers from the manifest.
|
||||
targetLayerDigest := imgManifest.FSLayers[0].BlobSum
|
||||
|
@ -684,8 +683,8 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
|||
// Pull from the registry using the <name>@<digest> reference.
|
||||
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
||||
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
||||
c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
|
||||
assert.Assert(c, exitStatus != 0, "expected a non-zero exit status")
|
||||
|
||||
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
|
||||
c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
|
||||
assert.Assert(c, strings.Contains(out, expectedErrorMsg), fmt.Sprintf("expected error message in output: %s", out))
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *testing.T) {
|
||||
out := cli.DockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo").Combined()
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -23,7 +24,7 @@ func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
|
|||
cli.DockerCmd(c, "inspect", cleanedImageID)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitWithoutPause(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
||||
|
||||
|
@ -39,7 +40,7 @@ func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
|||
}
|
||||
|
||||
//test commit a paused container should not unpause it after commit
|
||||
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitPausedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
|
||||
|
||||
|
@ -50,10 +51,10 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
|||
|
||||
out = inspectField(c, cleanedContainerID, "State.Paused")
|
||||
// commit should not unpause a paused container
|
||||
c.Assert(out, checker.Contains, "true")
|
||||
assert.Assert(c, strings.Contains(out, "true"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitNewFile(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitNewFile(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name", "committer", "busybox", "/bin/sh", "-c", "echo koye > /foo")
|
||||
|
||||
imageID, _ := dockerCmd(c, "commit", "committer")
|
||||
|
@ -61,18 +62,17 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
|
||||
actual := strings.TrimSpace(out)
|
||||
c.Assert(actual, checker.Equals, "koye")
|
||||
assert.Equal(c, actual, "koye")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitHardlink(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
|
||||
|
||||
chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
|
||||
inode := chunks[0]
|
||||
chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
|
||||
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("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]), fmt.Sprintf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
|
||||
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
|
||||
imageID = strings.TrimSpace(imageID)
|
||||
|
||||
|
@ -81,10 +81,10 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
|||
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
|
||||
inode = chunks[0]
|
||||
chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
|
||||
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("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]), fmt.Sprintf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitTTY(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitTTY(c *testing.T) {
|
||||
dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
|
||||
|
||||
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
|
||||
|
@ -93,7 +93,7 @@ func (s *DockerSuite) TestCommitTTY(c *check.C) {
|
|||
dockerCmd(c, "run", imageID, "/bin/ls")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitWithHostBindMount(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
|
||||
|
||||
|
@ -103,7 +103,7 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
|
|||
dockerCmd(c, "run", imageID, "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitChange(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitChange(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name", "test", "busybox", "true")
|
||||
|
||||
imageID, _ := dockerCmd(c, "commit",
|
||||
|
@ -153,7 +153,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitChangeLabels(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitChangeLabels(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true")
|
||||
|
||||
imageID, _ := dockerCmd(c, "commit",
|
||||
|
@ -161,7 +161,7 @@ func (s *DockerSuite) TestCommitChangeLabels(c *check.C) {
|
|||
"test", "test-commit")
|
||||
imageID = strings.TrimSpace(imageID)
|
||||
|
||||
c.Assert(inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]")
|
||||
assert.Equal(c, inspectField(c, imageID, "Config.Labels"), "map[some:label2]")
|
||||
// check that container labels didn't change
|
||||
c.Assert(inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]")
|
||||
assert.Equal(c, inspectField(c, "test", "Config.Labels"), "map[some:label]")
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -22,7 +22,7 @@ import (
|
|||
// Check that copying from a container to a local symlink copies to the symlink
|
||||
// target and does not overwrite the local symlink itself.
|
||||
// TODO: move to docker/cli and/or integration/container/copy_test.go
|
||||
func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromSymlinkDestination(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
|
||||
|
||||
|
@ -36,38 +36,38 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
|
|||
srcPath := containerCpPath(containerID, "/file2")
|
||||
dstPath := cpPath(tmpDir, "symlinkToFile1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, dstPath, "file1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, dstPath, "file1") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a file from the container to a symlink to a directory. This
|
||||
// should copy the file into the symlink target directory.
|
||||
dstPath = cpPath(tmpDir, "symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dir1") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a file from the container to a symlink to a file that does
|
||||
// not exist (a broken symlink). This should create the target file with
|
||||
// the contents of the source file.
|
||||
dstPath = cpPath(tmpDir, "brokenSymlinkToFileX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, dstPath, "fileX"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, dstPath, "fileX") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a directory from the container to a symlink to a local
|
||||
// directory. This should copy the directory into the symlink target
|
||||
|
@ -75,13 +75,13 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
|
|||
srcPath = containerCpPath(containerID, "/dir2")
|
||||
dstPath = cpPath(tmpDir, "symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dir1") == nil)
|
||||
|
||||
// The directory should now contain a copy of "dir2".
|
||||
c.Assert(fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n") == nil)
|
||||
|
||||
// Next, copy a directory from the container to a symlink to a local
|
||||
// directory that does not exist (a broken symlink). This should create
|
||||
|
@ -89,13 +89,13 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
|
|||
// should not modify the symlink.
|
||||
dstPath = cpPath(tmpDir, "brokenSymlinkToDirX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, dstPath, "dirX"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dirX") == nil)
|
||||
|
||||
// The "dirX" directory should now be a copy of "dir2".
|
||||
c.Assert(fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n") == nil)
|
||||
}
|
||||
|
||||
// Possibilities are reduced to the remaining 10 cases:
|
||||
|
@ -117,7 +117,7 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
|
|||
// 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
|
||||
// contents of the source file into it.
|
||||
func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseA(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -129,15 +129,15 @@ func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
|
|||
srcPath := containerCpPath(containerID, "/root/file1")
|
||||
dstPath := cpPath(tmpDir, "itWorks.txt")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// B. SRC specifies a file and DST (with trailing path separator) doesn't
|
||||
// exist. This should cause an error because the copy operation cannot
|
||||
// create a directory when copying a single file.
|
||||
func (s *DockerSuite) TestCpFromCaseB(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseB(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
|
||||
|
||||
|
@ -150,12 +150,12 @@ func (s *DockerSuite) TestCpFromCaseB(c *check.C) {
|
|||
err := runDockerCp(c, srcPath, dstDir, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpDirNotExist(err), fmt.Sprintf("expected DirNotExists error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseC(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -170,17 +170,17 @@ func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
|
|||
dstPath := cpPath(tmpDir, "file2")
|
||||
|
||||
// Ensure the local file starts with different content.
|
||||
c.Assert(fileContentEquals(c, dstPath, "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file2\n") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// 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
|
||||
// this works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseD(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
|
||||
|
||||
|
@ -195,32 +195,32 @@ func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
|
|||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
_, err := os.Stat(dstPath)
|
||||
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("did not expect dstPath %q to exist", dstPath))
|
||||
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("did not expect dstPath %q to exist", dstPath))
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
// unable to remove dstDir
|
||||
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
|
||||
assert.Assert(c, os.RemoveAll(dstDir) == nil)
|
||||
|
||||
// unable to make dstDir
|
||||
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
|
||||
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)) == nil)
|
||||
|
||||
dstDir = cpPathTrailingSep(tmpDir, "dir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// E. SRC specifies a directory and DST does not exist. This should create a
|
||||
// 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
|
||||
// not.
|
||||
func (s *DockerSuite) TestCpFromCaseE(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseE(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
|
||||
|
||||
|
@ -231,25 +231,25 @@ func (s *DockerSuite) TestCpFromCaseE(c *check.C) {
|
|||
dstDir := cpPath(tmpDir, "testDir")
|
||||
dstPath := filepath.Join(dstDir, "file1-1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
// unable to remove dstDir
|
||||
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
|
||||
assert.Assert(c, os.RemoveAll(dstDir) == nil)
|
||||
|
||||
dstDir = cpPathTrailingSep(tmpDir, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseF(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -266,13 +266,13 @@ func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
|
|||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// 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
|
||||
// works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseG(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -288,30 +288,30 @@ func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
|
|||
resultDir := filepath.Join(dstDir, "dir1")
|
||||
dstPath := filepath.Join(resultDir, "file1-1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
// unable to remove dstDir
|
||||
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
|
||||
assert.Assert(c, os.RemoveAll(dstDir) == nil)
|
||||
|
||||
// unable to make dstDir
|
||||
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
|
||||
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)) == nil)
|
||||
|
||||
dstDir = cpPathTrailingSep(tmpDir, "dir2")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// H. SRC specifies a directory's contents only and DST does not exist. This
|
||||
// should create a directory at DST and copy the contents of the SRC
|
||||
// directory (but not the directory itself) into the DST directory. Ensure
|
||||
// this works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseH(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
|
||||
|
||||
|
@ -322,26 +322,26 @@ func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
|
|||
dstDir := cpPath(tmpDir, "testDir")
|
||||
dstPath := filepath.Join(dstDir, "file1-1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
// unable to remove resultDir
|
||||
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
|
||||
assert.Assert(c, os.RemoveAll(dstDir) == nil)
|
||||
|
||||
dstDir = cpPathTrailingSep(tmpDir, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// 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
|
||||
// directory.
|
||||
func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseI(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -358,14 +358,14 @@ func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
|
|||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// J. SRC specifies a directory's contents only and DST exists as a 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
|
||||
// trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpFromCaseJ(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromCaseJ(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -380,21 +380,21 @@ func (s *DockerSuite) TestCpFromCaseJ(c *check.C) {
|
|||
dstDir := cpPath(tmpDir, "dir2")
|
||||
dstPath := filepath.Join(dstDir, "file1-1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
// unable to remove dstDir
|
||||
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
|
||||
assert.Assert(c, os.RemoveAll(dstDir) == nil)
|
||||
|
||||
// unable to make dstDir
|
||||
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
|
||||
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)) == nil)
|
||||
|
||||
dstDir = cpPathTrailingSep(tmpDir, "dir2")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n") == nil)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
|
@ -27,14 +27,14 @@ const (
|
|||
)
|
||||
|
||||
// Ensure that an all-local path case returns an error.
|
||||
func (s *DockerSuite) TestCpLocalOnly(c *check.C) {
|
||||
func (s *DockerSuite) TestCpLocalOnly(c *testing.T) {
|
||||
err := runDockerCp(c, "foo", "bar", nil)
|
||||
assert.ErrorContains(c, err, "must specify at least one container source")
|
||||
}
|
||||
|
||||
// Test for #5656
|
||||
// Check that garbage paths don't escape the container's rootfs
|
||||
func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
|
||||
func (s *DockerSuite) TestCpGarbagePath(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -70,7 +70,7 @@ func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
|
|||
}
|
||||
|
||||
// Check that relative paths are relative to the container's rootfs
|
||||
func (s *DockerSuite) TestCpRelativePath(c *check.C) {
|
||||
func (s *DockerSuite) TestCpRelativePath(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -112,7 +112,7 @@ func (s *DockerSuite) TestCpRelativePath(c *check.C) {
|
|||
}
|
||||
|
||||
// Check that absolute paths are relative to the container's rootfs
|
||||
func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
|
||||
func (s *DockerSuite) TestCpAbsolutePath(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -149,7 +149,7 @@ func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
|
|||
|
||||
// Test for #5619
|
||||
// Check that absolute symlinks are still relative to the container's rootfs
|
||||
func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
|
||||
func (s *DockerSuite) TestCpAbsoluteSymlink(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
|
||||
|
||||
|
@ -185,7 +185,7 @@ func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
|
|||
|
||||
// Check that symlinks to a directory behave as expected when copying one from
|
||||
// a container.
|
||||
func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *check.C) {
|
||||
func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link")
|
||||
|
||||
|
@ -231,7 +231,7 @@ func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *check.C) {
|
|||
|
||||
// Check that symlinks to a directory behave as expected when copying one to a
|
||||
// container.
|
||||
func (s *DockerSuite) TestCpToSymlinkToDirectory(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToSymlinkToDirectory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, testEnv.IsLocalDaemon) // Requires local volume mount bind.
|
||||
|
||||
|
@ -308,7 +308,7 @@ func (s *DockerSuite) TestCpToSymlinkToDirectory(c *check.C) {
|
|||
|
||||
// Test for #5619
|
||||
// Check that symlinks which are part of the resource path are still relative to the container's rootfs
|
||||
func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
|
||||
func (s *DockerSuite) TestCpSymlinkComponent(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
|
||||
|
||||
|
@ -347,7 +347,7 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
|
|||
}
|
||||
|
||||
// Check that cp with unprivileged user doesn't return any error
|
||||
func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
|
||||
func (s *DockerSuite) TestCpUnprivilegedUser(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
testRequires(c, UnixCli) // uses chmod/su: not available on windows
|
||||
|
||||
|
@ -371,7 +371,7 @@ func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
|
|||
result.Assert(c, icmd.Expected{})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
|
||||
func (s *DockerSuite) TestCpSpecialFiles(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
|
||||
|
@ -411,7 +411,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
|
|||
assert.Assert(c, bytes.Equal(actual, expected), "Expected copied file to be duplicate of the container hostname")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCpVolumePath(c *check.C) {
|
||||
func (s *DockerSuite) TestCpVolumePath(c *testing.T) {
|
||||
// stat /tmp/cp-test-volumepath851508420/test gets permission denied for the user
|
||||
testRequires(c, NotUserNamespace)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -474,7 +474,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
|
|||
assert.Assert(c, bytes.Equal(fb, fb2), "Expected copied file to be duplicate of bind-mounted file")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCpToDot(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToDot(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -497,7 +497,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
|
|||
assert.Equal(c, string(content), "lololol\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCpToStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToStdout(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
@ -514,7 +514,7 @@ func (s *DockerSuite) TestCpToStdout(c *check.C) {
|
|||
assert.Check(c, is.Contains(out, "-rw"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
|
||||
func (s *DockerSuite) TestCpNameHasColon(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
|
||||
|
@ -533,7 +533,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
|
|||
assert.Equal(c, string(content), "lololol\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestCopyAndRestart(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
expectedMsg := "hello"
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
|
||||
|
@ -552,7 +552,7 @@ func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), expectedMsg)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestCopyCreatedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
|
||||
|
||||
|
@ -565,7 +565,7 @@ func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
|
|||
// test copy with option `-L`: following symbol link
|
||||
// Check that symlinks to a file behave as expected when copying one from
|
||||
// a container to host following symbol link
|
||||
func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) {
|
||||
func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T) {
|
||||
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")
|
||||
assert.Equal(c, exitCode, 0, "failed to set up container: %s", out)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
|||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToSymlinkDestination(c *testing.T) {
|
||||
// stat /tmp/test-cp-to-symlink-destination-262430901/vol3 gets permission denied for the user
|
||||
testRequires(c, NotUserNamespace)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -40,38 +40,38 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
|||
srcPath := cpPath(testVol, "file2")
|
||||
dstPath := containerCpPath(containerID, "/vol2/symlinkToFile1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "file1"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a local file to a symlink to a directory in the container.
|
||||
// This should copy the file into the symlink target directory.
|
||||
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "file2"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a file to a symlink to a file that does not exist (a broken
|
||||
// symlink) in the container. This should create the target file with the
|
||||
// contents of the source file.
|
||||
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToFileX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX") == nil)
|
||||
|
||||
// The file should have the contents of "file2" now.
|
||||
c.Assert(fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n") == nil)
|
||||
|
||||
// Next, copy a local directory to a symlink to a directory in the
|
||||
// container. This should copy the directory into the symlink target
|
||||
|
@ -79,13 +79,13 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
|||
srcPath = cpPath(testVol, "/dir2")
|
||||
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1") == nil)
|
||||
|
||||
// The directory should now contain a copy of "dir2".
|
||||
c.Assert(fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n") == nil)
|
||||
|
||||
// Next, copy a local directory to a symlink to a local directory that does
|
||||
// not exist (a broken symlink) in the container. This should create the
|
||||
|
@ -93,13 +93,13 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
|||
// should not modify the symlink.
|
||||
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToDirX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil)
|
||||
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX") == nil)
|
||||
|
||||
// The "dirX" directory should now be a copy of "dir2".
|
||||
c.Assert(fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
|
||||
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n") == nil)
|
||||
}
|
||||
|
||||
// Possibilities are reduced to the remaining 10 cases:
|
||||
|
@ -121,7 +121,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
|||
// 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
|
||||
// contents of the source file into it.
|
||||
func (s *DockerSuite) TestCpToCaseA(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseA(c *testing.T) {
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
workDir: "/root", command: makeCatFileCommand("itWorks.txt"),
|
||||
})
|
||||
|
@ -134,15 +134,15 @@ func (s *DockerSuite) TestCpToCaseA(c *check.C) {
|
|||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "/root/itWorks.txt")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// B. SRC specifies a file and DST (with trailing path separator) doesn't
|
||||
// exist. This should cause an error because the copy operation cannot
|
||||
// create a directory when copying a single file.
|
||||
func (s *DockerSuite) TestCpToCaseB(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseB(c *testing.T) {
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
command: makeCatFileCommand("testDir/file1"),
|
||||
})
|
||||
|
@ -158,12 +158,12 @@ func (s *DockerSuite) TestCpToCaseB(c *check.C) {
|
|||
err := runDockerCp(c, srcPath, dstDir, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpDirNotExist(err), fmt.Sprintf("expected DirNotExists error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestCpToCaseC(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseC(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -179,18 +179,18 @@ func (s *DockerSuite) TestCpToCaseC(c *check.C) {
|
|||
dstPath := containerCpPath(containerID, "/root/file2")
|
||||
|
||||
// Ensure the container's file starts with the original content.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file2\n") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil) == nil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// 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
|
||||
// this works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpToCaseD(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseD(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true,
|
||||
|
@ -206,12 +206,12 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
|
|||
dstDir := containerCpPath(containerID, "dir1")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
|
@ -224,19 +224,19 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
|
|||
dstDir = containerCpPathTrailingSep(containerID, "dir1")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n") == nil)
|
||||
}
|
||||
|
||||
// E. SRC specifies a directory and DST does not exist. This should create a
|
||||
// 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
|
||||
// not.
|
||||
func (s *DockerSuite) TestCpToCaseE(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseE(c *testing.T) {
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
command: makeCatFileCommand("/testDir/file1-1"),
|
||||
})
|
||||
|
@ -249,10 +249,10 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
|
|||
srcDir := cpPath(tmpDir, "dir1")
|
||||
dstDir := containerCpPath(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
|
@ -263,15 +263,15 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
|
|||
|
||||
dstDir = containerCpPathTrailingSep(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *DockerSuite) TestCpToCaseF(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseF(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -288,13 +288,13 @@ func (s *DockerSuite) TestCpToCaseF(c *check.C) {
|
|||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// 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
|
||||
// works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpToCaseG(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseG(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -310,12 +310,12 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
|
|||
dstDir := containerCpPath(containerID, "/root/dir2")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
|
@ -328,19 +328,19 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
|
|||
dstDir = containerCpPathTrailingSep(containerID, "/dir2")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// H. SRC specifies a directory's contents only and DST does not exist. This
|
||||
// should create a directory at DST and copy the contents of the SRC
|
||||
// directory (but not the directory itself) into the DST directory. Ensure
|
||||
// this works whether DST has a trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpToCaseH(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseH(c *testing.T) {
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
command: makeCatFileCommand("/testDir/file1-1"),
|
||||
})
|
||||
|
@ -353,10 +353,10 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
|
|||
srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
|
||||
dstDir := containerCpPath(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
|
@ -367,16 +367,16 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
|
|||
|
||||
dstDir = containerCpPathTrailingSep(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// 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
|
||||
// directory.
|
||||
func (s *DockerSuite) TestCpToCaseI(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseI(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -393,14 +393,14 @@ func (s *DockerSuite) TestCpToCaseI(c *check.C) {
|
|||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
}
|
||||
|
||||
// J. SRC specifies a directory's contents only and DST exists as a 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
|
||||
// trailing path separator or not.
|
||||
func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToCaseJ(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
containerID := makeTestContainer(c, testContainerOptions{
|
||||
addContent: true, workDir: "/root",
|
||||
|
@ -416,12 +416,12 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
|
|||
dstDir := containerCpPath(containerID, "/dir2")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
|
||||
// Now try again but using a trailing path separator for dstDir.
|
||||
|
||||
|
@ -433,17 +433,17 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
|
|||
dstDir = containerCpPathTrailingSep(containerID, "/dir2")
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil) == nil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n") == nil)
|
||||
}
|
||||
|
||||
// The `docker cp` command should also ensure that you cannot
|
||||
// write to a container rootfs that is marked as read-only.
|
||||
func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *testing.T) {
|
||||
// --read-only + userns has remount issues
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
tmpDir := getTestDir(c, "test-cp-to-err-read-only-rootfs")
|
||||
|
@ -462,15 +462,15 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) {
|
|||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyReadOnly(err), fmt.Sprintf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
}
|
||||
|
||||
// The `docker cp` command should also ensure that you
|
||||
// cannot write to a volume that is mounted as read-only.
|
||||
func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *testing.T) {
|
||||
// --read-only + userns has remount issues
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
tmpDir := getTestDir(c, "test-cp-to-err-read-only-volume")
|
||||
|
@ -489,8 +489,8 @@ func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) {
|
|||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
||||
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
|
||||
assert.Assert(c, isCpCannotCopyReadOnly(err), fmt.Sprintf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
|
||||
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestCpToContainerWithPermissions(c *check.C) {
|
||||
func (s *DockerSuite) TestCpToContainerWithPermissions(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
tmpDir := getTestDir(c, "test-cp-to-host-with-permissions")
|
||||
|
@ -38,7 +38,7 @@ func (s *DockerSuite) TestCpToContainerWithPermissions(c *check.C) {
|
|||
}
|
||||
|
||||
// Check ownership is root, both in non-userns and userns enabled modes
|
||||
func (s *DockerSuite) TestCpCheckDestOwnership(c *check.C) {
|
||||
func (s *DockerSuite) TestCpCheckDestOwnership(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
tmpVolDir := getTestDir(c, "test-cp-tmpvol")
|
||||
containerID := makeTestContainer(c,
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -92,7 +92,7 @@ func defaultMkContentCommand() string {
|
|||
return mkFilesCommand(defaultFileData)
|
||||
}
|
||||
|
||||
func makeTestContentInDir(c *check.C, dir string) {
|
||||
func makeTestContentInDir(c *testing.T, dir string) {
|
||||
for _, fd := range defaultFileData {
|
||||
path := filepath.Join(dir, filepath.FromSlash(fd.path))
|
||||
switch fd.filetype {
|
||||
|
@ -118,7 +118,7 @@ type testContainerOptions struct {
|
|||
command string
|
||||
}
|
||||
|
||||
func makeTestContainer(c *check.C, options testContainerOptions) (containerID string) {
|
||||
func makeTestContainer(c *testing.T, options testContainerOptions) (containerID string) {
|
||||
if options.addContent {
|
||||
mkContentCmd := defaultMkContentCommand()
|
||||
if options.command == "" {
|
||||
|
@ -188,7 +188,7 @@ func containerCpPathTrailingSep(containerID string, pathElements ...string) stri
|
|||
return fmt.Sprintf("%s/", containerCpPath(containerID, pathElements...))
|
||||
}
|
||||
|
||||
func runDockerCp(c *check.C, src, dst string, params []string) (err error) {
|
||||
func runDockerCp(c *testing.T, src, dst string, params []string) (err error) {
|
||||
c.Logf("running `docker cp %s %s %s`", strings.Join(params, " "), src, dst)
|
||||
|
||||
args := []string{"cp"}
|
||||
|
@ -205,7 +205,7 @@ func runDockerCp(c *check.C, src, dst string, params []string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func startContainerGetOutput(c *check.C, containerID string) (out string, err error) {
|
||||
func startContainerGetOutput(c *testing.T, containerID string) (out string, err error) {
|
||||
c.Logf("running `docker start -a %s`", containerID)
|
||||
|
||||
args := []string{"start", "-a", containerID}
|
||||
|
@ -218,7 +218,7 @@ func startContainerGetOutput(c *check.C, containerID string) (out string, err er
|
|||
return
|
||||
}
|
||||
|
||||
func getTestDir(c *check.C, label string) (tmpDir string) {
|
||||
func getTestDir(c *testing.T, label string) (tmpDir string) {
|
||||
var err error
|
||||
|
||||
tmpDir, err = ioutil.TempDir("", label)
|
||||
|
@ -240,7 +240,7 @@ func isCpCannotCopyReadOnly(err error) bool {
|
|||
return strings.Contains(err.Error(), "marked read-only")
|
||||
}
|
||||
|
||||
func fileContentEquals(c *check.C, filename, contents string) (err error) {
|
||||
func fileContentEquals(c *testing.T, filename, contents string) (err error) {
|
||||
c.Logf("checking that file %q contains %q\n", filename, contents)
|
||||
|
||||
fileBytes, err := ioutil.ReadFile(filename)
|
||||
|
@ -260,7 +260,7 @@ func fileContentEquals(c *check.C, filename, contents string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func symlinkTargetEquals(c *check.C, symlink, expectedTarget string) (err error) {
|
||||
func symlinkTargetEquals(c *testing.T, symlink, expectedTarget string) (err error) {
|
||||
c.Logf("checking that the symlink %q points to %q\n", symlink, expectedTarget)
|
||||
|
||||
actualTarget, err := os.Readlink(symlink)
|
||||
|
@ -275,7 +275,7 @@ func symlinkTargetEquals(c *check.C, symlink, expectedTarget string) (err error)
|
|||
return
|
||||
}
|
||||
|
||||
func containerStartOutputEquals(c *check.C, containerID, contents string) (err error) {
|
||||
func containerStartOutputEquals(c *testing.T, containerID, contents string) (err error) {
|
||||
c.Logf("checking that container %q start output contains %q\n", containerID, contents)
|
||||
|
||||
out, err := startContainerGetOutput(c, containerID)
|
||||
|
|
|
@ -6,21 +6,20 @@ import (
|
|||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
// Make sure we can create a simple container with some args
|
||||
func (s *DockerSuite) TestCreateArgs(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateArgs(c *testing.T) {
|
||||
// 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")
|
||||
|
||||
|
@ -37,11 +36,11 @@ func (s *DockerSuite) TestCreateArgs(c *check.C) {
|
|||
}
|
||||
|
||||
err := json.Unmarshal([]byte(out), &containers)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
|
||||
assert.Equal(c, len(containers), 1)
|
||||
|
||||
cont := containers[0]
|
||||
c.Assert(string(cont.Path), checker.Equals, "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path))
|
||||
assert.Equal(c, string(cont.Path), "command", fmt.Sprintf("Unexpected container path. Expected command, received: %s", cont.Path))
|
||||
|
||||
b := false
|
||||
expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"}
|
||||
|
@ -58,7 +57,7 @@ func (s *DockerSuite) TestCreateArgs(c *check.C) {
|
|||
}
|
||||
|
||||
// Make sure we can grow the container's rootfs at creation time.
|
||||
func (s *DockerSuite) TestCreateGrowRootfs(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateGrowRootfs(c *testing.T) {
|
||||
// Windows and Devicemapper support growing the rootfs
|
||||
if testEnv.OSType != "windows" {
|
||||
testRequires(c, Devicemapper)
|
||||
|
@ -68,21 +67,21 @@ func (s *DockerSuite) TestCreateGrowRootfs(c *check.C) {
|
|||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
inspectOut := inspectField(c, cleanedContainerID, "HostConfig.StorageOpt")
|
||||
c.Assert(inspectOut, checker.Equals, "map[size:120G]")
|
||||
assert.Equal(c, inspectOut, "map[size:120G]")
|
||||
}
|
||||
|
||||
// Make sure we cannot shrink the container's rootfs at creation time.
|
||||
func (s *DockerSuite) TestCreateShrinkRootfs(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateShrinkRootfs(c *testing.T) {
|
||||
testRequires(c, Devicemapper)
|
||||
|
||||
// Ensure this fails because of the defaultBaseFsSize is 10G
|
||||
out, _, err := dockerCmdWithError("create", "--storage-opt", "size=5G", "busybox")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
c.Assert(out, checker.Contains, "Container size cannot be smaller than")
|
||||
assert.Assert(c, strings.Contains(out, "Container size cannot be smaller than"))
|
||||
}
|
||||
|
||||
// Make sure we can set hostconfig options too
|
||||
func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateHostConfig(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "-P", "busybox", "echo")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -96,15 +95,15 @@ func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
|
|||
}
|
||||
|
||||
err := json.Unmarshal([]byte(out), &containers)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
|
||||
assert.Equal(c, len(containers), 1)
|
||||
|
||||
cont := containers[0]
|
||||
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
||||
c.Assert(cont.HostConfig.PublishAllPorts, check.NotNil, check.Commentf("Expected PublishAllPorts, got false"))
|
||||
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
|
||||
assert.Assert(c, cont.HostConfig.PublishAllPorts, fmt.Sprintf("Expected PublishAllPorts, got false"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -117,23 +116,23 @@ func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
|
|||
}
|
||||
}
|
||||
err := json.Unmarshal([]byte(out), &containers)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
|
||||
assert.Equal(c, len(containers), 1)
|
||||
|
||||
cont := containers[0]
|
||||
|
||||
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
||||
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
|
||||
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
|
||||
assert.Equal(c, len(cont.HostConfig.PortBindings), 4, fmt.Sprintf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
|
||||
|
||||
for k, v := range cont.HostConfig.PortBindings {
|
||||
c.Assert(v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
|
||||
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
||||
assert.Equal(c, len(v), 1, fmt.Sprintf("Expected 1 ports binding, for the port %s but found %s", k, v))
|
||||
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateWithLargePortRange(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateWithLargePortRange(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -147,22 +146,22 @@ func (s *DockerSuite) TestCreateWithLargePortRange(c *check.C) {
|
|||
}
|
||||
|
||||
err := json.Unmarshal([]byte(out), &containers)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
|
||||
assert.Equal(c, len(containers), 1)
|
||||
|
||||
cont := containers[0]
|
||||
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
|
||||
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 65535)
|
||||
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
|
||||
assert.Equal(c, len(cont.HostConfig.PortBindings), 65535)
|
||||
|
||||
for k, v := range cont.HostConfig.PortBindings {
|
||||
c.Assert(v, checker.HasLen, 1)
|
||||
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
||||
assert.Equal(c, len(v), 1)
|
||||
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// "test123" should be printed by docker create + start
|
||||
func (s *DockerSuite) TestCreateEchoStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateEchoStdout(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "busybox", "echo", "test123")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -171,7 +170,7 @@ func (s *DockerSuite) TestCreateEchoStdout(c *check.C) {
|
|||
assert.Equal(c, out, "test123\n", "container should've printed 'test123', got %q", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateVolumesCreated(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
|
||||
|
@ -179,7 +178,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
|
|||
dockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox")
|
||||
|
||||
dir, err := inspectMountSourceField(name, prefix+slash+"foo")
|
||||
c.Assert(err, check.IsNil, check.Commentf("Error getting volume host path: %q", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Error getting volume host path: %q", err))
|
||||
|
||||
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
||||
c.Fatalf("Volume was not created")
|
||||
|
@ -190,7 +189,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateLabels(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateLabels(c *testing.T) {
|
||||
name := "test_create_labels"
|
||||
expected := map[string]string{"k1": "v1", "k2": "v2"}
|
||||
dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
|
||||
|
@ -203,7 +202,7 @@ func (s *DockerSuite) TestCreateLabels(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateLabelFromImage(c *testing.T) {
|
||||
imageName := "testcreatebuildlabel"
|
||||
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
||||
LABEL k1=v1 k2=v2`))
|
||||
|
@ -220,7 +219,7 @@ func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateHostnameWithNumber(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateHostnameWithNumber(c *testing.T) {
|
||||
image := "busybox"
|
||||
// Busybox on Windows does not implement hostname command
|
||||
if testEnv.OSType == "windows" {
|
||||
|
@ -230,7 +229,7 @@ func (s *DockerSuite) TestCreateHostnameWithNumber(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "web.0", "hostname not set, expected `web.0`, got: %s", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateRM(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateRM(c *testing.T) {
|
||||
// Test to make sure we can 'rm' a new container that is in
|
||||
// "Created" state, and has ever been run. Test "rm -f" too.
|
||||
|
||||
|
@ -247,7 +246,7 @@ func (s *DockerSuite) TestCreateRM(c *check.C) {
|
|||
dockerCmd(c, "rm", "-f", cID)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateModeIpcContainer(c *testing.T) {
|
||||
// Uses Linux specific functionality (--ipc)
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
|
||||
|
@ -257,7 +256,7 @@ func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
|
|||
dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateByImageID(c *testing.T) {
|
||||
imageName := "testcreatebyimageid"
|
||||
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio`))
|
||||
|
@ -290,16 +289,15 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateStopSignal(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateStopSignal(c *testing.T) {
|
||||
name := "test_create_stop_signal"
|
||||
dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox")
|
||||
|
||||
res := inspectFieldJSON(c, name, "Config.StopSignal")
|
||||
c.Assert(res, checker.Contains, "9")
|
||||
|
||||
assert.Assert(c, strings.Contains(res, "9"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateWithWorkdir(c *testing.T) {
|
||||
name := "foo"
|
||||
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
|
@ -313,19 +311,19 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) {
|
|||
dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *testing.T) {
|
||||
name := "test-invalidate-log-opts"
|
||||
out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "unknown log opt")
|
||||
assert.Assert(c, strings.Contains(out, "unknown log opt"))
|
||||
assert.Assert(c, is.Contains(out, "unknown log opt"))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-a")
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
assert.Assert(c, !strings.Contains(out, name))
|
||||
}
|
||||
|
||||
// #20972
|
||||
func (s *DockerSuite) TestCreate64ByteHexID(c *check.C) {
|
||||
func (s *DockerSuite) TestCreate64ByteHexID(c *testing.T) {
|
||||
out := inspectField(c, "busybox", "Id")
|
||||
imageID := strings.TrimPrefix(strings.TrimSpace(string(out)), "sha256:")
|
||||
|
||||
|
@ -333,7 +331,7 @@ func (s *DockerSuite) TestCreate64ByteHexID(c *check.C) {
|
|||
}
|
||||
|
||||
// Test case for #23498
|
||||
func (s *DockerSuite) TestCreateUnsetEntrypoint(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateUnsetEntrypoint(c *testing.T) {
|
||||
name := "test-entrypoint"
|
||||
dockerfile := `FROM busybox
|
||||
ADD entrypoint.sh /entrypoint.sh
|
||||
|
@ -354,22 +352,21 @@ exec "$@"`,
|
|||
|
||||
out := cli.DockerCmd(c, "create", "--entrypoint=", name, "echo", "foo").Combined()
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(id, check.Not(check.Equals), "")
|
||||
assert.Assert(c, id != "")
|
||||
out = cli.DockerCmd(c, "start", "-a", id).Combined()
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
|
||||
assert.Equal(c, strings.TrimSpace(out), "foo")
|
||||
}
|
||||
|
||||
// #22471
|
||||
func (s *DockerSuite) TestCreateStopTimeout(c *check.C) {
|
||||
func (s *DockerSuite) TestCreateStopTimeout(c *testing.T) {
|
||||
name1 := "test_create_stop_timeout_1"
|
||||
dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox")
|
||||
|
||||
res := inspectFieldJSON(c, name1, "Config.StopTimeout")
|
||||
c.Assert(res, checker.Contains, "15")
|
||||
|
||||
assert.Assert(c, strings.Contains(res, "15"))
|
||||
name2 := "test_create_stop_timeout_2"
|
||||
dockerCmd(c, "create", "--name", name2, "busybox")
|
||||
|
||||
res = inspectFieldJSON(c, name2, "Config.StopTimeout")
|
||||
c.Assert(res, checker.Contains, "null")
|
||||
assert.Assert(c, strings.Contains(res, "null"))
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@ package main
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/go-check/check"
|
||||
"golang.org/x/sys/unix"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
@ -42,7 +42,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) {
|
|||
}
|
||||
|
||||
// TestDaemonRestartWithPluginDisabled tests state restore for a disabled plugin
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
@ -69,7 +69,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) {
|
|||
|
||||
// TestDaemonKillLiveRestoreWithPlugins SIGKILLs daemon started with --live-restore.
|
||||
// Plugins should continue to run.
|
||||
func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c, "--live-restore")
|
||||
|
@ -95,7 +95,7 @@ func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) {
|
|||
|
||||
// TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore.
|
||||
// Plugins should continue to run.
|
||||
func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c, "--live-restore")
|
||||
|
@ -120,7 +120,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C)
|
|||
}
|
||||
|
||||
// TestDaemonShutdownWithPlugins shuts down running plugins.
|
||||
func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
@ -158,7 +158,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) {
|
|||
}
|
||||
|
||||
// TestDaemonKillWithPlugins leaves plugins running.
|
||||
func (s *DockerDaemonSuite) TestDaemonKillWithPlugins(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonKillWithPlugins(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
@ -185,7 +185,7 @@ func (s *DockerDaemonSuite) TestDaemonKillWithPlugins(c *check.C) {
|
|||
}
|
||||
|
||||
// TestVolumePlugin tests volume creation using a plugin.
|
||||
func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestVolumePlugin(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
volName := "plugin-volume"
|
||||
|
@ -231,7 +231,7 @@ func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestPluginVolumeRemoveOnRestart(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestPluginVolumeRemoveOnRestart(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c, "--live-restore=true")
|
||||
|
@ -272,7 +272,7 @@ func existsMountpointWithPrefix(mountpointPrefix string) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
@ -300,7 +300,7 @@ func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, pName))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestPluginListFilterCapability(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestPluginListFilterCapability(c *testing.T) {
|
||||
testRequires(c, IsAmd64, Network)
|
||||
|
||||
s.d.Start(c)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,6 +11,7 @@ import (
|
|||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -19,13 +20,12 @@ import (
|
|||
eventstestutils "github.com/docker/docker/daemon/events/testutils"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsTimestampFormats(c *testing.T) {
|
||||
name := "events-time-format-test"
|
||||
|
||||
// Start stopwatch, generate an event
|
||||
|
@ -54,7 +54,7 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsUntag(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsUntag(c *testing.T) {
|
||||
image := "busybox"
|
||||
dockerCmd(c, "tag", image, "utest:tag1")
|
||||
dockerCmd(c, "tag", image, "utest:tag2")
|
||||
|
@ -77,7 +77,7 @@ func (s *DockerSuite) TestEventsUntag(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerEvents(c *testing.T) {
|
||||
dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true")
|
||||
|
||||
out, _ := dockerCmd(c, "events", "--until", daemonUnixTime(c))
|
||||
|
@ -89,7 +89,7 @@ func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
|
|||
assert.Assert(c, is.DeepEqual(containerEvents[:5], []string{"create", "attach", "start", "die", "destroy"}), out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true")
|
||||
|
||||
|
@ -113,7 +113,7 @@ func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *check.C) {
|
|||
assert.Equal(c, matchedEvents, 2, "missing events for container container-events-test:\n%s", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing.T) {
|
||||
dockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true")
|
||||
timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
|
||||
timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1)
|
||||
|
@ -127,7 +127,7 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
|
|||
assert.Assert(c, is.DeepEqual(containerEvents, []string{"create", "attach", "start", "die", "destroy"}), out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImageTag(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsImageTag(c *testing.T) {
|
||||
time.Sleep(1 * time.Second) // because API has seconds granularity
|
||||
since := daemonUnixTime(c)
|
||||
image := "testimageevents:tag"
|
||||
|
@ -145,7 +145,7 @@ func (s *DockerSuite) TestEventsImageTag(c *check.C) {
|
|||
assert.Equal(c, matches["action"], "tag")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImagePull(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsImagePull(c *testing.T) {
|
||||
// TODO Windows: Enable this test once pull and reliable image names are available
|
||||
testRequires(c, DaemonIsLinux)
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -163,7 +163,7 @@ func (s *DockerSuite) TestEventsImagePull(c *check.C) {
|
|||
assert.Equal(c, matches["action"], "pull")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImageImport(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsImageImport(c *testing.T) {
|
||||
// TODO Windows CI. This should be portable once export/import are
|
||||
// more reliable (@swernli)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -187,7 +187,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
|
|||
assert.Equal(c, matches["action"], "import", "matches: %v\nout:\n%s\n", matches, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsImageLoad(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
myImageName := "footest:v1"
|
||||
dockerCmd(c, "tag", "busybox", myImageName)
|
||||
|
@ -226,7 +226,7 @@ func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
|
|||
assert.Equal(c, matches["action"], "save", "matches: %v\nout:\n%s\n", matches, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsPluginOps(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsPluginOps(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -245,7 +245,7 @@ func (s *DockerSuite) TestEventsPluginOps(c *check.C) {
|
|||
assert.Assert(c, is.DeepEqual(pluginEvents, []string{"pull", "enable", "disable", "remove"}), out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilters(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilters(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
||||
|
@ -260,7 +260,7 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
|
|||
assert.Assert(c, count >= 2, "should have had 2 start events but had %d, out: %s", count, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterImageName(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
|
||||
|
@ -288,7 +288,7 @@ func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
|
|||
assert.Assert(c, count2 != 0, "Expected event from container but got %d from %s", count2, container2)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterLabels(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterLabels(c *testing.T) {
|
||||
since := strconv.FormatUint(uint64(daemonTime(c).Unix()), 10)
|
||||
label := "io.docker.testing=foo"
|
||||
|
||||
|
@ -323,7 +323,7 @@ func (s *DockerSuite) TestEventsFilterLabels(c *check.C) {
|
|||
assert.Assert(c, found)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterImageLabels(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
name := "labelfiltertest"
|
||||
label := "io.docker.testing=image"
|
||||
|
@ -353,7 +353,7 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterContainer(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
nameID := make(map[string]string)
|
||||
|
||||
|
@ -391,7 +391,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsCommit(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsCommit(c *testing.T) {
|
||||
// Problematic on Windows as cannot commit a running container
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -408,7 +408,7 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "commit"), "Missing 'commit' log event")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsCopy(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsCopy(c *testing.T) {
|
||||
// Build a test image.
|
||||
buildImageSuccessfully(c, "cpimg", build.WithDockerfile(`
|
||||
FROM busybox
|
||||
|
@ -437,7 +437,7 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "extract-to-dir"), "Missing 'extract-to-dir' log event")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsResize(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsResize(c *testing.T) {
|
||||
out := runSleepingContainer(c, "-d")
|
||||
cID := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(cID))
|
||||
|
@ -460,7 +460,7 @@ func (s *DockerSuite) TestEventsResize(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "resize"), "Missing 'resize' log event")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsAttach(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsAttach(c *testing.T) {
|
||||
// TODO Windows CI: Figure out why this test fails intermittently (TP5).
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -498,7 +498,7 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "attach"), "Missing 'attach' log event")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsRename(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsRename(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "--name", "oldName", "busybox", "true")
|
||||
cID := strings.TrimSpace(out)
|
||||
dockerCmd(c, "rename", "oldName", "newName")
|
||||
|
@ -509,7 +509,7 @@ func (s *DockerSuite) TestEventsRename(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "rename"), "Missing 'rename' log event")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsTop(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsTop(c *testing.T) {
|
||||
// Problematic on Windows as Windows does not support top
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -526,7 +526,7 @@ func (s *DockerSuite) TestEventsTop(c *check.C) {
|
|||
}
|
||||
|
||||
// #14316
|
||||
func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *testing.T) {
|
||||
// Problematic to port for Windows CI during TP5 timeframe until
|
||||
// supporting push
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -546,7 +546,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, repoName), "Missing 'push' log event for %s", repoName)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterType(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterType(c *testing.T) {
|
||||
// FIXME(vdemeester) fails on e2e run
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -600,7 +600,7 @@ func (s *DockerSuite) TestEventsFilterType(c *check.C) {
|
|||
}
|
||||
|
||||
// #25798
|
||||
func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
runSleepingContainer(c, "--name", "test-container", "-d")
|
||||
waitRun("test-container")
|
||||
|
@ -630,7 +630,7 @@ func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *check.C) {
|
|||
assert.Equal(c, len(events), 1, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
||||
waitRun("test-container")
|
||||
|
@ -640,7 +640,7 @@ func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) {
|
|||
assert.Assert(c, len(events) > 1, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsContainerRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerRestart(c *testing.T) {
|
||||
dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false")
|
||||
|
||||
// wait until test2 is auto removed.
|
||||
|
@ -680,7 +680,7 @@ func (s *DockerSuite) TestEventsContainerRestart(c *check.C) {
|
|||
assert.Equal(c, dieCount, 4, "testEvent should die 4 times: %v", actions)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsSinceInTheFuture(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsSinceInTheFuture(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
||||
waitRun("test-container")
|
||||
|
||||
|
@ -692,7 +692,7 @@ func (s *DockerSuite) TestEventsSinceInTheFuture(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "cannot be after `until`"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsUntilInThePast(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsUntilInThePast(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
|
||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
||||
|
@ -709,7 +709,7 @@ func (s *DockerSuite) TestEventsUntilInThePast(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "test-container"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFormat(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
||||
|
@ -732,7 +732,7 @@ func (s *DockerSuite) TestEventsFormat(c *check.C) {
|
|||
assert.Equal(c, startCount, 2, "should have had 2 start events but had %d, out: %s", startCount, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFormatBadFunc(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFormatBadFunc(c *testing.T) {
|
||||
// make sure it fails immediately, without receiving any event
|
||||
result := dockerCmdWithResult("events", "--format", "{{badFuncString .}}")
|
||||
result.Assert(c, icmd.Expected{
|
||||
|
@ -742,7 +742,7 @@ func (s *DockerSuite) TestEventsFormatBadFunc(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFormatBadField(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFormatBadField(c *testing.T) {
|
||||
// make sure it fails immediately, without receiving any event
|
||||
result := dockerCmdWithResult("events", "--format", "{{.badFieldString}}")
|
||||
result.Assert(c, icmd.Expected{
|
||||
|
|
|
@ -10,18 +10,18 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"golang.org/x/sys/unix"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// #5979
|
||||
func (s *DockerSuite) TestEventsRedirectStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsRedirectStdout(c *testing.T) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "busybox", "true")
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (s *DockerSuite) TestEventsRedirectStdout(c *check.C) {
|
|||
assert.NilError(c, scanner.Err(), "Scan err for command %q", command)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsOOMDisableFalse(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsOOMDisableFalse(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, swapMemorySupport, NotPpc64le)
|
||||
|
||||
errChan := make(chan error)
|
||||
|
@ -77,7 +77,7 @@ func (s *DockerSuite) TestEventsOOMDisableFalse(c *check.C) {
|
|||
assert.Equal(c, parseEventAction(c, events[nEvents-1]), "die")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsOOMDisableTrue(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotArm, swapMemorySupport, NotPpc64le)
|
||||
|
||||
errChan := make(chan error)
|
||||
|
@ -125,7 +125,7 @@ func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) {
|
|||
}
|
||||
|
||||
// #18453
|
||||
func (s *DockerSuite) TestEventsContainerFilterByName(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerFilterByName(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
cOut, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
|
||||
c1 := strings.TrimSpace(cOut)
|
||||
|
@ -139,7 +139,7 @@ func (s *DockerSuite) TestEventsContainerFilterByName(c *check.C) {
|
|||
}
|
||||
|
||||
// #18453
|
||||
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
buf := &bytes.Buffer{}
|
||||
cmd := exec.Command(dockerBinary, "events", "-f", "container=foo", "--since=0")
|
||||
|
@ -164,7 +164,7 @@ func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeEvents(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeEvents(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -192,7 +192,7 @@ func (s *DockerSuite) TestVolumeEvents(c *check.C) {
|
|||
assert.Equal(c, volumeEvents[4], "destroy")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkEvents(c *check.C) {
|
||||
func (s *DockerSuite) TestNetworkEvents(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -219,7 +219,7 @@ func (s *DockerSuite) TestNetworkEvents(c *check.C) {
|
|||
assert.Equal(c, netEvents[3], "destroy")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
// Observe create/connect network actions
|
||||
|
@ -247,7 +247,7 @@ func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "test-event-network-local-2"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsStreaming(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
observer, err := newEventObserver(c)
|
||||
|
@ -301,7 +301,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsImageUntagDelete(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
observer, err := newEventObserver(c)
|
||||
|
@ -340,7 +340,7 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -359,7 +359,7 @@ func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *check.C) {
|
|||
assert.Equal(c, networkActions[0], "create")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterVolumeID(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterVolumeID(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -374,7 +374,7 @@ func (s *DockerSuite) TestEventsFilterVolumeID(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(events[0], "driver=local"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilterNetworkID(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsFilterNetworkID(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
|
@ -387,7 +387,7 @@ func (s *DockerSuite) TestEventsFilterNetworkID(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(events[0], "type=bridge"))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonEvents(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonEvents(c *testing.T) {
|
||||
|
||||
// daemon config file
|
||||
configFilePath := "test.json"
|
||||
|
@ -455,7 +455,7 @@ func (s *DockerDaemonSuite) TestDaemonEvents(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonEventsWithFilters(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonEventsWithFilters(c *testing.T) {
|
||||
|
||||
// daemon config file
|
||||
configFilePath := "test.json"
|
||||
|
|
|
@ -11,18 +11,18 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestExec(c *check.C) {
|
||||
func (s *DockerSuite) TestExec(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
|
||||
assert.NilError(c, waitRun(strings.TrimSpace(out)))
|
||||
|
@ -31,7 +31,7 @@ func (s *DockerSuite) TestExec(c *check.C) {
|
|||
assert.Equal(c, strings.Trim(out, "\r\n"), "test")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecInteractive(c *check.C) {
|
||||
func (s *DockerSuite) TestExecInteractive(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (s *DockerSuite) TestExecInteractive(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestExecAfterContainerRestart(c *testing.T) {
|
||||
out := runSleepingContainer(c)
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(cleanedContainerID))
|
||||
|
@ -78,7 +78,7 @@ func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "hello")
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *testing.T) {
|
||||
// TODO Windows CI: DockerDaemonSuite doesn't run on Windows, and requires a little work to get this ported.
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
|
@ -96,7 +96,7 @@ func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
|
|||
}
|
||||
|
||||
// Regression test for #9155, #9044
|
||||
func (s *DockerSuite) TestExecEnv(c *check.C) {
|
||||
func (s *DockerSuite) TestExecEnv(c *testing.T) {
|
||||
// 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
|
||||
// into the process that is launched, not into the machine environment. Hence
|
||||
|
@ -111,7 +111,7 @@ func (s *DockerSuite) TestExecEnv(c *check.C) {
|
|||
assert.Check(c, strings.Contains(out, "HOME=/root"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecSetEnv(c *check.C) {
|
||||
func (s *DockerSuite) TestExecSetEnv(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
runSleepingContainer(c, "-e", "HOME=/root", "-d", "--name", "testing")
|
||||
assert.NilError(c, waitRun("testing"))
|
||||
|
@ -122,14 +122,14 @@ func (s *DockerSuite) TestExecSetEnv(c *check.C) {
|
|||
assert.Check(c, strings.Contains(out, "ABC=xyz"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecExitStatus(c *check.C) {
|
||||
func (s *DockerSuite) TestExecExitStatus(c *testing.T) {
|
||||
runSleepingContainer(c, "-d", "--name", "top")
|
||||
|
||||
result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
|
||||
result.Assert(c, icmd.Expected{ExitCode: 23, Error: "exit status 23"})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestExecPausedContainer(c *testing.T) {
|
||||
testRequires(c, IsPausable)
|
||||
|
||||
out := runSleepingContainer(c, "-d", "--name", "testing")
|
||||
|
@ -144,7 +144,7 @@ func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
|
|||
}
|
||||
|
||||
// regression test for #9476
|
||||
func (s *DockerSuite) TestExecTTYCloseStdin(c *check.C) {
|
||||
func (s *DockerSuite) TestExecTTYCloseStdin(c *testing.T) {
|
||||
// TODO Windows CI: This requires some work to port to Windows.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
|
||||
|
@ -165,7 +165,7 @@ func (s *DockerSuite) TestExecTTYCloseStdin(c *check.C) {
|
|||
assert.Assert(c, !strings.Contains(out, "nsenter-exec"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
|
||||
func (s *DockerSuite) TestExecTTYWithoutStdin(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
@ -202,7 +202,7 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
|
|||
}
|
||||
|
||||
// FIXME(vdemeester) this should be a unit tests on cli/command/container package
|
||||
func (s *DockerSuite) TestExecParseError(c *check.C) {
|
||||
func (s *DockerSuite) TestExecParseError(c *testing.T) {
|
||||
// TODO Windows CI: Requires some extra work. Consider copying the
|
||||
// runSleepingContainer helper to have an exec version.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -216,7 +216,7 @@ func (s *DockerSuite) TestExecParseError(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
|
||||
func (s *DockerSuite) TestExecStopNotHanging(c *testing.T) {
|
||||
// TODO Windows CI: Requires some extra work. Consider copying the
|
||||
// runSleepingContainer helper to have an exec version.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -244,7 +244,7 @@ func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecCgroup(c *check.C) {
|
||||
func (s *DockerSuite) TestExecCgroup(c *testing.T) {
|
||||
// Not applicable on Windows - using Linux specific functionality
|
||||
testRequires(c, NotUserNamespace)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -297,7 +297,7 @@ func (s *DockerSuite) TestExecCgroup(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecInspectID(c *check.C) {
|
||||
func (s *DockerSuite) TestExecInspectID(c *testing.T) {
|
||||
out := runSleepingContainer(c, "-d")
|
||||
id := strings.TrimSuffix(out, "\n")
|
||||
|
||||
|
@ -364,7 +364,7 @@ func (s *DockerSuite) TestExecInspectID(c *check.C) {
|
|||
assert.ErrorContains(c, err, "No such exec instance")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *testing.T) {
|
||||
// Problematic on Windows as Windows does not support links
|
||||
testRequires(c, DaemonIsLinux)
|
||||
var out string
|
||||
|
@ -380,7 +380,7 @@ func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {
|
|||
dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
|
||||
func (s *DockerSuite) TestRunMutableNetworkFiles(c *testing.T) {
|
||||
// Not applicable on Windows to Windows CI.
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
for _, fn := range []string{"resolv.conf", "hosts"} {
|
||||
|
@ -421,7 +421,7 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecWithUser(c *check.C) {
|
||||
func (s *DockerSuite) TestExecWithUser(c *testing.T) {
|
||||
// TODO Windows CI: This may be fixable in the future once Windows
|
||||
// supports users
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -434,7 +434,7 @@ func (s *DockerSuite) TestExecWithUser(c *check.C) {
|
|||
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 *check.C) {
|
||||
func (s *DockerSuite) TestExecWithPrivileged(c *testing.T) {
|
||||
// Not applicable on Windows
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
// Start main loop which attempts mknod repeatedly
|
||||
|
@ -464,7 +464,7 @@ func (s *DockerSuite) TestExecWithPrivileged(c *check.C) {
|
|||
assert.Assert(c, !strings.Contains(result.Combined(), "Success"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecWithImageUser(c *check.C) {
|
||||
func (s *DockerSuite) TestExecWithImageUser(c *testing.T) {
|
||||
// Not applicable on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testbuilduser"
|
||||
|
@ -477,7 +477,7 @@ func (s *DockerSuite) TestExecWithImageUser(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "dockerio"), "exec with user by id expected dockerio user got %s", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestExecOnReadonlyContainer(c *testing.T) {
|
||||
// Windows does not support read-only
|
||||
// --read-only + userns has remount issues
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
@ -485,7 +485,7 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
|
|||
dockerCmd(c, "exec", "parent", "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecUlimits(c *check.C) {
|
||||
func (s *DockerSuite) TestExecUlimits(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testexeculimits"
|
||||
runSleepingContainer(c, "-d", "--ulimit", "nofile=511:511", "--name", name)
|
||||
|
@ -497,7 +497,7 @@ func (s *DockerSuite) TestExecUlimits(c *check.C) {
|
|||
}
|
||||
|
||||
// #15750
|
||||
func (s *DockerSuite) TestExecStartFails(c *check.C) {
|
||||
func (s *DockerSuite) TestExecStartFails(c *testing.T) {
|
||||
// TODO Windows CI. This test should be portable. Figure out why it fails
|
||||
// currently.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -511,7 +511,7 @@ func (s *DockerSuite) TestExecStartFails(c *check.C) {
|
|||
}
|
||||
|
||||
// Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297
|
||||
func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) {
|
||||
func (s *DockerSuite) TestExecWindowsPathNotWiped(c *testing.T) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60")
|
||||
assert.NilError(c, waitRun(strings.TrimSpace(out)))
|
||||
|
@ -521,7 +521,7 @@ func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, `windowspowershell\v1.0`))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecEnvLinksHost(c *check.C) {
|
||||
func (s *DockerSuite) TestExecEnvLinksHost(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
runSleepingContainer(c, "-d", "--name", "foo")
|
||||
runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar")
|
||||
|
|
|
@ -7,15 +7,15 @@ import (
|
|||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// regression test for #12546
|
||||
func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
|
||||
func (s *DockerSuite) TestExecInteractiveStdinClose(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
|
||||
contID := strings.TrimSpace(out)
|
||||
|
@ -44,7 +44,7 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecTTY(c *check.C) {
|
||||
func (s *DockerSuite) TestExecTTY(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
dockerCmd(c, "run", "-d", "--name=test", "busybox", "sh", "-c", "echo hello > /foo && top")
|
||||
|
||||
|
@ -74,7 +74,7 @@ func (s *DockerSuite) TestExecTTY(c *check.C) {
|
|||
}
|
||||
|
||||
// Test the TERM env var is set when -t is provided on exec
|
||||
func (s *DockerSuite) TestExecWithTERM(c *check.C) {
|
||||
func (s *DockerSuite) TestExecWithTERM(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
out, _ := dockerCmd(c, "run", "-id", "busybox", "/bin/cat")
|
||||
contID := strings.TrimSpace(out)
|
||||
|
@ -86,7 +86,7 @@ func (s *DockerSuite) TestExecWithTERM(c *check.C) {
|
|||
|
||||
// Test that the TERM env var is not set on exec when -t is not provided, even if it was set
|
||||
// on run
|
||||
func (s *DockerSuite) TestExecWithNoTERM(c *check.C) {
|
||||
func (s *DockerSuite) TestExecWithNoTERM(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
|
||||
contID := strings.TrimSpace(out)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -13,26 +11,19 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
const volumePluginName = "test-external-volume-driver"
|
||||
|
||||
func init() {
|
||||
check.Suite(&DockerExternalVolumeSuite{
|
||||
ds: &DockerSuite{},
|
||||
})
|
||||
}
|
||||
|
||||
type eventCounter struct {
|
||||
activations int
|
||||
creations int
|
||||
|
@ -51,20 +42,20 @@ type DockerExternalVolumeSuite struct {
|
|||
*volumePlugin
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
s.ec = &eventCounter{}
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TearDownTest(c *testing.T) {
|
||||
if s.d != nil {
|
||||
s.d.Stop(c)
|
||||
s.ds.TearDownTest(c)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) SetUpSuite(c *testing.T) {
|
||||
s.volumePlugin = newVolumePlugin(c, volumePluginName)
|
||||
}
|
||||
|
||||
|
@ -86,7 +77,7 @@ func (p *volumePlugin) Close() {
|
|||
p.Server.Close()
|
||||
}
|
||||
|
||||
func newVolumePlugin(c *check.C, name string) *volumePlugin {
|
||||
func newVolumePlugin(c *testing.T, name string) *volumePlugin {
|
||||
mux := http.NewServeMux()
|
||||
s := &volumePlugin{Server: httptest.NewServer(mux), ec: &eventCounter{}, vols: make(map[string]vol)}
|
||||
|
||||
|
@ -276,62 +267,59 @@ func newVolumePlugin(c *check.C, name string) *volumePlugin {
|
|||
return s
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TearDownSuite(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TearDownSuite(c *testing.T) {
|
||||
s.volumePlugin.Close()
|
||||
|
||||
err := os.RemoveAll("/etc/docker/plugins")
|
||||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "test")
|
||||
|
||||
out, _, err := dockerCmdWithError("volume", "create", "test", "--driver", volumePluginName)
|
||||
c.Assert(err, check.NotNil, check.Commentf("volume create exception name already in use with another driver"))
|
||||
c.Assert(out, checker.Contains, "must be unique")
|
||||
|
||||
assert.Assert(c, err != nil, "volume create exception name already in use with another driver")
|
||||
assert.Assert(c, strings.Contains(out, "must be unique"))
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Driver }}", "test")
|
||||
_, _, err = dockerCmdWithError("volume", "create", "test", "--driver", strings.TrimSpace(out))
|
||||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
||||
assert.NilError(c, err, out)
|
||||
c.Assert(out, checker.Contains, s.Server.URL)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, s.Server.URL))
|
||||
_, err = s.d.Cmd("volume", "rm", "external-volume-test")
|
||||
assert.NilError(c, err)
|
||||
|
||||
p := hostVolumePath("external-volume-test")
|
||||
_, err = os.Lstat(p)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err))
|
||||
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("Expected volume path in host to not exist: %s, %v\n", p, err))
|
||||
|
||||
c.Assert(s.ec.activations, checker.Equals, 1)
|
||||
c.Assert(s.ec.creations, checker.Equals, 1)
|
||||
c.Assert(s.ec.removals, checker.Equals, 1)
|
||||
c.Assert(s.ec.mounts, checker.Equals, 1)
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
||||
assert.Equal(c, s.ec.activations, 1)
|
||||
assert.Equal(c, s.ec.creations, 1)
|
||||
assert.Equal(c, s.ec.removals, 1)
|
||||
assert.Equal(c, s.ec.mounts, 1)
|
||||
assert.Equal(c, s.ec.unmounts, 1)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
||||
assert.NilError(c, err, out)
|
||||
c.Assert(out, checker.Contains, s.Server.URL)
|
||||
|
||||
c.Assert(s.ec.activations, checker.Equals, 1)
|
||||
c.Assert(s.ec.creations, checker.Equals, 1)
|
||||
c.Assert(s.ec.removals, checker.Equals, 1)
|
||||
c.Assert(s.ec.mounts, checker.Equals, 1)
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
||||
assert.Assert(c, strings.Contains(out, s.Server.URL))
|
||||
assert.Equal(c, s.ec.activations, 1)
|
||||
assert.Equal(c, s.ec.creations, 1)
|
||||
assert.Equal(c, s.ec.removals, 1)
|
||||
assert.Equal(c, s.ec.mounts, 1)
|
||||
assert.Equal(c, s.ec.unmounts, 1)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest")
|
||||
|
@ -343,14 +331,14 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check
|
|||
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
c.Assert(s.ec.activations, checker.Equals, 1)
|
||||
c.Assert(s.ec.creations, checker.Equals, 1)
|
||||
c.Assert(s.ec.removals, checker.Equals, 1)
|
||||
c.Assert(s.ec.mounts, checker.Equals, 2)
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 2)
|
||||
assert.Equal(c, s.ec.activations, 1)
|
||||
assert.Equal(c, s.ec.creations, 1)
|
||||
assert.Equal(c, s.ec.removals, 1)
|
||||
assert.Equal(c, s.ec.mounts, 2)
|
||||
assert.Equal(c, s.ec.unmounts, 2)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest")
|
||||
|
@ -359,11 +347,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *c
|
|||
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
c.Assert(s.ec.activations, checker.Equals, 1)
|
||||
c.Assert(s.ec.creations, checker.Equals, 1)
|
||||
c.Assert(s.ec.removals, checker.Equals, 1)
|
||||
c.Assert(s.ec.mounts, checker.Equals, 1)
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
||||
assert.Equal(c, s.ec.activations, 1)
|
||||
assert.Equal(c, s.ec.creations, 1)
|
||||
assert.Equal(c, s.ec.removals, 1)
|
||||
assert.Equal(c, s.ec.mounts, 1)
|
||||
assert.Equal(c, s.ec.unmounts, 1)
|
||||
}
|
||||
|
||||
func hostVolumePath(name string) string {
|
||||
|
@ -371,7 +359,7 @@ func hostVolumePath(name string) string {
|
|||
}
|
||||
|
||||
// Make sure a request to use a down driver doesn't block other requests
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *testing.T) {
|
||||
specPath := "/etc/docker/plugins/down-driver.spec"
|
||||
err := ioutil.WriteFile(specPath, []byte("tcp://127.0.0.7:9999"), 0644)
|
||||
assert.NilError(c, err)
|
||||
|
@ -382,10 +370,10 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *
|
|||
cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver")
|
||||
cmd2 := exec.Command(dockerBinary, "volume", "create")
|
||||
|
||||
c.Assert(cmd1.Start(), checker.IsNil)
|
||||
assert.Assert(c, cmd1.Start() == nil)
|
||||
defer cmd1.Process.Kill()
|
||||
time.Sleep(100 * time.Millisecond) // ensure API has been called
|
||||
c.Assert(cmd2.Start(), checker.IsNil)
|
||||
assert.Assert(c, cmd2.Start() == nil)
|
||||
|
||||
go func() {
|
||||
cmd1.Wait()
|
||||
|
@ -407,7 +395,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
driverName := "test-external-volume-driver-retry"
|
||||
|
||||
|
@ -437,14 +425,14 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyE
|
|||
_, err := s.d.Cmd("volume", "rm", "external-volume-test")
|
||||
assert.NilError(c, err)
|
||||
|
||||
c.Assert(p.ec.activations, checker.Equals, 1)
|
||||
c.Assert(p.ec.creations, checker.Equals, 1)
|
||||
c.Assert(p.ec.removals, checker.Equals, 1)
|
||||
c.Assert(p.ec.mounts, checker.Equals, 1)
|
||||
c.Assert(p.ec.unmounts, checker.Equals, 1)
|
||||
assert.Equal(c, p.ec.activations, 1)
|
||||
assert.Equal(c, p.ec.creations, 1)
|
||||
assert.Equal(c, p.ec.removals, 1)
|
||||
assert.Equal(c, p.ec.mounts, 1)
|
||||
assert.Equal(c, p.ec.unmounts, 1)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "-d", volumePluginName, "foo")
|
||||
dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top")
|
||||
|
||||
|
@ -453,31 +441,31 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c
|
|||
Driver string
|
||||
}
|
||||
out := inspectFieldJSON(c, "testing", "Mounts")
|
||||
c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
|
||||
c.Assert(len(mounts), checker.Equals, 1, check.Commentf("%s", out))
|
||||
c.Assert(mounts[0].Name, checker.Equals, "foo")
|
||||
c.Assert(mounts[0].Driver, checker.Equals, volumePluginName)
|
||||
assert.Assert(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts) == nil)
|
||||
assert.Equal(c, len(mounts), 1, fmt.Sprintf("%s", out))
|
||||
assert.Equal(c, mounts[0].Name, "foo")
|
||||
assert.Equal(c, mounts[0].Driver, volumePluginName)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc3")
|
||||
out, _ := dockerCmd(c, "volume", "ls")
|
||||
ls := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(ls), check.Equals, 2, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(ls), 2, fmt.Sprintf("\n%s", out))
|
||||
|
||||
vol := strings.Fields(ls[len(ls)-1])
|
||||
c.Assert(len(vol), check.Equals, 2, check.Commentf("%v", vol))
|
||||
c.Assert(vol[0], check.Equals, volumePluginName)
|
||||
c.Assert(vol[1], check.Equals, "abc3")
|
||||
assert.Equal(c, len(vol), 2, fmt.Sprintf("%v", vol))
|
||||
assert.Equal(c, vol[0], volumePluginName)
|
||||
assert.Equal(c, vol[1], "abc3")
|
||||
|
||||
c.Assert(s.ec.lists, check.Equals, 1)
|
||||
assert.Equal(c, s.ec.lists, 1)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("volume", "inspect", "dummy")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
c.Assert(out, checker.Contains, "No such volume")
|
||||
c.Assert(s.ec.gets, check.Equals, 1)
|
||||
assert.Assert(c, strings.Contains(out, "No such volume"))
|
||||
assert.Equal(c, s.ec.gets, 1)
|
||||
|
||||
dockerCmd(c, "volume", "create", "test", "-d", volumePluginName)
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "test")
|
||||
|
@ -487,26 +475,26 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
|
|||
}
|
||||
var st []vol
|
||||
|
||||
c.Assert(json.Unmarshal([]byte(out), &st), checker.IsNil)
|
||||
c.Assert(st, checker.HasLen, 1)
|
||||
c.Assert(st[0].Status, checker.HasLen, 1, check.Commentf("%v", st[0]))
|
||||
c.Assert(st[0].Status["Hello"], checker.Equals, "world", check.Commentf("%v", st[0].Status))
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &st) == nil)
|
||||
assert.Equal(c, len(st), 1)
|
||||
assert.Equal(c, len(st[0].Status), 1, fmt.Sprintf("%v", st[0]))
|
||||
assert.Equal(c, st[0].Status["Hello"], "world", fmt.Sprintf("%v", st[0].Status))
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc1")
|
||||
s.d.Restart(c)
|
||||
|
||||
dockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true")
|
||||
var mounts []types.MountPoint
|
||||
inspectFieldAndUnmarshall(c, "test", "Mounts", &mounts)
|
||||
c.Assert(mounts, checker.HasLen, 1)
|
||||
c.Assert(mounts[0].Driver, checker.Equals, volumePluginName)
|
||||
assert.Equal(c, len(mounts), 1)
|
||||
assert.Equal(c, mounts[0].Driver, volumePluginName)
|
||||
}
|
||||
|
||||
// Ensures that the daemon handles when the plugin responds to a `Get` request with a null volume and a null error.
|
||||
// Prior the daemon would panic in this scenario.
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *testing.T) {
|
||||
s.d.Start(c)
|
||||
|
||||
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, "abc2", "--opt", "ninja=1")
|
||||
|
@ -514,27 +502,27 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *
|
|||
|
||||
out, err = s.d.Cmd("volume", "inspect", "abc2")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
c.Assert(out, checker.Contains, "No such volume")
|
||||
assert.Assert(c, strings.Contains(out, "No such volume"))
|
||||
}
|
||||
|
||||
// Ensure only cached paths are used in volume list to prevent N+1 calls to `VolumeDriver.Path`
|
||||
//
|
||||
// TODO(@cpuguy83): This test is testing internal implementation. In all the cases here, there may not even be a path
|
||||
// available because the volume is not even mounted. Consider removing this test.
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *testing.T) {
|
||||
s.d.Start(c)
|
||||
c.Assert(s.ec.paths, checker.Equals, 0)
|
||||
assert.Equal(c, s.ec.paths, 0)
|
||||
|
||||
out, err := s.d.Cmd("volume", "create", "test", "--driver=test-external-volume-driver")
|
||||
assert.NilError(c, err, out)
|
||||
c.Assert(s.ec.paths, checker.Equals, 0)
|
||||
assert.Equal(c, s.ec.paths, 0)
|
||||
|
||||
out, err = s.d.Cmd("volume", "ls")
|
||||
assert.NilError(c, err, out)
|
||||
c.Assert(s.ec.paths, checker.Equals, 0)
|
||||
assert.Equal(c, s.ec.paths, 0)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
out, err := s.d.Cmd("run", "--rm", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
||||
|
@ -543,21 +531,21 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *check.C)
|
|||
}
|
||||
|
||||
// Check that VolumeDriver.Capabilities gets called, and only called once
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *testing.T) {
|
||||
s.d.Start(c)
|
||||
c.Assert(s.ec.caps, checker.Equals, 0)
|
||||
assert.Equal(c, s.ec.caps, 0)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, fmt.Sprintf("test%d", i))
|
||||
assert.NilError(c, err, out)
|
||||
c.Assert(s.ec.caps, checker.Equals, 1)
|
||||
assert.Equal(c, s.ec.caps, 1)
|
||||
out, err = s.d.Cmd("volume", "inspect", "--format={{.Scope}}", fmt.Sprintf("test%d", i))
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, strings.TrimSpace(out), volume.GlobalScope)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *testing.T) {
|
||||
driverName := stringid.GenerateRandomID()
|
||||
p := newVolumePlugin(c, driverName)
|
||||
defer p.Close()
|
||||
|
@ -569,8 +557,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
|
|||
|
||||
out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
c.Assert(out, checker.Contains, "must be unique")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "must be unique"))
|
||||
// simulate out of band volume deletion on plugin level
|
||||
delete(p.vols, "test")
|
||||
|
||||
|
@ -583,11 +570,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
|
|||
var vs []types.Volume
|
||||
err = json.Unmarshal([]byte(out), &vs)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(vs, checker.HasLen, 1)
|
||||
c.Assert(vs[0].Driver, checker.Equals, driverName)
|
||||
c.Assert(vs[0].Options, checker.NotNil)
|
||||
c.Assert(vs[0].Options["foo"], checker.Equals, "bar")
|
||||
c.Assert(vs[0].Driver, checker.Equals, driverName)
|
||||
assert.Equal(c, len(vs), 1)
|
||||
assert.Equal(c, vs[0].Driver, driverName)
|
||||
assert.Assert(c, vs[0].Options != nil)
|
||||
assert.Equal(c, vs[0].Options["foo"], "bar")
|
||||
assert.Equal(c, vs[0].Driver, driverName)
|
||||
|
||||
// simulate out of band volume deletion on plugin level
|
||||
delete(p.vols, "test")
|
||||
|
@ -601,32 +588,32 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
|
|||
vs = nil
|
||||
err = json.Unmarshal([]byte(out), &vs)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(vs, checker.HasLen, 1)
|
||||
c.Assert(vs[0].Options, checker.HasLen, 0)
|
||||
c.Assert(vs[0].Driver, checker.Equals, "local")
|
||||
assert.Equal(c, len(vs), 1)
|
||||
assert.Equal(c, len(vs[0].Options), 0)
|
||||
assert.Equal(c, vs[0].Driver, "local")
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--opt=invalidOption=1", "--name=testumount")
|
||||
|
||||
out, _ := s.d.Cmd("run", "-v", "testumount:/foo", "busybox", "true")
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
|
||||
assert.Equal(c, s.ec.unmounts, 0, fmt.Sprintf("%s", out))
|
||||
out, _ = s.d.Cmd("run", "-w", "/foo", "-v", "testumount:/foo", "busybox", "true")
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
|
||||
assert.Equal(c, s.ec.unmounts, 0, fmt.Sprintf("%s", out))
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *check.C) {
|
||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--name=test")
|
||||
|
||||
out, _ := s.d.Cmd("run", "-d", "--name=test", "-v", "test:/foo", "busybox", "/bin/sh", "-c", "touch /test && top")
|
||||
c.Assert(s.ec.mounts, checker.Equals, 1, check.Commentf("%s", out))
|
||||
assert.Equal(c, s.ec.mounts, 1, fmt.Sprintf("%s", out))
|
||||
|
||||
out, _ = s.d.Cmd("cp", "test:/test", "/tmp/test")
|
||||
c.Assert(s.ec.mounts, checker.Equals, 2, check.Commentf("%s", out))
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 1, check.Commentf("%s", out))
|
||||
assert.Equal(c, s.ec.mounts, 2, fmt.Sprintf("%s", out))
|
||||
assert.Equal(c, s.ec.unmounts, 1, fmt.Sprintf("%s", out))
|
||||
|
||||
out, _ = s.d.Cmd("kill", "test")
|
||||
c.Assert(s.ec.unmounts, checker.Equals, 2, check.Commentf("%s", out))
|
||||
assert.Equal(c, s.ec.unmounts, 2, fmt.Sprintf("%s", out))
|
||||
}
|
|
@ -4,15 +4,15 @@ import (
|
|||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func waitForHealthStatus(c *check.C, name string, prev string, expected string) {
|
||||
func waitForHealthStatus(c *testing.T, name string, prev string, expected string) {
|
||||
prev = prev + "\n"
|
||||
expected = expected + "\n"
|
||||
for {
|
||||
|
@ -20,7 +20,7 @@ func waitForHealthStatus(c *check.C, name string, prev string, expected string)
|
|||
if out == expected {
|
||||
return
|
||||
}
|
||||
c.Check(out, checker.Equals, prev)
|
||||
assert.Equal(c, out, prev)
|
||||
if out != prev {
|
||||
return
|
||||
}
|
||||
|
@ -28,15 +28,15 @@ func waitForHealthStatus(c *check.C, name string, prev string, expected string)
|
|||
}
|
||||
}
|
||||
|
||||
func getHealth(c *check.C, name string) *types.Health {
|
||||
func getHealth(c *testing.T, name string) *types.Health {
|
||||
out, _ := dockerCmd(c, "inspect", "--format={{json .State.Health}}", name)
|
||||
var health types.Health
|
||||
err := json.Unmarshal([]byte(out), &health)
|
||||
c.Check(err, checker.Equals, nil)
|
||||
assert.Equal(c, err, nil)
|
||||
return &health
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestHealth(c *check.C) {
|
||||
func (s *DockerSuite) TestHealth(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
@ -54,12 +54,12 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
cid, _ := dockerCmd(c, "create", "--name", name, imageName)
|
||||
out, _ := dockerCmd(c, "ps", "-a", "--format={{.ID}} {{.Status}}")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
c.Check(out, checker.Equals, cid[:12]+" Created\n")
|
||||
assert.Equal(c, out, cid[:12]+" Created\n")
|
||||
|
||||
// Inspect the options
|
||||
out, _ = dockerCmd(c, "inspect",
|
||||
"--format=timeout={{.Config.Healthcheck.Timeout}} interval={{.Config.Healthcheck.Interval}} retries={{.Config.Healthcheck.Retries}} test={{.Config.Healthcheck.Test}}", name)
|
||||
c.Check(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n")
|
||||
assert.Equal(c, out, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n")
|
||||
|
||||
// Start
|
||||
dockerCmd(c, "start", name)
|
||||
|
@ -71,7 +71,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
|
||||
// Inspect the status
|
||||
out, _ = dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
|
||||
c.Check(out, checker.Equals, "unhealthy\n")
|
||||
assert.Equal(c, out, "unhealthy\n")
|
||||
|
||||
// Make it healthy again
|
||||
dockerCmd(c, "exec", name, "touch", "/status")
|
||||
|
@ -83,7 +83,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
// Disable the check from the CLI
|
||||
dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName)
|
||||
out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "noh")
|
||||
c.Check(out, checker.Equals, "[NONE]\n")
|
||||
assert.Equal(c, out, "[NONE]\n")
|
||||
dockerCmd(c, "rm", "noh")
|
||||
|
||||
// Disable the check with a new build
|
||||
|
@ -91,7 +91,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
HEALTHCHECK NONE`))
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "no_healthcheck")
|
||||
c.Check(out, checker.Equals, "[NONE]\n")
|
||||
assert.Equal(c, out, "[NONE]\n")
|
||||
|
||||
// Enable the checks from the CLI
|
||||
_, _ = dockerCmd(c, "run", "-d", "--name=fatal_healthcheck",
|
||||
|
@ -101,11 +101,11 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
"no_healthcheck")
|
||||
waitForHealthStatus(c, "fatal_healthcheck", "starting", "healthy")
|
||||
health := getHealth(c, "fatal_healthcheck")
|
||||
c.Check(health.Status, checker.Equals, "healthy")
|
||||
c.Check(health.FailingStreak, checker.Equals, 0)
|
||||
assert.Equal(c, health.Status, "healthy")
|
||||
assert.Equal(c, health.FailingStreak, 0)
|
||||
last := health.Log[len(health.Log)-1]
|
||||
c.Check(last.ExitCode, checker.Equals, 0)
|
||||
c.Check(last.Output, checker.Equals, "OK\n")
|
||||
assert.Equal(c, last.ExitCode, 0)
|
||||
assert.Equal(c, last.Output, "OK\n")
|
||||
|
||||
// Fail the check
|
||||
dockerCmd(c, "exec", "fatal_healthcheck", "rm", "/status")
|
||||
|
@ -113,8 +113,8 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
|
||||
failsStr, _ := dockerCmd(c, "inspect", "--format={{.State.Health.FailingStreak}}", "fatal_healthcheck")
|
||||
fails, err := strconv.Atoi(strings.TrimSpace(failsStr))
|
||||
c.Check(err, check.IsNil)
|
||||
c.Check(fails >= 3, checker.Equals, true)
|
||||
assert.Assert(c, err == nil)
|
||||
assert.Equal(c, fails >= 3, true)
|
||||
dockerCmd(c, "rm", "-f", "fatal_healthcheck")
|
||||
|
||||
// Check timeout
|
||||
|
@ -125,9 +125,9 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
waitForHealthStatus(c, "test", "starting", "unhealthy")
|
||||
health = getHealth(c, "test")
|
||||
last = health.Log[len(health.Log)-1]
|
||||
c.Check(health.Status, checker.Equals, "unhealthy")
|
||||
c.Check(last.ExitCode, checker.Equals, -1)
|
||||
c.Check(last.Output, checker.Equals, "Health check exceeded timeout (1s)")
|
||||
assert.Equal(c, health.Status, "unhealthy")
|
||||
assert.Equal(c, last.ExitCode, -1)
|
||||
assert.Equal(c, last.Output, "Health check exceeded timeout (1s)")
|
||||
dockerCmd(c, "rm", "-f", "test")
|
||||
|
||||
// Check JSON-format
|
||||
|
@ -139,12 +139,12 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
CMD ["cat", "/my status"]`))
|
||||
out, _ = dockerCmd(c, "inspect",
|
||||
"--format={{.Config.Healthcheck.Test}}", imageName)
|
||||
c.Check(out, checker.Equals, "[CMD cat /my status]\n")
|
||||
assert.Equal(c, out, "[CMD cat /my status]\n")
|
||||
|
||||
}
|
||||
|
||||
// GitHub #33021
|
||||
func (s *DockerSuite) TestUnsetEnvVarHealthCheck(c *check.C) {
|
||||
func (s *DockerSuite) TestUnsetEnvVarHealthCheck(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
imageName := "testhealth"
|
||||
|
|
|
@ -5,15 +5,16 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
// This is a heisen-test. Because the created timestamp of images and the behavior of
|
||||
// sort is not predictable it doesn't always fail.
|
||||
func (s *DockerSuite) TestBuildHistory(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildHistory(c *testing.T) {
|
||||
name := "testbuildhistory"
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL label.A="A"
|
||||
|
@ -50,21 +51,21 @@ LABEL label.Z="Z"`))
|
|||
for i := 0; i < 26; i++ {
|
||||
echoValue := fmt.Sprintf("LABEL label.%s=%s", expectedValues[i], expectedValues[i])
|
||||
actualValue := actualValues[i]
|
||||
c.Assert(actualValue, checker.Contains, echoValue)
|
||||
assert.Assert(c, strings.Contains(actualValue, echoValue))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
|
||||
func (s *DockerSuite) TestHistoryExistentImage(c *testing.T) {
|
||||
dockerCmd(c, "history", "busybox")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
|
||||
func (s *DockerSuite) TestHistoryNonExistentImage(c *testing.T) {
|
||||
_, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestHistoryImageWithComment(c *testing.T) {
|
||||
name := "testhistoryimagewithcomment"
|
||||
|
||||
// make an image through docker commit <container id> [ -m messages ]
|
||||
|
@ -80,10 +81,10 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
|
|||
out, _ := dockerCmd(c, "history", name)
|
||||
outputTabs := strings.Fields(strings.Split(out, "\n")[1])
|
||||
actualValue := outputTabs[len(outputTabs)-1]
|
||||
c.Assert(actualValue, checker.Contains, comment)
|
||||
assert.Assert(c, strings.Contains(actualValue, comment))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
|
||||
func (s *DockerSuite) TestHistoryHumanOptionFalse(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "history", "--human=false", "busybox")
|
||||
lines := strings.Split(out, "\n")
|
||||
sizeColumnRegex, _ := regexp.Compile("SIZE +")
|
||||
|
@ -97,11 +98,11 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
|
|||
sizeString := lines[i][startIndex:endIndex]
|
||||
|
||||
_, err := strconv.Atoi(strings.TrimSpace(sizeString))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("The size '%s' was not an Integer", sizeString))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("The size '%s' was not an Integer", sizeString))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
|
||||
func (s *DockerSuite) TestHistoryHumanOptionTrue(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "history", "--human=true", "busybox")
|
||||
lines := strings.Split(out, "\n")
|
||||
sizeColumnRegex, _ := regexp.Compile("SIZE +")
|
||||
|
@ -114,6 +115,7 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
|
|||
endIndex = len(lines[i])
|
||||
}
|
||||
sizeString := lines[i][startIndex:endIndex]
|
||||
c.Assert(strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString))
|
||||
assert.Assert(c, cmp.Regexp("^"+humanSizeRegexRaw+"$",
|
||||
strings.TrimSpace(sizeString)), fmt.Sprintf("The size '%s' was not in human format", sizeString))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,47 +8,45 @@ import (
|
|||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *testing.T) {
|
||||
imagesOut, _ := dockerCmd(c, "images")
|
||||
c.Assert(imagesOut, checker.Contains, "busybox")
|
||||
assert.Assert(c, strings.Contains(imagesOut, "busybox"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *testing.T) {
|
||||
name := "imagewithtag"
|
||||
dockerCmd(c, "tag", "busybox", name+":v1")
|
||||
dockerCmd(c, "tag", "busybox", name+":v1v1")
|
||||
dockerCmd(c, "tag", "busybox", name+":v2")
|
||||
|
||||
imagesOut, _ := dockerCmd(c, "images", name+":v1")
|
||||
c.Assert(imagesOut, checker.Contains, name)
|
||||
c.Assert(imagesOut, checker.Contains, "v1")
|
||||
c.Assert(imagesOut, checker.Not(checker.Contains), "v2")
|
||||
c.Assert(imagesOut, checker.Not(checker.Contains), "v1v1")
|
||||
|
||||
assert.Assert(c, strings.Contains(imagesOut, name))
|
||||
assert.Assert(c, strings.Contains(imagesOut, "v1"))
|
||||
assert.Assert(c, !strings.Contains(imagesOut, "v2"))
|
||||
assert.Assert(c, !strings.Contains(imagesOut, "v1v1"))
|
||||
imagesOut, _ = dockerCmd(c, "images", name)
|
||||
c.Assert(imagesOut, checker.Contains, name)
|
||||
c.Assert(imagesOut, checker.Contains, "v1")
|
||||
c.Assert(imagesOut, checker.Contains, "v1v1")
|
||||
c.Assert(imagesOut, checker.Contains, "v2")
|
||||
assert.Assert(c, strings.Contains(imagesOut, name))
|
||||
assert.Assert(c, strings.Contains(imagesOut, "v1"))
|
||||
assert.Assert(c, strings.Contains(imagesOut, "v1v1"))
|
||||
assert.Assert(c, strings.Contains(imagesOut, "v2"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *testing.T) {
|
||||
imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent")
|
||||
c.Assert(imagesOut, checker.Not(checker.Contains), "busybox")
|
||||
assert.Assert(c, !strings.Contains(imagesOut, "busybox"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *testing.T) {
|
||||
buildImageSuccessfully(c, "order:test_a", build.WithDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio1`))
|
||||
id1 := getIDByName(c, "order:test_a")
|
||||
|
@ -63,18 +61,18 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
|
||||
imgs := strings.Split(out, "\n")
|
||||
c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
|
||||
c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
|
||||
c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
|
||||
assert.Equal(c, imgs[0], id3, fmt.Sprintf("First image must be %s, got %s", id3, imgs[0]))
|
||||
assert.Equal(c, imgs[1], id2, fmt.Sprintf("First image must be %s, got %s", id2, imgs[1]))
|
||||
assert.Equal(c, imgs[2], id1, fmt.Sprintf("First image must be %s, got %s", id1, imgs[2]))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Invalid filter")
|
||||
assert.Assert(c, strings.Contains(out, "Invalid filter"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFilterLabelMatch(c *testing.T) {
|
||||
imageName1 := "images_filter_test1"
|
||||
imageName2 := "images_filter_test2"
|
||||
imageName3 := "images_filter_test3"
|
||||
|
@ -92,9 +90,11 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
|
||||
out = strings.TrimSpace(out)
|
||||
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID))
|
||||
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID))
|
||||
c.Assert(out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID))
|
||||
assert.Assert(c, is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image1ID), out))
|
||||
|
||||
assert.Assert(c, is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image2ID), out))
|
||||
|
||||
assert.Assert(c, !is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image3ID), out)().Success())
|
||||
|
||||
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
|
||||
out = strings.TrimSpace(out)
|
||||
|
@ -102,7 +102,7 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
|||
}
|
||||
|
||||
// Regression : #15659
|
||||
func (s *DockerSuite) TestCommitWithFilterLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestCommitWithFilterLabel(c *testing.T) {
|
||||
// Create a container
|
||||
dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh")
|
||||
// Commit with labels "using changes"
|
||||
|
@ -114,7 +114,7 @@ func (s *DockerSuite) TestCommitWithFilterLabel(c *check.C) {
|
|||
assert.Equal(c, out, imageID)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *testing.T) {
|
||||
buildImageSuccessfully(c, "image:1", build.WithDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL number=1`))
|
||||
imageID1 := getIDByName(c, "image:1")
|
||||
|
@ -128,34 +128,34 @@ LABEL number=3`))
|
|||
expected := []string{imageID3, imageID2}
|
||||
|
||||
out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
expected = []string{imageID3}
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "since=image:2", "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
expected = []string{imageID2, imageID1}
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "before=image:3", "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
expected = []string{imageID1}
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "before=image:2", "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image")
|
||||
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
|
||||
}
|
||||
|
||||
func assertImageList(out string, expected []string) bool {
|
||||
|
@ -184,7 +184,7 @@ func assertImageList(out string, expected []string) bool {
|
|||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test on `docker image ls`
|
||||
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *testing.T) {
|
||||
imageName := "images_filter_test"
|
||||
// Build a image and fail to build so that we have dangling images ?
|
||||
buildImage(imageName, build.WithDockerfile(`FROM busybox
|
||||
|
@ -224,7 +224,7 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// create container 1
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
@ -239,26 +239,24 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
|||
|
||||
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
|
||||
// Expect one dangling image
|
||||
c.Assert(strings.Count(out, imageID), checker.Equals, 1)
|
||||
assert.Equal(c, strings.Count(out, imageID), 1)
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
|
||||
//dangling=false would not include dangling images
|
||||
c.Assert(out, checker.Not(checker.Contains), imageID)
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, imageID))
|
||||
out, _ = dockerCmd(c, "images")
|
||||
//docker images still include dangling images
|
||||
c.Assert(out, checker.Contains, imageID)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, imageID))
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test for `docker image ls`
|
||||
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Invalid filter")
|
||||
assert.Assert(c, strings.Contains(out, "Invalid filter"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *testing.T) {
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
MAINTAINER docker
|
||||
|
@ -276,12 +274,12 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images shouldn't show non-heads images
|
||||
c.Assert(out, checker.Not(checker.Contains), intermediate)
|
||||
assert.Assert(c, !strings.Contains(out, intermediate))
|
||||
// images should contain final built images
|
||||
c.Assert(out, checker.Contains, stringid.TruncateID(id))
|
||||
assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch
|
||||
dockerfile := `
|
||||
FROM scratch
|
||||
|
@ -293,12 +291,12 @@ func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images should contain images built from scratch
|
||||
c.Assert(out, checker.Contains, stringid.TruncateID(id))
|
||||
assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
|
||||
}
|
||||
|
||||
// For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows
|
||||
// doesn't support from scratch
|
||||
func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *testing.T) {
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
MAINTAINER docker`
|
||||
|
@ -309,24 +307,22 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images should contain images built from busybox
|
||||
c.Assert(out, checker.Contains, stringid.TruncateID(id))
|
||||
assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
|
||||
}
|
||||
|
||||
// #18181
|
||||
func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFilterNameWithPort(c *testing.T) {
|
||||
tag := "a.b.c.d:5000/hello"
|
||||
dockerCmd(c, "tag", "busybox", tag)
|
||||
out, _ := dockerCmd(c, "images", tag)
|
||||
c.Assert(out, checker.Contains, tag)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, tag))
|
||||
out, _ = dockerCmd(c, "images", tag+":latest")
|
||||
c.Assert(out, checker.Contains, tag)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, tag))
|
||||
out, _ = dockerCmd(c, "images", tag+":no-such-tag")
|
||||
c.Assert(out, checker.Not(checker.Contains), tag)
|
||||
assert.Assert(c, !strings.Contains(out, tag))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFormat(c *testing.T) {
|
||||
// testRequires(c, DaemonIsLinux)
|
||||
tag := "myimage"
|
||||
dockerCmd(c, "tag", "busybox", tag+":v1")
|
||||
|
@ -342,7 +338,7 @@ func (s *DockerSuite) TestImagesFormat(c *check.C) {
|
|||
}
|
||||
|
||||
// ImagesDefaultFormatAndQuiet
|
||||
func (s *DockerSuite) TestImagesFormatDefaultFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestImagesFormatDefaultFormat(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
// create container 1
|
||||
|
|
|
@ -8,15 +8,14 @@ import (
|
|||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
||||
func (s *DockerSuite) TestImportDisplay(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -34,9 +33,9 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
|||
assert.Equal(c, out, "", "command output should've been nothing.")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportBadURL(c *check.C) {
|
||||
func (s *DockerSuite) TestImportBadURL(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("import", "http://nourl/bad")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("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
|
||||
if !strings.Contains(out, "dial tcp") &&
|
||||
!strings.Contains(out, "ApplyLayer exit status 1 stdout: stderr: archive/tar: invalid tar header") &&
|
||||
|
@ -45,12 +44,12 @@ func (s *DockerSuite) TestImportBadURL(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportFile(c *check.C) {
|
||||
func (s *DockerSuite) TestImportFile(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
|
||||
|
||||
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
assert.Assert(c, err == nil, "failed to create temporary file")
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
|
@ -66,12 +65,12 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
|
|||
assert.Equal(c, out, "", "command output should've been nothing.")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportGzipped(c *check.C) {
|
||||
func (s *DockerSuite) TestImportGzipped(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
|
||||
|
||||
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
assert.Assert(c, err == nil, "failed to create temporary file")
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
w := gzip.NewWriter(temporaryFile)
|
||||
|
@ -79,7 +78,7 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
|
|||
Command: []string{dockerBinary, "export", "test-import"},
|
||||
Stdout: w,
|
||||
}).Assert(c, icmd.Success)
|
||||
c.Assert(w.Close(), checker.IsNil, check.Commentf("failed to close gzip writer"))
|
||||
assert.Assert(c, w.Close() == nil, "failed to close gzip writer")
|
||||
temporaryFile.Close()
|
||||
out, _ := dockerCmd(c, "import", temporaryFile.Name())
|
||||
assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")
|
||||
|
@ -89,12 +88,12 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
|
|||
assert.Equal(c, out, "", "command output should've been nothing.")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
||||
func (s *DockerSuite) TestImportFileWithMessage(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
|
||||
|
||||
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
assert.Assert(c, err == nil, "failed to create temporary file")
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
|
@ -110,27 +109,27 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
|||
out, _ = dockerCmd(c, "history", image)
|
||||
split := strings.Split(out, "\n")
|
||||
|
||||
c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
|
||||
assert.Equal(c, len(split), 3, "expected 3 lines from image history")
|
||||
r := regexp.MustCompile("[\\s]{2,}")
|
||||
split = r.Split(split[1], -1)
|
||||
|
||||
c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message"))
|
||||
assert.Equal(c, message, split[3], "didn't get expected value in commit message")
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--rm", image, "true")
|
||||
assert.Equal(c, out, "", "command output should've been nothing")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
|
||||
func (s *DockerSuite) TestImportFileNonExistentFile(c *testing.T) {
|
||||
_, _, err := dockerCmdWithError("import", "example.com/myImage.tar")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("import non-existing file must failed"))
|
||||
assert.Assert(c, err != nil, "import non-existing file must failed")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) {
|
||||
func (s *DockerSuite) TestImportWithQuotedChanges(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
cli.DockerCmd(c, "run", "--name", "test-import", "busybox", "true")
|
||||
|
||||
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
assert.Assert(c, err == nil, "failed to create temporary file")
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(bufio.NewWriter(temporaryFile))).Assert(c, icmd.Success)
|
||||
|
|
|
@ -5,16 +5,15 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// ensure docker info succeeds
|
||||
func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "info")
|
||||
|
||||
// always shown fields
|
||||
|
@ -53,14 +52,14 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
|
|||
}
|
||||
|
||||
for _, linePrefix := range stringsToCheck {
|
||||
c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
|
||||
assert.Assert(c, strings.Contains(out, linePrefix), fmt.Sprintf("couldn't find string %v in output", linePrefix))
|
||||
}
|
||||
}
|
||||
|
||||
// TestInfoFormat tests `docker info --format`
|
||||
func (s *DockerSuite) TestInfoFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoFormat(c *testing.T) {
|
||||
out, status := dockerCmd(c, "info", "--format", "{{json .}}")
|
||||
c.Assert(status, checker.Equals, 0)
|
||||
assert.Equal(c, status, 0)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(out), &m)
|
||||
assert.NilError(c, err)
|
||||
|
@ -70,7 +69,7 @@ func (s *DockerSuite) TestInfoFormat(c *check.C) {
|
|||
|
||||
// TestInfoDiscoveryBackend verifies that a daemon run with `--cluster-advertise` and
|
||||
// `--cluster-store` properly show the backend's endpoint in info output.
|
||||
func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDiscoveryBackend(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
|
@ -81,13 +80,13 @@ func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
|
|||
|
||||
out, err := d.Cmd("info")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise)))
|
||||
}
|
||||
|
||||
// TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
|
||||
// an invalid `--cluster-advertise` configuration
|
||||
func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
|
@ -104,7 +103,7 @@ func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
|
|||
|
||||
// TestInfoDiscoveryAdvertiseInterfaceName verifies that a daemon run with `--cluster-advertise`
|
||||
// configured with interface name properly show the advertise ip-address in info output.
|
||||
func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, Network, DaemonIsLinux)
|
||||
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
|
@ -124,24 +123,24 @@ func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
|
|||
|
||||
out, err := d.Cmd("info")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String()))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String())))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
existing := existingContainerStates(c)
|
||||
|
||||
dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
out, _ := dockerCmd(c, "info")
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *testing.T) {
|
||||
testRequires(c, IsPausable)
|
||||
|
||||
existing := existingContainerStates(c)
|
||||
|
@ -152,13 +151,13 @@ func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
|||
dockerCmd(c, "pause", cleanedContainerID)
|
||||
|
||||
out, _ = dockerCmd(c, "info")
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
existing := existingContainerStates(c)
|
||||
|
@ -169,13 +168,13 @@ func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
|||
dockerCmd(c, "stop", cleanedContainerID)
|
||||
|
||||
out, _ = dockerCmd(c, "info")
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1)))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoDebug(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
|
@ -184,16 +183,16 @@ func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
|||
|
||||
out, err := d.Cmd("--debug", "info")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, "Debug Mode (client): true\n")
|
||||
c.Assert(out, checker.Contains, "Debug Mode (server): true\n")
|
||||
c.Assert(out, checker.Contains, "File Descriptors")
|
||||
c.Assert(out, checker.Contains, "Goroutines")
|
||||
c.Assert(out, checker.Contains, "System Time")
|
||||
c.Assert(out, checker.Contains, "EventsListeners")
|
||||
c.Assert(out, checker.Contains, "Docker Root Dir")
|
||||
assert.Assert(c, strings.Contains(out, "Debug Mode (client): true\n"))
|
||||
assert.Assert(c, strings.Contains(out, "Debug Mode (server): true\n"))
|
||||
assert.Assert(c, strings.Contains(out, "File Descriptors"))
|
||||
assert.Assert(c, strings.Contains(out, "Goroutines"))
|
||||
assert.Assert(c, strings.Contains(out, "System Time"))
|
||||
assert.Assert(c, strings.Contains(out, "EventsListeners"))
|
||||
assert.Assert(c, strings.Contains(out, "Docker Root Dir"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
|
||||
func (s *DockerSuite) TestInsecureRegistries(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
registryCIDR := "192.168.1.0/24"
|
||||
|
@ -205,12 +204,12 @@ func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
|
|||
|
||||
out, err := d.Cmd("info")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, "Insecure Registries:\n")
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
|
||||
assert.Assert(c, strings.Contains(out, "Insecure Registries:\n"))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" %s\n", registryHost)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" %s\n", registryCIDR)))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestRegistryMirrors(c *testing.T) {
|
||||
|
||||
registryMirror1 := "https://192.168.1.2"
|
||||
registryMirror2 := "http://registry.mirror.com:5000"
|
||||
|
@ -219,12 +218,12 @@ func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("info")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, "Registry Mirrors:\n")
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror1))
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror2))
|
||||
assert.Assert(c, strings.Contains(out, "Registry Mirrors:\n"))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" %s", registryMirror1)))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" %s", registryMirror2)))
|
||||
}
|
||||
|
||||
func existingContainerStates(c *check.C) map[string]int {
|
||||
func existingContainerStates(c *testing.T) map[string]int {
|
||||
out, _ := dockerCmd(c, "info", "--format", "{{json .}}")
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(out), &m)
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestInfoSecurityOptions(c *check.C) {
|
||||
func (s *DockerSuite) TestInfoSecurityOptions(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, Apparmor, DaemonIsLinux)
|
||||
|
||||
out, _ := dockerCmd(c, "info")
|
||||
c.Assert(out, checker.Contains, "Security Options:\n apparmor\n seccomp\n Profile: default\n")
|
||||
assert.Assert(c, strings.Contains(out, "Security Options:\n apparmor\n seccomp\n Profile: default\n"))
|
||||
}
|
||||
|
|
|
@ -6,23 +6,22 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func checkValidGraphDriver(c *check.C, name string) {
|
||||
func checkValidGraphDriver(c *testing.T, name string) {
|
||||
if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" {
|
||||
c.Fatalf("%v is not a valid graph driver name", name)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectImage(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectImage(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
imageTest := "emptyfs"
|
||||
// It is important that this ID remain stable. If a code change causes
|
||||
|
@ -33,16 +32,16 @@ func (s *DockerSuite) TestInspectImage(c *check.C) {
|
|||
imageTestID := "sha256:11f64303f0f7ffdc71f001788132bca5346831939a956e3e975c93267d89a16d"
|
||||
id := inspectField(c, imageTest, "Id")
|
||||
|
||||
c.Assert(id, checker.Equals, imageTestID)
|
||||
assert.Equal(c, id, imageTestID)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectInt64(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectInt64(c *testing.T) {
|
||||
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
|
||||
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
|
||||
c.Assert(inspectOut, checker.Equals, "314572800")
|
||||
assert.Equal(c, inspectOut, "314572800")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectDefault(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectDefault(c *testing.T) {
|
||||
//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.
|
||||
|
||||
|
@ -50,35 +49,35 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
|
|||
containerID := strings.TrimSpace(out)
|
||||
|
||||
inspectOut := inspectField(c, "busybox", "Id")
|
||||
c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID)
|
||||
assert.Equal(c, strings.TrimSpace(inspectOut), containerID)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectStatus(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectStatus(c *testing.T) {
|
||||
out := runSleepingContainer(c, "-d")
|
||||
out = strings.TrimSpace(out)
|
||||
|
||||
inspectOut := inspectField(c, out, "State.Status")
|
||||
c.Assert(inspectOut, checker.Equals, "running")
|
||||
assert.Equal(c, inspectOut, "running")
|
||||
|
||||
// Windows does not support pause/unpause on Windows Server Containers.
|
||||
// (RS1 does for Hyper-V Containers, but production CI is not setup for that)
|
||||
if testEnv.OSType != "windows" {
|
||||
dockerCmd(c, "pause", out)
|
||||
inspectOut = inspectField(c, out, "State.Status")
|
||||
c.Assert(inspectOut, checker.Equals, "paused")
|
||||
assert.Equal(c, inspectOut, "paused")
|
||||
|
||||
dockerCmd(c, "unpause", out)
|
||||
inspectOut = inspectField(c, out, "State.Status")
|
||||
c.Assert(inspectOut, checker.Equals, "running")
|
||||
assert.Equal(c, inspectOut, "running")
|
||||
}
|
||||
|
||||
dockerCmd(c, "stop", out)
|
||||
inspectOut = inspectField(c, out, "State.Status")
|
||||
c.Assert(inspectOut, checker.Equals, "exited")
|
||||
assert.Equal(c, inspectOut, "exited")
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTypeFlagContainer(c *testing.T) {
|
||||
//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.
|
||||
runSleepingContainer(c, "--name=busybox", "-d")
|
||||
|
@ -88,7 +87,7 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
|
|||
assert.Equal(c, out, "true\n") // not a container JSON
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) {
|
||||
//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
|
||||
//not try to get the image JSON. It will throw an error.
|
||||
|
@ -100,7 +99,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
|
|||
assert.ErrorContains(c, err, "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithImage(c *testing.T) {
|
||||
//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
|
||||
//will throw an error.
|
||||
|
@ -108,38 +107,39 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
|
|||
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
||||
|
||||
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
|
||||
c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON
|
||||
// not an image JSON
|
||||
assert.Assert(c, !strings.Contains(out, "State"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
|
||||
//Both the container and image are named busybox. docker inspect will fail
|
||||
//as --type=foobar is not a valid value for the flag.
|
||||
|
||||
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
||||
|
||||
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("%s", exitCode))
|
||||
c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err))
|
||||
c.Assert(out, checker.Contains, "not a valid value for --type")
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("%d", exitCode))
|
||||
assert.Equal(c, exitCode, 1, fmt.Sprintf("%s", err))
|
||||
assert.Assert(c, strings.Contains(out, "not a valid value for --type"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectImageFilterInt(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
imageTest := "emptyfs"
|
||||
out := inspectField(c, imageTest, "Size")
|
||||
|
||||
size, err := strconv.Atoi(out)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect size of the image: %s, %v", out, err))
|
||||
|
||||
//now see if the size turns out to be the same
|
||||
formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size)
|
||||
out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
|
||||
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
||||
assert.NilError(c, err)
|
||||
c.Assert(result, checker.Equals, true)
|
||||
assert.Equal(c, result, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectContainerFilterInt(c *testing.T) {
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
|
||||
Stdin: strings.NewReader("blahblah"),
|
||||
|
@ -151,17 +151,17 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
|||
out = inspectField(c, id, "State.ExitCode")
|
||||
|
||||
exitCode, err := strconv.Atoi(out)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect exitcode of the container: %s, %v", out, err))
|
||||
|
||||
//now get the exit code to verify
|
||||
formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
|
||||
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
||||
inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
||||
assert.NilError(c, err)
|
||||
c.Assert(inspectResult, checker.Equals, true)
|
||||
assert.Equal(c, inspectResult, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectImageGraphDriver(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, Devicemapper)
|
||||
imageTest := "emptyfs"
|
||||
name := inspectField(c, imageTest, "GraphDriver.Name")
|
||||
|
@ -171,15 +171,15 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
|
|||
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
|
||||
|
||||
_, err := strconv.Atoi(deviceID)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
||||
|
||||
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
|
||||
|
||||
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectContainerGraphDriver(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, Devicemapper)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
@ -193,18 +193,18 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
|
|||
|
||||
deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId")
|
||||
|
||||
c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)
|
||||
assert.Assert(c, imageDeviceID != deviceID)
|
||||
|
||||
_, err := strconv.Atoi(deviceID)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
||||
|
||||
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
|
||||
|
||||
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectBindMountPoint(c *testing.T) {
|
||||
modifier := ",z"
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
if testEnv.OSType == "windows" {
|
||||
|
@ -222,21 +222,21 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
// check that there is only one mountpoint
|
||||
c.Assert(mp, check.HasLen, 1)
|
||||
assert.Equal(c, len(mp), 1)
|
||||
|
||||
m := mp[0]
|
||||
|
||||
c.Assert(m.Name, checker.Equals, "")
|
||||
c.Assert(m.Driver, checker.Equals, "")
|
||||
c.Assert(m.Source, checker.Equals, prefix+slash+"data")
|
||||
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
|
||||
assert.Equal(c, m.Name, "")
|
||||
assert.Equal(c, m.Driver, "")
|
||||
assert.Equal(c, m.Source, prefix+slash+"data")
|
||||
assert.Equal(c, m.Destination, prefix+slash+"data")
|
||||
if testEnv.OSType != "windows" { // Windows does not set mode
|
||||
c.Assert(m.Mode, checker.Equals, "ro"+modifier)
|
||||
assert.Equal(c, m.Mode, "ro"+modifier)
|
||||
}
|
||||
c.Assert(m.RW, checker.Equals, false)
|
||||
assert.Equal(c, m.RW, false)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectNamedMountPoint(c *testing.T) {
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
|
||||
dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
|
||||
|
@ -248,19 +248,19 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
// check that there is only one mountpoint
|
||||
c.Assert(mp, checker.HasLen, 1)
|
||||
assert.Equal(c, len(mp), 1)
|
||||
|
||||
m := mp[0]
|
||||
|
||||
c.Assert(m.Name, checker.Equals, "data")
|
||||
c.Assert(m.Driver, checker.Equals, "local")
|
||||
c.Assert(m.Source, checker.Not(checker.Equals), "")
|
||||
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
|
||||
c.Assert(m.RW, checker.Equals, true)
|
||||
assert.Equal(c, m.Name, "data")
|
||||
assert.Equal(c, m.Driver, "local")
|
||||
assert.Assert(c, m.Source != "")
|
||||
assert.Equal(c, m.Destination, prefix+slash+"data")
|
||||
assert.Equal(c, m.RW, true)
|
||||
}
|
||||
|
||||
// #14947
|
||||
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
id := strings.TrimSpace(out)
|
||||
startedAt := inspectField(c, id, "State.StartedAt")
|
||||
|
@ -281,20 +281,20 @@ func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
|||
}
|
||||
|
||||
// #15633
|
||||
func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectLogConfigNoType(c *testing.T) {
|
||||
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
|
||||
var logConfig container.LogConfig
|
||||
|
||||
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
|
||||
|
||||
err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("%v", out))
|
||||
|
||||
c.Assert(logConfig.Type, checker.Equals, "json-file")
|
||||
c.Assert(logConfig.Config["max-file"], checker.Equals, "42", check.Commentf("%v", logConfig))
|
||||
assert.Equal(c, logConfig.Type, "json-file")
|
||||
assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
|
||||
|
||||
//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.
|
||||
|
@ -303,35 +303,34 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
|
|||
|
||||
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
|
||||
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestInspectSizeFlagContainer(c *testing.T) {
|
||||
runSleepingContainer(c, "--name=busybox", "-d")
|
||||
|
||||
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
||||
out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox")
|
||||
sz := strings.Split(out, ",")
|
||||
|
||||
c.Assert(strings.TrimSpace(sz[0]), check.Not(check.Equals), "<nil>")
|
||||
c.Assert(strings.TrimSpace(sz[1]), check.Not(check.Equals), "<nil>")
|
||||
assert.Assert(c, strings.TrimSpace(sz[0]) != "<nil>")
|
||||
assert.Assert(c, strings.TrimSpace(sz[1]) != "<nil>")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectTemplateError(c *testing.T) {
|
||||
// Template parsing error for both the container and image.
|
||||
|
||||
runSleepingContainer(c, "--name=container1", "-d")
|
||||
|
||||
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1")
|
||||
c.Assert(err, check.Not(check.IsNil))
|
||||
c.Assert(out, checker.Contains, "Template parsing error")
|
||||
|
||||
assert.Assert(c, err != nil)
|
||||
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
||||
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
||||
c.Assert(err, check.Not(check.IsNil))
|
||||
c.Assert(out, checker.Contains, "Template parsing error")
|
||||
assert.Assert(c, err != nil)
|
||||
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectJSONFields(c *testing.T) {
|
||||
runSleepingContainer(c, "--name=busybox", "-d")
|
||||
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox")
|
||||
|
||||
|
@ -339,68 +338,67 @@ func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
|
|||
assert.Equal(c, out, "[]\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectByPrefix(c *testing.T) {
|
||||
id := inspectField(c, "busybox", "Id")
|
||||
assert.Assert(c, strings.HasPrefix(id, "sha256:"))
|
||||
|
||||
id2 := inspectField(c, id[:12], "Id")
|
||||
c.Assert(id, checker.Equals, id2)
|
||||
assert.Equal(c, id, id2)
|
||||
|
||||
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
|
||||
c.Assert(id, checker.Equals, id3)
|
||||
assert.Equal(c, id, id3)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectStopWhenNotFound(c *testing.T) {
|
||||
runSleepingContainer(c, "--name=busybox1", "-d")
|
||||
runSleepingContainer(c, "--name=busybox2", "-d")
|
||||
result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing")
|
||||
|
||||
c.Assert(result.Error, checker.Not(check.IsNil))
|
||||
c.Assert(result.Stdout(), checker.Contains, "busybox1")
|
||||
c.Assert(result.Stdout(), checker.Contains, "busybox2")
|
||||
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
|
||||
|
||||
assert.Assert(c, result.Error != nil)
|
||||
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
||||
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
||||
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
||||
// test inspect would not fast fail
|
||||
result = dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "missing", "busybox1", "busybox2")
|
||||
|
||||
c.Assert(result.Error, checker.Not(check.IsNil))
|
||||
c.Assert(result.Stdout(), checker.Contains, "busybox1")
|
||||
c.Assert(result.Stdout(), checker.Contains, "busybox2")
|
||||
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
|
||||
assert.Assert(c, result.Error != nil)
|
||||
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
||||
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
||||
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectHistory(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectHistory(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
|
||||
dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
|
||||
out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, "test comment")
|
||||
assert.Assert(c, strings.Contains(out, "test comment"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
contName := "test1"
|
||||
dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
|
||||
netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
|
||||
out := inspectField(c, contName, "NetworkSettings.Networks")
|
||||
c.Assert(out, checker.Contains, "bridge")
|
||||
assert.Assert(c, strings.Contains(out, "bridge"))
|
||||
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
|
||||
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerNetworkCustom(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectContainerNetworkCustom(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
netOut, _ := dockerCmd(c, "network", "create", "net1")
|
||||
dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
|
||||
out := inspectField(c, "container1", "NetworkSettings.Networks")
|
||||
c.Assert(out, checker.Contains, "net1")
|
||||
assert.Assert(c, strings.Contains(out, "net1"))
|
||||
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
|
||||
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectRootFS(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectRootFS(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("inspect", "busybox")
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -410,17 +408,17 @@ func (s *DockerSuite) TestInspectRootFS(c *check.C) {
|
|||
assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectAmpersand(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectAmpersand(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
name := "test"
|
||||
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
|
||||
c.Assert(out, checker.Contains, `soanni&rtr`)
|
||||
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
||||
out, _ = dockerCmd(c, "inspect", name)
|
||||
c.Assert(out, checker.Contains, `soanni&rtr`)
|
||||
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectPlugin(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectPlugin(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
|
@ -447,14 +445,14 @@ func (s *DockerSuite) TestInspectPlugin(c *check.C) {
|
|||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, pNameWithTag)
|
||||
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
||||
}
|
||||
|
||||
// Test case for 29185
|
||||
func (s *DockerSuite) TestInspectUnknownObject(c *check.C) {
|
||||
func (s *DockerSuite) TestInspectUnknownObject(c *testing.T) {
|
||||
// This test should work on both Windows and Linux
|
||||
out, _, err := dockerCmdWithError("inspect", "foobar")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Error: No such object: foobar")
|
||||
assert.Assert(c, strings.Contains(out, "Error: No such object: foobar"))
|
||||
assert.ErrorContains(c, err, "Error: No such object: foobar")
|
||||
}
|
||||
|
|
|
@ -6,35 +6,35 @@ import (
|
|||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
_, exitCode, err := dockerCmdWithError("run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
|
||||
|
||||
// run ping failed with error
|
||||
c.Assert(exitCode, checker.Equals, 1, check.Commentf("error: %v", err))
|
||||
assert.Equal(c, exitCode, 1, fmt.Sprintf("error: %v", err))
|
||||
}
|
||||
|
||||
// Test for appropriate error when calling --link with an invalid target container
|
||||
func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksInvalidContainerTarget(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true")
|
||||
|
||||
// an invalid container target should produce an error
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
// an invalid container target should produce an error
|
||||
// note: convert the output to lowercase first as the error string
|
||||
// capitalization was changed after API version 1.32
|
||||
c.Assert(strings.ToLower(out), checker.Contains, "could not get container")
|
||||
assert.Assert(c, strings.Contains(strings.ToLower(out), "could not get container"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// Test with the three different ways of specifying the default network on Linux
|
||||
testLinkPingOnNetwork(c, "")
|
||||
|
@ -42,7 +42,7 @@ func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
|||
testLinkPingOnNetwork(c, "bridge")
|
||||
}
|
||||
|
||||
func testLinkPingOnNetwork(c *check.C, network string) {
|
||||
func testLinkPingOnNetwork(c *testing.T, network string) {
|
||||
var postArgs []string
|
||||
if network != "" {
|
||||
postArgs = append(postArgs, []string{"--net", network}...)
|
||||
|
@ -78,7 +78,7 @@ func testLinkPingOnNetwork(c *check.C, network string) {
|
|||
dockerCmd(c, "rm", "-f", "container2")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
||||
idA := strings.TrimSpace(out)
|
||||
|
@ -91,7 +91,7 @@ func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksInspectLinksStarted(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
||||
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
||||
|
@ -110,7 +110,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
|||
assert.DeepEqual(c, result, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksInspectLinksStopped(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
||||
|
@ -130,7 +130,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
|||
assert.DeepEqual(c, result, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "create", "--name=first", "busybox", "top")
|
||||
dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
|
||||
|
@ -138,7 +138,7 @@ func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksHostsFilesInject(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
|
||||
|
@ -148,15 +148,15 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
|
|||
out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")
|
||||
idTwo := strings.TrimSpace(out)
|
||||
|
||||
c.Assert(waitRun(idTwo), checker.IsNil)
|
||||
assert.Assert(c, waitRun(idTwo) == nil)
|
||||
|
||||
readContainerFileWithExec(c, idOne, "/etc/hosts")
|
||||
contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts")
|
||||
// Host is not present in updated hosts file
|
||||
c.Assert(string(contentTwo), checker.Contains, "onetwo")
|
||||
assert.Assert(c, strings.Contains(string(contentTwo), "onetwo"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksUpdateOnRestart(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, testEnv.IsLocalDaemon)
|
||||
dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
|
||||
|
@ -169,70 +169,70 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
|
|||
getIP := func(hosts []byte, hostname string) string {
|
||||
re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname)))
|
||||
matches := re.FindSubmatch(hosts)
|
||||
c.Assert(matches, checker.NotNil, check.Commentf("Hostname %s have no matches in hosts", hostname))
|
||||
assert.Assert(c, matches != nil, fmt.Sprintf("Hostname %s have no matches in hosts", hostname))
|
||||
return string(matches[1])
|
||||
}
|
||||
ip := getIP(content, "one")
|
||||
c.Assert(ip, checker.Equals, realIP)
|
||||
assert.Equal(c, ip, realIP)
|
||||
|
||||
ip = getIP(content, "onetwo")
|
||||
c.Assert(ip, checker.Equals, realIP)
|
||||
assert.Equal(c, ip, realIP)
|
||||
|
||||
dockerCmd(c, "restart", "one")
|
||||
realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
|
||||
|
||||
content = readContainerFileWithExec(c, id, "/etc/hosts")
|
||||
ip = getIP(content, "one")
|
||||
c.Assert(ip, checker.Equals, realIP)
|
||||
assert.Equal(c, ip, realIP)
|
||||
|
||||
ip = getIP(content, "onetwo")
|
||||
c.Assert(ip, checker.Equals, realIP)
|
||||
assert.Equal(c, ip, realIP)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksEnvs(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksEnvs(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
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")
|
||||
c.Assert(out, checker.Contains, "FIRST_ENV_e1=\n")
|
||||
c.Assert(out, checker.Contains, "FIRST_ENV_e2=v2")
|
||||
c.Assert(out, checker.Contains, "FIRST_ENV_e3=v3=v3")
|
||||
assert.Assert(c, strings.Contains(out, "FIRST_ENV_e1=\n"))
|
||||
assert.Assert(c, strings.Contains(out, "FIRST_ENV_e2=v2"))
|
||||
assert.Assert(c, strings.Contains(out, "FIRST_ENV_e3=v3=v3"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinkShortDefinition(c *check.C) {
|
||||
func (s *DockerSuite) TestLinkShortDefinition(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
|
||||
|
||||
cid := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(cid), checker.IsNil)
|
||||
assert.Assert(c, waitRun(cid) == nil)
|
||||
|
||||
out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top")
|
||||
|
||||
cid2 := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(cid2), checker.IsNil)
|
||||
assert.Assert(c, waitRun(cid2) == nil)
|
||||
|
||||
links := inspectFieldJSON(c, cid2, "HostConfig.Links")
|
||||
c.Assert(links, checker.Equals, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
|
||||
assert.Equal(c, links, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksNetworkHostContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
|
||||
out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
|
||||
|
||||
// Running container linking to a container with --net host should have failed
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
// Running container linking to a container with --net host should have failed
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error()))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
|
||||
// /etc/hosts should be a regular file
|
||||
c.Assert(out, checker.Matches, "^-.+\n")
|
||||
assert.Assert(c, cmp.Regexp("^-.+\n$", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLinksMultipleWithSameName(c *check.C) {
|
||||
func (s *DockerSuite) TestLinksMultipleWithSameName(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
|
||||
dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
|
||||
|
|
|
@ -4,12 +4,12 @@ import (
|
|||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestLoginWithoutTTY(c *check.C) {
|
||||
func (s *DockerSuite) TestLoginWithoutTTY(c *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "login")
|
||||
|
||||
// Send to stdin so the process does not get the TTY
|
||||
|
@ -20,7 +20,7 @@ func (s *DockerSuite) TestLoginWithoutTTY(c *check.C) {
|
|||
assert.ErrorContains(c, err, "") //"Expected non nil err when logging in & TTY not available"
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.T) {
|
||||
// wrong credentials
|
||||
out, _, err := dockerCmdWithError("login", "-u", s.reg.Username(), "-p", "WRONGPASSWORD", privateRegistryURL)
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
osPath := os.Getenv("PATH")
|
||||
|
@ -65,7 +65,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C)
|
|||
}
|
||||
|
||||
// #23100
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *testing.T) {
|
||||
osPath := os.Getenv("PATH")
|
||||
defer os.Setenv("PATH", osPath)
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) BenchmarkLogsCLIRotateFollow(c *check.C) {
|
||||
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)
|
||||
|
|
|
@ -6,31 +6,31 @@ import (
|
|||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// This used to work, it test a log of PageSize-1 (gh#4851)
|
||||
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *testing.T) {
|
||||
testLogsContainerPagination(c, 32767)
|
||||
}
|
||||
|
||||
// Regression test: When going over the PageSize, it used to panic (gh#4851)
|
||||
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *testing.T) {
|
||||
testLogsContainerPagination(c, 32768)
|
||||
}
|
||||
|
||||
// Regression test: When going much over the PageSize, it used to block (gh#4851)
|
||||
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *testing.T) {
|
||||
testLogsContainerPagination(c, 33000)
|
||||
}
|
||||
|
||||
func testLogsContainerPagination(c *check.C, testLen int) {
|
||||
func testLogsContainerPagination(c *testing.T, testLen int) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen))
|
||||
id := strings.TrimSpace(out)
|
||||
dockerCmd(c, "wait", id)
|
||||
|
@ -38,7 +38,7 @@ func testLogsContainerPagination(c *check.C, testLen int) {
|
|||
assert.Equal(c, len(out), testLen+1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsTimestamps(c *testing.T) {
|
||||
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))
|
||||
|
||||
|
@ -63,7 +63,7 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsSeparateStderr(c *testing.T) {
|
||||
msg := "stderr_log"
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -74,7 +74,7 @@ func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsStderrInStdout(c *testing.T) {
|
||||
// TODO Windows: Needs investigation why this fails. Obtained string includes
|
||||
// a bunch of ANSI escape sequences before the "stderr_log" message.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -89,7 +89,7 @@ func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsTail(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsTail(c *testing.T) {
|
||||
testLen := 100
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)).Combined()
|
||||
|
||||
|
@ -121,7 +121,7 @@ func (s *DockerSuite) TestLogsTail(c *check.C) {
|
|||
assert.Equal(c, len(lines), testLen+1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsFollowStopped(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello")
|
||||
id := getIDByName(c, "test")
|
||||
|
||||
|
@ -142,7 +142,7 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsSince(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsSince(c *testing.T) {
|
||||
name := "testlogssince"
|
||||
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)
|
||||
|
@ -177,7 +177,7 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsSinceFutureFollow(c *testing.T) {
|
||||
// TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testlogssincefuturefollow"
|
||||
|
@ -211,7 +211,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
|||
}
|
||||
|
||||
// Regression test for #8832
|
||||
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *testing.T) {
|
||||
// TODO Windows: Fix this test for TP5.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
expected := 150000
|
||||
|
@ -269,7 +269,7 @@ func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, s
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done")
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
@ -297,7 +297,7 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
|||
assert.NilError(c, waitForGoroutines(nroutines))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 2; done")
|
||||
id := strings.TrimSpace(out)
|
||||
assert.NilError(c, waitRun(id))
|
||||
|
@ -315,14 +315,14 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
|||
assert.NilError(c, waitForGoroutines(nroutines))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *testing.T) {
|
||||
name := "testlogsnocontainer"
|
||||
out, _, _ := dockerCmdWithError("logs", name)
|
||||
message := fmt.Sprintf("No such container: %s\n", name)
|
||||
assert.Assert(c, strings.Contains(out, message))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsWithDetails(c *check.C) {
|
||||
func (s *DockerSuite) 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")
|
||||
out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test")
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// GH14530. Validates combinations of --net= with other options
|
||||
|
@ -17,80 +18,70 @@ const stringCheckPS = "PID USER"
|
|||
// 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
|
||||
// stop the tests.
|
||||
func dockerCmdWithFail(c *check.C, args ...string) (string, int) {
|
||||
func dockerCmdWithFail(c *testing.T, args ...string) (string, int) {
|
||||
out, status, err := dockerCmdWithError(args...)
|
||||
c.Assert(err, check.NotNil, check.Commentf("%v", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("%v", out))
|
||||
return out, status
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetHostnameWithNetHost(c *check.C) {
|
||||
func (s *DockerSuite) TestNetHostnameWithNetHost(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, stringCheckPS)
|
||||
assert.Assert(c, strings.Contains(out, stringCheckPS))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetHostname(c *check.C) {
|
||||
func (s *DockerSuite) TestNetHostname(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-h=name", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, stringCheckPS)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, stringCheckPS))
|
||||
out, _ = dockerCmd(c, "run", "-h=name", "--net=bridge", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, stringCheckPS)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, stringCheckPS))
|
||||
out, _ = dockerCmd(c, "run", "-h=name", "--net=none", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, stringCheckPS)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, stringCheckPS))
|
||||
out, _ = dockerCmdWithFail(c, "run", "-h=name", "--net=container:other", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHostname.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkHostname.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, "invalid container format container:<name|id>")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "invalid container format container:<name|id>"))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=weird", "busybox", "ps")
|
||||
c.Assert(strings.ToLower(out), checker.Contains, "not found")
|
||||
assert.Assert(c, strings.Contains(strings.ToLower(out), "not found"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *check.C) {
|
||||
func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndLinks.Error())
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndLinks.Error()))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestConflictContainerNetworkHostAndLinks(c *check.C) {
|
||||
func (s *DockerSuite) TestConflictContainerNetworkHostAndLinks(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
||||
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--link=zip:zap", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error()))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestConflictNetworkModeNetHostAndOptions(c *check.C) {
|
||||
func (s *DockerSuite) TestConflictNetworkModeNetHostAndOptions(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
||||
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error()))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *check.C) {
|
||||
func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkAndDNS.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkAndDNS.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--add-host=name:8.8.8.8", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHosts.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkHosts.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-P", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-p", "8080", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
|
||||
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()))
|
||||
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--expose", "8000-9000", "busybox", "ps")
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkExposePorts.Error())
|
||||
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictNetworkExposePorts.Error()))
|
||||
}
|
||||
|
|
13
integration-cli/docker_cli_network_test.go
Normal file
13
integration-cli/docker_cli_network_test.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
)
|
||||
|
||||
type DockerNetworkSuite struct {
|
||||
server *httptest.Server
|
||||
ds *DockerSuite
|
||||
d *daemon.Daemon
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -3,13 +3,13 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestPluginLogDriver(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginLogDriver(c *testing.T) {
|
||||
testRequires(c, IsAmd64, DaemonIsLinux)
|
||||
|
||||
pluginName := "cpuguy83/docker-logdriver-test:latest"
|
||||
|
@ -29,7 +29,7 @@ func (s *DockerSuite) TestPluginLogDriver(c *check.C) {
|
|||
}
|
||||
|
||||
// Make sure log drivers are listed in info, and v2 plugins are not.
|
||||
func (s *DockerSuite) TestPluginLogDriverInfoList(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginLogDriverInfoList(c *testing.T) {
|
||||
testRequires(c, IsAmd64, DaemonIsLinux)
|
||||
pluginName := "cpuguy83/docker-logdriver-test"
|
||||
|
||||
|
|
|
@ -9,14 +9,13 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/docker/docker/internal/test/fixtures/plugin"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -29,52 +28,48 @@ var (
|
|||
npNameWithTag = npName + ":" + pTag
|
||||
)
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) {
|
||||
plugin := ps.getPluginRepoWithTag()
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, err := dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, plugin)
|
||||
c.Assert(out, checker.Contains, "true")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, plugin))
|
||||
assert.Assert(c, strings.Contains(out, "true"))
|
||||
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
|
||||
id = strings.TrimSpace(id)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "is enabled")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "is enabled"))
|
||||
_, _, err = dockerCmdWithError("plugin", "disable", plugin)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, plugin)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, plugin))
|
||||
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id))
|
||||
if !os.IsNotExist(err) {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginForceRemove(c *testing.T) {
|
||||
pNameWithTag := ps.getPluginRepoWithTag()
|
||||
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag)
|
||||
c.Assert(out, checker.Contains, "is enabled")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "is enabled"))
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, pNameWithTag)
|
||||
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginActive(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginActive(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
||||
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
||||
|
@ -84,8 +79,7 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag)
|
||||
c.Assert(out, checker.Contains, "in use")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "in use"))
|
||||
_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -94,10 +88,10 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {
|
|||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, pNameWithTag)
|
||||
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginActiveNetwork(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
|
@ -108,56 +102,49 @@ func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
|
|||
nID := strings.TrimSpace(out)
|
||||
|
||||
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
||||
c.Assert(out, checker.Contains, "is in use")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "is in use"))
|
||||
_, _, err = dockerCmdWithError("network", "rm", nID)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
||||
c.Assert(out, checker.Contains, "is enabled")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "is enabled"))
|
||||
_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, npNameWithTag)
|
||||
assert.Assert(c, strings.Contains(out, npNameWithTag))
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginInstallDisable(c *testing.T) {
|
||||
pName := ps.getPluginRepoWithTag()
|
||||
|
||||
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, "false")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "false"))
|
||||
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
||||
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
dockerCmd(c, "volume", "ls")
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginSet(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginSet(c *testing.T) {
|
||||
client := testEnv.APIClient()
|
||||
|
||||
name := "test"
|
||||
|
@ -180,35 +167,31 @@ func (ps *DockerPluginSuite) TestPluginSet(c *check.C) {
|
|||
{Name: "pdev2", Settable: []string{"path"}}, // Device without Path is invalid.
|
||||
}
|
||||
})
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
|
||||
assert.Assert(c, err == nil, "failed to create test plugin")
|
||||
|
||||
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
||||
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
|
||||
|
||||
dockerCmd(c, "plugin", "set", name, "DEBUG=1")
|
||||
|
||||
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
||||
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
||||
|
||||
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
|
||||
c.Assert(strings.TrimSpace(env), checker.Contains, mntSrc)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(env), mntSrc))
|
||||
dockerCmd(c, "plugin", "set", name, "pmount1.source=bar")
|
||||
|
||||
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
|
||||
c.Assert(strings.TrimSpace(env), checker.Contains, "bar")
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(env), "bar"))
|
||||
out, _, err := dockerCmdWithError("plugin", "set", name, "pmount2.source=bar2")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Plugin config has no mount source")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "Plugin config has no mount source"))
|
||||
out, _, err = dockerCmdWithError("plugin", "set", name, "pdev2.path=/dev/bar2")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Plugin config has no device path")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "Plugin config has no device path"))
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginInstallArgs(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginInstallArgs(c *testing.T) {
|
||||
pName := path.Join(ps.registryHost(), "plugin", "testplugininstallwithargs")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
@ -218,13 +201,12 @@ func (ps *DockerPluginSuite) TestPluginInstallArgs(c *check.C) {
|
|||
})
|
||||
|
||||
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
||||
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginInstallImage(c *testing.T) {
|
||||
testRequires(c, IsAmd64)
|
||||
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
@ -235,32 +217,29 @@ func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
|
|||
|
||||
out, _, err := dockerCmdWithError("plugin", "install", repoName)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
|
||||
assert.Assert(c, strings.Contains(out, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`))
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *testing.T) {
|
||||
pName := ps.getPluginRepoWithTag()
|
||||
|
||||
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
||||
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already enabled"))
|
||||
_, _, err = dockerCmdWithError("plugin", "disable", pName)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already disabled"))
|
||||
_, _, err = dockerCmdWithError("plugin", "remove", pName)
|
||||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginCreate(c *testing.T) {
|
||||
name := "foo/bar-driver"
|
||||
temp, err := ioutil.TempDir("", "foo")
|
||||
assert.NilError(c, err)
|
||||
|
@ -275,24 +254,21 @@ func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
|
|||
|
||||
out, _, err := dockerCmdWithError("plugin", "create", name, temp)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
out, _, err = dockerCmdWithError("plugin", "create", name, temp)
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "already exist")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "already exist"))
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
// The output will consists of one HEADER line and one line of foo/bar-driver
|
||||
c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
|
||||
assert.Equal(c, len(strings.Split(strings.TrimSpace(out), "\n")), 2)
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginInspect(c *testing.T) {
|
||||
pNameWithTag := ps.getPluginRepoWithTag()
|
||||
|
||||
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
||||
|
@ -300,9 +276,8 @@ func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
|
|||
|
||||
out, _, err := dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, pNameWithTag)
|
||||
c.Assert(out, checker.Contains, "true")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
||||
assert.Assert(c, strings.Contains(out, "true"))
|
||||
// Find the ID first
|
||||
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
|
@ -334,25 +309,24 @@ func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
|
|||
|
||||
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, pNameWithTag)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
||||
// After remove nothing should be found
|
||||
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
||||
assert.ErrorContains(c, err, "")
|
||||
}
|
||||
|
||||
// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
|
||||
func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginInspectOnWindows(c *testing.T) {
|
||||
// This test should work on Windows only
|
||||
testRequires(c, DaemonIsWindows)
|
||||
|
||||
out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "plugins are not supported on this platform")
|
||||
assert.Assert(c, strings.Contains(out, "plugins are not supported on this platform"))
|
||||
assert.ErrorContains(c, err, "plugins are not supported on this platform")
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginIDPrefix(c *testing.T) {
|
||||
name := "test"
|
||||
client := testEnv.APIClient()
|
||||
|
||||
|
@ -363,7 +337,7 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
|
|||
})
|
||||
cancel()
|
||||
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
|
||||
assert.Assert(c, err == nil, "failed to create test plugin")
|
||||
|
||||
// Find ID first
|
||||
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
|
||||
|
@ -373,43 +347,40 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
|
|||
// List current state
|
||||
out, _, err := dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
c.Assert(out, checker.Contains, "false")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
assert.Assert(c, strings.Contains(out, "false"))
|
||||
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
||||
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
|
||||
|
||||
dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
|
||||
|
||||
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
||||
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
||||
|
||||
// Enable
|
||||
_, _, err = dockerCmdWithError("plugin", "enable", id[:5])
|
||||
assert.NilError(c, err)
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
c.Assert(out, checker.Contains, "true")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
assert.Assert(c, strings.Contains(out, "true"))
|
||||
// Disable
|
||||
_, _, err = dockerCmdWithError("plugin", "disable", id[:5])
|
||||
assert.NilError(c, err)
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
c.Assert(out, checker.Contains, "false")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
assert.Assert(c, strings.Contains(out, "false"))
|
||||
// Remove
|
||||
_, _, err = dockerCmdWithError("plugin", "remove", id[:5])
|
||||
assert.NilError(c, err)
|
||||
// List returns none
|
||||
out, _, err = dockerCmdWithError("plugin", "ls")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
assert.Assert(c, !strings.Contains(out, name))
|
||||
}
|
||||
|
||||
func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
|
||||
func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *testing.T) {
|
||||
config, err := ioutil.TempDir("", "config-file-")
|
||||
assert.NilError(c, err)
|
||||
defer os.RemoveAll(config)
|
||||
|
@ -425,7 +396,7 @@ func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
|
|||
err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
|
||||
cfg.Description = "test plugin"
|
||||
})
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
|
||||
assert.Assert(c, err == nil, "failed to create test plugin")
|
||||
|
||||
out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -437,10 +408,10 @@ description: test plugin
|
|||
enabled: false`, id, name)
|
||||
|
||||
out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), expectedOutput))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginUpgrade(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64, NotUserNamespace)
|
||||
plugin := "cpuguy83/docker-volume-driver-plugin-local:latest"
|
||||
pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2"
|
||||
|
@ -451,14 +422,13 @@ func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
|
|||
|
||||
out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2)
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
c.Assert(out, checker.Contains, "disabled before upgrading")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "disabled before upgrading"))
|
||||
out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
// make sure "v2" does not exists
|
||||
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
|
||||
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("%s", out))
|
||||
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("%s", out))
|
||||
|
||||
dockerCmd(c, "plugin", "disable", "-f", plugin)
|
||||
dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)
|
||||
|
@ -472,7 +442,7 @@ func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
|
|||
dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
|
||||
func (s *DockerSuite) TestPluginMetricsCollector(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64)
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary)
|
||||
d.Start(c)
|
||||
|
@ -480,7 +450,7 @@ func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
|
|||
|
||||
name := "cpuguy83/docker-metrics-plugin-test:latest"
|
||||
r := cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", name), cli.Daemon(d))
|
||||
c.Assert(r.Error, checker.IsNil, check.Commentf(r.Combined()))
|
||||
assert.Assert(c, r.Error == nil, r.Combined())
|
||||
|
||||
// plugin lisens on localhost:19393 and proxies the metrics
|
||||
resp, err := http.Get("http://localhost:19393/metrics")
|
||||
|
@ -490,5 +460,5 @@ func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
|
|||
b, err := ioutil.ReadAll(resp.Body)
|
||||
assert.NilError(c, err)
|
||||
// check that a known metric is there... don't expect this metric to change over time.. probably safe
|
||||
c.Assert(string(b), checker.Contains, "container_actions")
|
||||
assert.Assert(c, strings.Contains(string(b), "container_actions"))
|
||||
}
|
||||
|
|
|
@ -7,13 +7,12 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestPortList(c *check.C) {
|
||||
func (s *DockerSuite) TestPortList(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// one port
|
||||
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "top")
|
||||
|
@ -105,7 +104,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
|
|||
"-p", "9090-9092:80",
|
||||
"busybox", "top")
|
||||
// Exhausted port range did not return an error
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
dockerCmd(c, "rm", "-f", IDs[i])
|
||||
|
@ -121,7 +120,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
|
|||
"-p", invalidRange,
|
||||
"busybox", "top")
|
||||
// Port range should have returned an error
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
||||
// test host range:container range spec.
|
||||
|
@ -157,7 +156,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
|
|||
dockerCmd(c, "rm", "-f", ID)
|
||||
}
|
||||
|
||||
func assertPortList(c *check.C, out string, expected []string) error {
|
||||
func assertPortList(c *testing.T, out string, expected []string) error {
|
||||
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
||||
if len(lines) != len(expected) {
|
||||
return fmt.Errorf("different size lists %s, %d, %d", out, len(lines), len(expected))
|
||||
|
@ -174,7 +173,7 @@ func assertPortList(c *check.C, out string, expected []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func assertPortRange(c *check.C, out string, expectedTcp, expectedUdp []int) error {
|
||||
func assertPortRange(c *testing.T, out string, expectedTcp, expectedUdp []int) error {
|
||||
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
||||
|
||||
var validTcp, validUdp bool
|
||||
|
@ -206,11 +205,11 @@ func assertPortRange(c *check.C, out string, expectedTcp, expectedUdp []int) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func stopRemoveContainer(id string, c *check.C) {
|
||||
func stopRemoveContainer(id string, c *testing.T) {
|
||||
dockerCmd(c, "rm", "-f", id)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
||||
func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// Run busybox with command line expose (equivalent to EXPOSE in image's Dockerfile) for the following ports
|
||||
port1 := 80
|
||||
|
@ -224,10 +223,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
unpPort2 := fmt.Sprintf("%d/tcp", port2)
|
||||
out, _ := dockerCmd(c, "ps", "-n=1")
|
||||
// Missing unpublished ports in docker ps output
|
||||
c.Assert(out, checker.Contains, unpPort1)
|
||||
assert.Assert(c, strings.Contains(out, unpPort1))
|
||||
// Missing unpublished ports in docker ps output
|
||||
c.Assert(out, checker.Contains, unpPort2)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, unpPort2))
|
||||
// Run the container forcing to publish the exposed ports
|
||||
dockerCmd(c, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5")
|
||||
|
||||
|
@ -236,9 +234,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2)
|
||||
out, _ = dockerCmd(c, "ps", "-n=1")
|
||||
// Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort1) in docker ps output
|
||||
c.Assert(expBndRegx1.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort1: %s", out, unpPort1))
|
||||
assert.Equal(c, expBndRegx1.MatchString(out), true, fmt.Sprintf("out: %s; unpPort1: %s", out, unpPort1))
|
||||
// Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort2) in docker ps output
|
||||
c.Assert(expBndRegx2.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort2: %s", out, unpPort2))
|
||||
assert.Equal(c, expBndRegx2.MatchString(out), true, fmt.Sprintf("out: %s; unpPort2: %s", out, unpPort2))
|
||||
|
||||
// Run the container specifying explicit port bindings for the exposed ports
|
||||
offset := 10000
|
||||
|
@ -252,10 +250,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2)
|
||||
out, _ = dockerCmd(c, "ps", "-n=1")
|
||||
// Cannot find expected port binding (expBnd1) in docker ps output
|
||||
c.Assert(out, checker.Contains, expBnd1)
|
||||
assert.Assert(c, strings.Contains(out, expBnd1))
|
||||
// Cannot find expected port binding (expBnd2) in docker ps output
|
||||
c.Assert(out, checker.Contains, expBnd2)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, expBnd2))
|
||||
// Remove container now otherwise it will interfere with next test
|
||||
stopRemoveContainer(id, c)
|
||||
|
||||
|
@ -266,9 +263,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
// Check docker ps o/p for last created container reports the specified port mappings
|
||||
out, _ = dockerCmd(c, "ps", "-n=1")
|
||||
// Cannot find expected port binding (expBnd1) in docker ps output
|
||||
c.Assert(out, checker.Contains, expBnd1)
|
||||
assert.Assert(c, strings.Contains(out, expBnd1))
|
||||
// Cannot find expected port binding (expBnd2) in docker ps output
|
||||
c.Assert(out, checker.Contains, expBnd2)
|
||||
assert.Assert(c, strings.Contains(out, expBnd2))
|
||||
// Remove container now otherwise it will interfere with next test
|
||||
stopRemoveContainer(id, c)
|
||||
|
||||
|
@ -278,12 +275,12 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
// Check docker ps o/p for last created container reports the specified unpublished port and port mapping
|
||||
out, _ = dockerCmd(c, "ps", "-n=1")
|
||||
// Missing unpublished exposed ports (unpPort1) in docker ps output
|
||||
c.Assert(out, checker.Contains, unpPort1)
|
||||
assert.Assert(c, strings.Contains(out, unpPort1))
|
||||
// Missing port binding (expBnd2) in docker ps output
|
||||
c.Assert(out, checker.Contains, expBnd2)
|
||||
assert.Assert(c, strings.Contains(out, expBnd2))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
||||
func (s *DockerSuite) TestPortHostBinding(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
|
@ -302,10 +299,10 @@ func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
|||
|
||||
out, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "9876")
|
||||
// Port is still bound after the Container is removed
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
||||
func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
|
@ -314,7 +311,7 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
|||
out, _ = dockerCmd(c, "port", firstID, "80")
|
||||
|
||||
_, exposedPort, err := net.SplitHostPort(out)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("out: %s", out))
|
||||
|
||||
dockerCmd(c, "run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort))
|
||||
|
@ -324,29 +321,25 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
|||
out, _, err = dockerCmdWithError("run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort))
|
||||
// Port is still bound after the Container is removed
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortBindingOnSandbox(c *check.C) {
|
||||
func (s *DockerSuite) TestPortBindingOnSandbox(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net")
|
||||
nr := getNetworkResource(c, "internal-net")
|
||||
c.Assert(nr.Internal, checker.Equals, true)
|
||||
assert.Equal(c, nr.Internal, true)
|
||||
|
||||
dockerCmd(c, "run", "--net", "internal-net", "-d", "--name", "c1",
|
||||
"-p", "8080:8080", "busybox", "nc", "-l", "-p", "8080")
|
||||
c.Assert(waitRun("c1"), check.IsNil)
|
||||
assert.Assert(c, waitRun("c1") == nil)
|
||||
|
||||
_, _, err := dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
|
||||
c.Assert(err, check.NotNil,
|
||||
check.Commentf("Port mapping on internal network is expected to fail"))
|
||||
|
||||
assert.Assert(c, err != nil, "Port mapping on internal network is expected to fail")
|
||||
// Connect container to another normal bridge network
|
||||
dockerCmd(c, "network", "create", "-d", "bridge", "foo-net")
|
||||
dockerCmd(c, "network", "connect", "foo-net", "c1")
|
||||
|
||||
_, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
|
||||
c.Assert(err, check.IsNil,
|
||||
check.Commentf("Port mapping on the new network is expected to succeed"))
|
||||
|
||||
assert.Assert(c, err == nil, "Port mapping on the new network is expected to succeed")
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package main
|
|||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) {
|
||||
func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
|
@ -20,7 +20,7 @@ func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) {
|
|||
|
||||
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost
|
||||
// See https://golang.org/pkg/net/http/#ProxyFromEnvironment
|
||||
func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *testing.T) {
|
||||
// get the IP to use to connect since we can't use localhost
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
assert.NilError(c, err)
|
||||
|
|
|
@ -8,39 +8,41 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func pruneNetworkAndVerify(c *check.C, d *daemon.Daemon, kept, pruned []string) {
|
||||
func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) {
|
||||
_, err := d.Cmd("network", "prune", "--force")
|
||||
assert.NilError(c, err)
|
||||
|
||||
for _, s := range kept {
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(*check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) {
|
||||
out, err := d.Cmd("network", "ls", "--format", "{{.Name}}")
|
||||
assert.NilError(c, err)
|
||||
return out, nil
|
||||
}, checker.Contains, s)
|
||||
return out, ""
|
||||
}, checker.Contains(s)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
for _, s := range pruned {
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(*check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) {
|
||||
out, err := d.Cmd("network", "ls", "--format", "{{.Name}}")
|
||||
assert.NilError(c, err)
|
||||
return out, nil
|
||||
}, checker.Not(checker.Contains), s)
|
||||
return out, ""
|
||||
}, checker.Not(checker.Contains(s))), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestPruneNetwork(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestPruneNetwork(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
_, err := d.Cmd("network", "create", "n1") // used by container (testprune)
|
||||
assert.NilError(c, err)
|
||||
|
@ -64,7 +66,7 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *check.C) {
|
|||
"busybox", "top")
|
||||
assert.NilError(c, err)
|
||||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, replicas+1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(replicas+1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// prune and verify
|
||||
pruneNetworkAndVerify(c, d, []string{"n1", "n3"}, []string{"n2", "n4"})
|
||||
|
@ -74,12 +76,12 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
_, err = d.Cmd("service", "rm", serviceName)
|
||||
assert.NilError(c, err)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
pruneNetworkAndVerify(c, d, []string{}, []string{"n1", "n3"})
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestPruneImageDangling(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
result := cli.BuildCmd(c, "test", cli.Daemon(s.d),
|
||||
|
@ -92,26 +94,22 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("images", "-q", "--no-trunc")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id))
|
||||
out, err = s.d.Cmd("image", "prune", "--force")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id))
|
||||
out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id))
|
||||
out, err = s.d.Cmd("image", "prune", "--force", "--all")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id))
|
||||
out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
|
||||
func (s *DockerSuite) TestPruneContainerUntil(c *testing.T) {
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox").Combined()
|
||||
id1 := strings.TrimSpace(out)
|
||||
cli.WaitExited(c, id1, 5*time.Second)
|
||||
|
@ -123,15 +121,14 @@ func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
|
|||
cli.WaitExited(c, id2, 5*time.Second)
|
||||
|
||||
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "until="+until).Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestPruneContainerLabel(c *testing.T) {
|
||||
out := cli.DockerCmd(c, "run", "-d", "--label", "foo", "busybox").Combined()
|
||||
id1 := strings.TrimSpace(out)
|
||||
cli.WaitExited(c, id1, 5*time.Second)
|
||||
|
@ -158,53 +155,47 @@ func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
|
|||
|
||||
// With config.json only, prune based on label=foobar
|
||||
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id4)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id4))
|
||||
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label=foo").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id3))
|
||||
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id3))
|
||||
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede
|
||||
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPruneVolumeLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestPruneVolumeLabel(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "volume", "create", "--label", "foo")
|
||||
id1 := strings.TrimSpace(out)
|
||||
c.Assert(id1, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, id1 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "create", "--label", "bar")
|
||||
id2 := strings.TrimSpace(out)
|
||||
c.Assert(id2, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, id2 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "create")
|
||||
id3 := strings.TrimSpace(out)
|
||||
c.Assert(id3, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, id3 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "create", "--label", "foobar")
|
||||
id4 := strings.TrimSpace(out)
|
||||
c.Assert(id4, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, id4 != "")
|
||||
|
||||
// Add a config file of label=foobar, that will have no impact if cli is label!=foobar
|
||||
config := `{"pruneFilters": ["label=foobar"]}`
|
||||
|
@ -216,59 +207,51 @@ func (s *DockerSuite) TestPruneVolumeLabel(c *check.C) {
|
|||
|
||||
// With config.json only, prune based on label=foobar
|
||||
out, _ = dockerCmd(c, "--config", d, "volume", "prune", "--force")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id4)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id4))
|
||||
out, _ = dockerCmd(c, "volume", "prune", "--force", "--filter", "label=foo")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id3))
|
||||
out, _ = dockerCmd(c, "volume", "prune", "--force", "--filter", "label!=bar")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id3))
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id3))
|
||||
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede
|
||||
out, _ = dockerCmd(c, "--config", d, "volume", "prune", "--force", "--filter", "label!=foobar")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPruneNetworkLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestPruneNetworkLabel(c *testing.T) {
|
||||
dockerCmd(c, "network", "create", "--label", "foo", "n1")
|
||||
dockerCmd(c, "network", "create", "--label", "bar", "n2")
|
||||
dockerCmd(c, "network", "create", "n3")
|
||||
|
||||
out, _ := dockerCmd(c, "network", "prune", "--force", "--filter", "label=foo")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "n1")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "n1"))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n2"))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n3"))
|
||||
out, _ = dockerCmd(c, "network", "prune", "--force", "--filter", "label!=bar")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "n3")
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n1"))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n2"))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "n3"))
|
||||
out, _ = dockerCmd(c, "network", "prune", "--force")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "n2")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n1"))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "n2"))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), "n3"))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestPruneImageLabel(c *testing.T) {
|
||||
s.d.StartWithBusybox(c)
|
||||
|
||||
result := cli.BuildCmd(c, "test1", cli.Daemon(s.d),
|
||||
|
@ -280,8 +263,7 @@ func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
|
|||
id1 := strings.TrimSpace(result.Combined())
|
||||
out, err := s.d.Cmd("images", "-q", "--no-trunc")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
result = cli.BuildCmd(c, "test2", cli.Daemon(s.d),
|
||||
build.WithDockerfile(`FROM busybox
|
||||
LABEL bar=foo`),
|
||||
|
@ -291,20 +273,17 @@ func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
|
|||
id2 := strings.TrimSpace(result.Combined())
|
||||
out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label=foo=bar")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label!=bar=foo")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id2))
|
||||
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label=bar=foo")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
}
|
||||
|
|
|
@ -5,20 +5,19 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersBase(c *testing.T) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
||||
out := runSleepingContainer(c, "-d")
|
||||
|
@ -35,89 +34,89 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|||
fourthID := strings.TrimSpace(out)
|
||||
|
||||
// make sure the second is running
|
||||
c.Assert(waitRun(secondID), checker.IsNil)
|
||||
assert.Assert(c, waitRun(secondID) == nil)
|
||||
|
||||
// make sure third one is not running
|
||||
dockerCmd(c, "wait", thirdID)
|
||||
|
||||
// make sure the forth is running
|
||||
c.Assert(waitRun(fourthID), checker.IsNil)
|
||||
assert.Assert(c, waitRun(fourthID) == nil)
|
||||
|
||||
// all
|
||||
out, _ = dockerCmd(c, "ps", "-a")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), true, fmt.Sprintf("ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// running
|
||||
out, _ = dockerCmd(c, "ps")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), true, fmt.Sprintf("RUNNING: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// limit
|
||||
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
|
||||
expected := []string{fourthID, thirdID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-n=2")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter since
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a")
|
||||
expected = []string{fourthID, thirdID, secondID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID)
|
||||
expected = []string{fourthID, secondID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID)
|
||||
expected = []string{fourthID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter before
|
||||
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a")
|
||||
expected = []string{thirdID, secondID, firstID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID)
|
||||
expected = []string{secondID, firstID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
|
||||
expected = []string{secondID, firstID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter since & before
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a")
|
||||
expected = []string{thirdID, secondID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID)
|
||||
expected = []string{secondID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter since & limit
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a")
|
||||
expected = []string{fourthID, thirdID}
|
||||
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter before & limit
|
||||
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a")
|
||||
expected = []string{thirdID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
// filter since & filter before & limit
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a")
|
||||
expected = []string{thirdID}
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1")
|
||||
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
||||
|
||||
}
|
||||
|
||||
|
@ -139,7 +138,7 @@ func assertContainerList(out string, expected []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersSize(c *testing.T) {
|
||||
// Problematic on Windows as it doesn't report the size correctly @swernli
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "busybox")
|
||||
|
@ -173,13 +172,13 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
|||
sizeIndex := strings.Index(lines[0], "SIZE")
|
||||
idIndex := strings.Index(lines[0], "CONTAINER ID")
|
||||
foundID := lines[1][idIndex : idIndex+12]
|
||||
c.Assert(foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
|
||||
assert.Equal(c, foundID, id[:12], fmt.Sprintf("Expected id %s, got %s", id[:12], foundID))
|
||||
expectedSize := fmt.Sprintf("%dB", 2+baseBytes)
|
||||
foundSize := lines[1][sizeIndex:]
|
||||
c.Assert(foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
|
||||
assert.Assert(c, strings.Contains(foundSize, expectedSize), fmt.Sprintf("Expected size %q, got %q", expectedSize, foundSize))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterStatus(c *testing.T) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
||||
// start exited container
|
||||
|
@ -196,11 +195,11 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
|||
// filter containers by exited
|
||||
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited").Combined()
|
||||
containerOut := strings.TrimSpace(out)
|
||||
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, firstID)
|
||||
assert.Equal(c, RemoveOutputForExistingElements(containerOut, existingContainers), firstID)
|
||||
|
||||
out = cli.DockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running").Combined()
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, secondID)
|
||||
assert.Equal(c, RemoveOutputForExistingElements(containerOut, existingContainers), secondID)
|
||||
|
||||
result := cli.Docker(cli.Args("ps", "-a", "-q", "--filter=status=rubbish"), cli.WithTimeout(time.Second*60))
|
||||
err := "Invalid filter 'status=rubbish'"
|
||||
|
@ -222,11 +221,11 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
|||
|
||||
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused").Combined()
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, pausedID)
|
||||
assert.Equal(c, RemoveOutputForExistingElements(containerOut, existingContainers), pausedID)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
// Test legacy no health check
|
||||
out := runSleepingContainer(c, "--name=none_legacy")
|
||||
|
@ -236,7 +235,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|||
|
||||
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
|
||||
containerOut := strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
|
||||
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
|
||||
|
||||
// Test no health check specified explicitly
|
||||
out = runSleepingContainer(c, "--name=none", "--no-healthcheck")
|
||||
|
@ -246,7 +245,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|||
|
||||
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
|
||||
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
|
||||
|
||||
// Test failing health check
|
||||
out = runSleepingContainer(c, "--name=failing_container", "--health-cmd=exit 1", "--health-interval=1s")
|
||||
|
@ -256,7 +255,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|||
|
||||
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy").Combined()
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
|
||||
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
|
||||
|
||||
// Check passing healthcheck
|
||||
out = runSleepingContainer(c, "--name=passing_container", "--health-cmd=exit 0", "--health-interval=1s")
|
||||
|
@ -266,10 +265,10 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|||
|
||||
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
|
||||
containerOut = strings.TrimSpace(RemoveOutputForExistingElements(out, existingContainers))
|
||||
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterID(c *testing.T) {
|
||||
// start container
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
@ -280,10 +279,10 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
|||
// filter containers by id
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
|
||||
containerOut := strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterName(c *testing.T) {
|
||||
// start container
|
||||
dockerCmd(c, "run", "--name=a_name_to_match", "busybox")
|
||||
id := getIDByName(c, "a_name_to_match")
|
||||
|
@ -294,7 +293,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
|||
// filter containers by name
|
||||
out, _ := dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
|
||||
containerOut := strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
|
||||
assert.Equal(c, containerOut, id[:12], fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
|
||||
}
|
||||
|
||||
// Test for the ancestor filter for ps.
|
||||
|
@ -305,7 +304,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
|||
// - 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)
|
||||
// - Filter them out :P
|
||||
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *testing.T) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
||||
// Build images
|
||||
|
@ -378,7 +377,7 @@ func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
|
|||
checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageName2+","+imageName1Tagged, []string{fourthID, fifthID})
|
||||
}
|
||||
|
||||
func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expectedIDs []string) {
|
||||
func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, expectedIDs []string) {
|
||||
var actualIDs []string
|
||||
if out != "" {
|
||||
actualIDs = strings.Split(out[:len(out)-1], "\n")
|
||||
|
@ -386,7 +385,7 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
|
|||
sort.Strings(actualIDs)
|
||||
sort.Strings(expectedIDs)
|
||||
|
||||
c.Assert(actualIDs, checker.HasLen, len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
|
||||
assert.Equal(c, len(actualIDs), len(expectedIDs), fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
|
||||
if len(expectedIDs) > 0 {
|
||||
same := true
|
||||
for i := range expectedIDs {
|
||||
|
@ -396,11 +395,11 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
|
|||
break
|
||||
}
|
||||
}
|
||||
c.Assert(same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
|
||||
assert.Equal(c, same, true, fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterLabel(c *testing.T) {
|
||||
// start container
|
||||
dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox")
|
||||
firstID := getIDByName(c, "first")
|
||||
|
@ -416,55 +415,54 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
|||
// filter containers by exact match
|
||||
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
|
||||
containerOut := strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
|
||||
assert.Equal(c, containerOut, firstID, fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
|
||||
|
||||
// filter containers by two labels
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
|
||||
assert.Equal(c, containerOut, firstID, fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
|
||||
|
||||
// filter containers by two labels, but expect not found because of AND behavior
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Equals, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
|
||||
assert.Equal(c, containerOut, "", fmt.Sprintf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
|
||||
|
||||
// filter containers by exact key
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
|
||||
containerOut = strings.TrimSpace(out)
|
||||
c.Assert(containerOut, checker.Contains, firstID)
|
||||
c.Assert(containerOut, checker.Contains, secondID)
|
||||
c.Assert(containerOut, checker.Not(checker.Contains), thirdID)
|
||||
assert.Assert(c, strings.Contains(containerOut, firstID))
|
||||
assert.Assert(c, strings.Contains(containerOut, secondID))
|
||||
assert.Assert(c, !strings.Contains(containerOut, thirdID))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterExited(c *testing.T) {
|
||||
runSleepingContainer(c, "--name=sleep")
|
||||
|
||||
firstZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
|
||||
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("Should fail. out: %s", out))
|
||||
firstNonZero := getIDByName(c, "nonzero1")
|
||||
|
||||
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("Should fail. out: %s", out))
|
||||
secondNonZero := getIDByName(c, "nonzero2")
|
||||
|
||||
// filter containers by exited=0
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
||||
c.Assert(out, checker.Contains, strings.TrimSpace(firstZero))
|
||||
c.Assert(out, checker.Contains, strings.TrimSpace(secondZero))
|
||||
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(firstNonZero))
|
||||
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(secondNonZero))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, strings.TrimSpace(firstZero)))
|
||||
assert.Assert(c, strings.Contains(out, strings.TrimSpace(secondZero)))
|
||||
assert.Assert(c, !strings.Contains(out, strings.TrimSpace(firstNonZero)))
|
||||
assert.Assert(c, !strings.Contains(out, strings.TrimSpace(secondNonZero)))
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
|
||||
c.Assert(out, checker.Contains, strings.TrimSpace(firstNonZero))
|
||||
c.Assert(out, checker.Contains, strings.TrimSpace(secondNonZero))
|
||||
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(firstZero))
|
||||
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(secondZero))
|
||||
assert.Assert(c, strings.Contains(out, strings.TrimSpace(firstNonZero)))
|
||||
assert.Assert(c, strings.Contains(out, strings.TrimSpace(secondNonZero)))
|
||||
assert.Assert(c, !strings.Contains(out, strings.TrimSpace(firstZero)))
|
||||
assert.Assert(c, !strings.Contains(out, strings.TrimSpace(secondZero)))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
||||
func (s *DockerSuite) TestPsRightTagName(c *testing.T) {
|
||||
// TODO Investigate further why this fails on Windows to Windows CI
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -499,18 +497,18 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
|||
f := strings.Fields(line)
|
||||
switch f[0] {
|
||||
case id1:
|
||||
c.Assert(f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
|
||||
assert.Equal(c, f[1], "busybox", fmt.Sprintf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
|
||||
case id2:
|
||||
c.Assert(f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
|
||||
assert.Equal(c, f[1], tag, fmt.Sprintf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
|
||||
case id3:
|
||||
c.Assert(f[1], checker.Equals, imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
|
||||
assert.Equal(c, f[1], imageID, fmt.Sprintf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
|
||||
default:
|
||||
c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterCreated(c *testing.T) {
|
||||
// create a container
|
||||
out, _ := dockerCmd(c, "create", "busybox")
|
||||
cID := strings.TrimSpace(out)
|
||||
|
@ -518,8 +516,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|||
|
||||
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
|
||||
out, _ = dockerCmd(c, "ps", "-q")
|
||||
c.Assert(out, checker.Not(checker.Contains), shortCID, check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, shortCID), fmt.Sprintf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
|
||||
// Make sure it DOES show up as 'Created' for 'ps -a'
|
||||
out, _ = dockerCmd(c, "ps", "-a")
|
||||
|
||||
|
@ -529,10 +526,10 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|||
continue
|
||||
}
|
||||
hits++
|
||||
c.Assert(line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line))
|
||||
assert.Assert(c, strings.Contains(line, "Created"), fmt.Sprintf("Missing 'Created' on '%s'", line))
|
||||
}
|
||||
|
||||
c.Assert(hits, checker.Equals, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
|
||||
assert.Equal(c, hits, 1, fmt.Sprintf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
|
||||
|
||||
// filter containers by 'create' - note, no -a needed
|
||||
out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
|
||||
|
@ -541,7 +538,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|||
}
|
||||
|
||||
// Test for GitHub issue #12595
|
||||
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
||||
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *testing.T) {
|
||||
// TODO: Investigate why this fails on Windows to Windows CI further.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
|
||||
|
@ -564,11 +561,11 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|||
lines = RemoveLinesForExistingElements(lines, existingContainers)
|
||||
// skip header
|
||||
lines = lines[1:]
|
||||
c.Assert(len(lines), checker.Equals, 1)
|
||||
assert.Equal(c, len(lines), 1)
|
||||
|
||||
for _, line := range lines {
|
||||
f := strings.Fields(line)
|
||||
c.Assert(f[1], checker.Equals, originalImageName)
|
||||
assert.Equal(c, f[1], originalImageName)
|
||||
}
|
||||
|
||||
icmd.RunCommand(dockerBinary, "commit", containerID, updatedImageName).Assert(c, icmd.Success)
|
||||
|
@ -581,34 +578,34 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|||
lines = RemoveLinesForExistingElements(lines, existingContainers)
|
||||
// skip header
|
||||
lines = lines[1:]
|
||||
c.Assert(len(lines), checker.Equals, 1)
|
||||
assert.Equal(c, len(lines), 1)
|
||||
|
||||
for _, line := range lines {
|
||||
f := strings.Fields(line)
|
||||
c.Assert(f[1], checker.Equals, originalImageID)
|
||||
assert.Equal(c, f[1], originalImageID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top")
|
||||
c.Assert(waitRun("foo"), checker.IsNil)
|
||||
assert.Assert(c, waitRun("foo") == nil)
|
||||
out, _ := dockerCmd(c, "ps")
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
expected := "0.0.0.0:5000->5000/tcp"
|
||||
fields := strings.Fields(lines[1])
|
||||
c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
|
||||
assert.Equal(c, fields[len(fields)-2], expected, fmt.Sprintf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
|
||||
|
||||
dockerCmd(c, "kill", "foo")
|
||||
dockerCmd(c, "wait", "foo")
|
||||
out, _ = dockerCmd(c, "ps", "-l")
|
||||
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
fields = strings.Fields(lines[1])
|
||||
c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
|
||||
assert.Assert(c, fields[len(fields)-2] != expected, fmt.Sprintf("Should not got %v", expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
||||
func (s *DockerSuite) TestPsShowMounts(c *testing.T) {
|
||||
existingContainers := ExistingContainerNames(c)
|
||||
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
|
@ -618,9 +615,9 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
dockerCmd(c, "volume", "create", "ps-volume-test")
|
||||
// volume mount containers
|
||||
runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
|
||||
c.Assert(waitRun("volume-test-1"), checker.IsNil)
|
||||
assert.Assert(c, waitRun("volume-test-1") == nil)
|
||||
runSleepingContainer(c, "--name=volume-test-2", "--volume", mp)
|
||||
c.Assert(waitRun("volume-test-2"), checker.IsNil)
|
||||
assert.Assert(c, waitRun("volume-test-2") == nil)
|
||||
// bind mount container
|
||||
var bindMountSource string
|
||||
var bindMountDestination string
|
||||
|
@ -632,7 +629,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
bindMountDestination = "/t"
|
||||
}
|
||||
runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination)
|
||||
c.Assert(waitRun("bind-mount-test"), checker.IsNil)
|
||||
assert.Assert(c, waitRun("bind-mount-test") == nil)
|
||||
|
||||
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
|
||||
|
||||
|
@ -642,8 +639,8 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
|
||||
fields := strings.Fields(lines[0])
|
||||
assert.Equal(c, len(fields), 2)
|
||||
c.Assert(fields[0], checker.Equals, "bind-mount-test")
|
||||
c.Assert(fields[1], checker.Equals, bindMountSource)
|
||||
assert.Equal(c, fields[0], "bind-mount-test")
|
||||
assert.Equal(c, fields[1], bindMountSource)
|
||||
|
||||
fields = strings.Fields(lines[1])
|
||||
assert.Equal(c, len(fields), 2)
|
||||
|
@ -651,7 +648,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
anonymousVolumeID := fields[1]
|
||||
|
||||
fields = strings.Fields(lines[2])
|
||||
c.Assert(fields[1], checker.Equals, "ps-volume-test")
|
||||
assert.Equal(c, fields[1], "ps-volume-test")
|
||||
|
||||
// filter by volume name
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=ps-volume-test")
|
||||
|
@ -661,11 +658,11 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
assert.Equal(c, len(lines), 1)
|
||||
|
||||
fields = strings.Fields(lines[0])
|
||||
c.Assert(fields[1], checker.Equals, "ps-volume-test")
|
||||
assert.Equal(c, fields[1], "ps-volume-test")
|
||||
|
||||
// empty results filtering by unknown volume
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=this-volume-should-not-exist")
|
||||
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
|
||||
assert.Equal(c, len(strings.TrimSpace(string(out))), 0)
|
||||
|
||||
// filter by mount destination
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp)
|
||||
|
@ -675,9 +672,9 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
assert.Equal(c, len(lines), 2)
|
||||
|
||||
fields = strings.Fields(lines[0])
|
||||
c.Assert(fields[1], checker.Equals, anonymousVolumeID)
|
||||
assert.Equal(c, fields[1], anonymousVolumeID)
|
||||
fields = strings.Fields(lines[1])
|
||||
c.Assert(fields[1], checker.Equals, "ps-volume-test")
|
||||
assert.Equal(c, fields[1], "ps-volume-test")
|
||||
|
||||
// filter by bind mount source
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
|
||||
|
@ -688,8 +685,8 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
|
||||
fields = strings.Fields(lines[0])
|
||||
assert.Equal(c, len(fields), 2)
|
||||
c.Assert(fields[0], checker.Equals, "bind-mount-test")
|
||||
c.Assert(fields[1], checker.Equals, bindMountSource)
|
||||
assert.Equal(c, fields[0], "bind-mount-test")
|
||||
assert.Equal(c, fields[1], bindMountSource)
|
||||
|
||||
// filter by bind mount destination
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
|
||||
|
@ -700,15 +697,15 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
|
||||
fields = strings.Fields(lines[0])
|
||||
assert.Equal(c, len(fields), 2)
|
||||
c.Assert(fields[0], checker.Equals, "bind-mount-test")
|
||||
c.Assert(fields[1], checker.Equals, bindMountSource)
|
||||
assert.Equal(c, fields[0], "bind-mount-test")
|
||||
assert.Equal(c, fields[1], bindMountSource)
|
||||
|
||||
// empty results filtering by unknown mount point
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
|
||||
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
|
||||
assert.Equal(c, len(strings.TrimSpace(string(out))), 0)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *testing.T) {
|
||||
existing := ExistingContainerIDs(c)
|
||||
|
||||
// TODO default network on Windows is not called "bridge", and creating a
|
||||
|
@ -743,8 +740,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|||
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 1)
|
||||
|
||||
// Making sure onbridgenetwork is on the output
|
||||
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
|
||||
|
||||
assert.Assert(c, strings.Contains(containerOut, "onbridgenetwork"), "Missing the container on network\n")
|
||||
// Filter docker ps on networks bridge and none
|
||||
out, _ = dockerCmd(c, "ps", "--filter", "network=bridge", "--filter", "network=none")
|
||||
containerOut = strings.TrimSpace(string(out))
|
||||
|
@ -758,9 +754,8 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|||
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 2)
|
||||
|
||||
// Making sure onbridgenetwork and onnonenetwork is on the output
|
||||
c.Assert(containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
|
||||
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n"))
|
||||
|
||||
assert.Assert(c, strings.Contains(containerOut, "onnonenetwork"), "Missing the container on none network\n")
|
||||
assert.Assert(c, strings.Contains(containerOut, "onbridgenetwork"), "Missing the container on bridge network\n")
|
||||
nwID, _ := dockerCmd(c, "network", "inspect", "--format", "{{.ID}}", "bridge")
|
||||
|
||||
// Filter by network ID
|
||||
|
@ -784,11 +779,10 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|||
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 1)
|
||||
|
||||
// Making sure onbridgenetwork is on the output
|
||||
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
|
||||
|
||||
assert.Assert(c, strings.Contains(containerOut, "onbridgenetwork"), "Missing the container on network\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsByOrder(c *check.C) {
|
||||
func (s *DockerSuite) TestPsByOrder(c *testing.T) {
|
||||
out := runSleepingContainer(c, "--name", "xyz-abc")
|
||||
container1 := strings.TrimSpace(out)
|
||||
|
||||
|
@ -807,7 +801,7 @@ func (s *DockerSuite) TestPsByOrder(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), fmt.Sprintf("%s\n%s", container2, container1))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
||||
func (s *DockerSuite) TestPsListContainersFilterPorts(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
||||
|
@ -818,32 +812,31 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
|||
id2 := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-8080/udp")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8081")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-81")
|
||||
assert.Equal(c, strings.TrimSpace(out), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=80/tcp")
|
||||
assert.Equal(c, strings.TrimSpace(out), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8080/tcp")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Equal(c, strings.TrimSpace(out), id2)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31"))
|
||||
existingContainers := ExistingContainerNames(c)
|
||||
|
||||
|
|
|
@ -8,14 +8,13 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/manifest"
|
||||
"github.com/docker/distribution/manifest/manifestlist"
|
||||
"github.com/docker/distribution/manifest/schema2"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
|
@ -25,7 +24,7 @@ import (
|
|||
// tags for the same image) are not also pulled down.
|
||||
//
|
||||
// Ref: docker/docker#8141
|
||||
func testPullImageWithAliases(c *check.C) {
|
||||
func testPullImageWithAliases(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
||||
var repos []string
|
||||
|
@ -52,16 +51,16 @@ func testPullImageWithAliases(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullImageWithAliases(c *testing.T) {
|
||||
testPullImageWithAliases(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullImageWithAliases(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullImageWithAliases(c *testing.T) {
|
||||
testPullImageWithAliases(c)
|
||||
}
|
||||
|
||||
// testConcurrentPullWholeRepo pulls the same repo concurrently.
|
||||
func testConcurrentPullWholeRepo(c *check.C) {
|
||||
func testConcurrentPullWholeRepo(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
||||
var repos []string
|
||||
|
@ -108,16 +107,16 @@ func testConcurrentPullWholeRepo(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) testConcurrentPullWholeRepo(c *check.C) {
|
||||
func (s *DockerRegistrySuite) testConcurrentPullWholeRepo(c *testing.T) {
|
||||
testConcurrentPullWholeRepo(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) testConcurrentPullWholeRepo(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) testConcurrentPullWholeRepo(c *testing.T) {
|
||||
testConcurrentPullWholeRepo(c)
|
||||
}
|
||||
|
||||
// testConcurrentFailingPull tries a concurrent pull that doesn't succeed.
|
||||
func testConcurrentFailingPull(c *check.C) {
|
||||
func testConcurrentFailingPull(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
||||
// Run multiple pulls concurrently
|
||||
|
@ -139,17 +138,17 @@ func testConcurrentFailingPull(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) testConcurrentFailingPull(c *check.C) {
|
||||
func (s *DockerRegistrySuite) testConcurrentFailingPull(c *testing.T) {
|
||||
testConcurrentFailingPull(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) testConcurrentFailingPull(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) testConcurrentFailingPull(c *testing.T) {
|
||||
testConcurrentFailingPull(c)
|
||||
}
|
||||
|
||||
// testConcurrentPullMultipleTags pulls multiple tags from the same repo
|
||||
// concurrently.
|
||||
func testConcurrentPullMultipleTags(c *check.C) {
|
||||
func testConcurrentPullMultipleTags(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
||||
var repos []string
|
||||
|
@ -195,17 +194,17 @@ func testConcurrentPullMultipleTags(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) {
|
||||
testConcurrentPullMultipleTags(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestConcurrentPullMultipleTags(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) {
|
||||
testConcurrentPullMultipleTags(c)
|
||||
}
|
||||
|
||||
// testPullIDStability verifies that pushing an image and pulling it back
|
||||
// preserves the image ID.
|
||||
func testPullIDStability(c *check.C) {
|
||||
func testPullIDStability(c *testing.T) {
|
||||
derivedImage := privateRegistryURL + "/dockercli/id-stability"
|
||||
baseImage := "busybox"
|
||||
|
||||
|
@ -256,16 +255,16 @@ func testPullIDStability(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullIDStability(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullIDStability(c *testing.T) {
|
||||
testPullIDStability(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *testing.T) {
|
||||
testPullIDStability(c)
|
||||
}
|
||||
|
||||
// #21213
|
||||
func testPullNoLayers(c *check.C) {
|
||||
func testPullNoLayers(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL)
|
||||
|
||||
buildImageSuccessfully(c, repoName, build.WithDockerfile(`
|
||||
|
@ -276,15 +275,15 @@ func testPullNoLayers(c *check.C) {
|
|||
dockerCmd(c, "pull", repoName)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullNoLayers(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullNoLayers(c *testing.T) {
|
||||
testPullNoLayers(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPullNoLayers(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPullNoLayers(c *testing.T) {
|
||||
testPullNoLayers(c)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
|
||||
testRequires(c, NotArm)
|
||||
pushDigest, err := setupImage(c)
|
||||
assert.NilError(c, err, "error setting up image")
|
||||
|
@ -340,10 +339,10 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
|
|||
// Add to revision store
|
||||
revisionDir := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "revisions", "sha256", hexDigest)
|
||||
err = os.Mkdir(revisionDir, 0755)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error creating revision dir"))
|
||||
assert.Assert(c, err == nil, "error creating revision dir")
|
||||
revisionPath := filepath.Join(revisionDir, "link")
|
||||
err = ioutil.WriteFile(revisionPath, []byte(manifestListDigest.String()), 0644)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error writing revision link"))
|
||||
assert.Assert(c, err == nil, "error writing revision link")
|
||||
|
||||
// Update tag
|
||||
tagPath := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "tags", "latest", "current", "link")
|
||||
|
@ -355,7 +354,7 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
|
|||
|
||||
// The pull output includes "Digest: <digest>", so find that
|
||||
matches := digestRegex.FindStringSubmatch(out)
|
||||
c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
|
||||
assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out))
|
||||
pullDigest := matches[1]
|
||||
|
||||
// Make sure the pushed and pull digests match
|
||||
|
@ -368,7 +367,7 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
|
|||
}
|
||||
|
||||
// #23100
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithScheme(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithScheme(c *testing.T) {
|
||||
osPath := os.Getenv("PATH")
|
||||
defer os.Setenv("PATH", osPath)
|
||||
|
||||
|
@ -395,8 +394,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
|
|||
|
||||
b, err := ioutil.ReadFile(configPath)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
|
||||
|
||||
assert.Assert(c, !strings.Contains(string(b), "\"auth\":"))
|
||||
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
|
||||
dockerCmd(c, "--config", tmp, "push", repoName)
|
||||
|
||||
|
@ -413,7 +411,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
|
|||
dockerCmd(c, "--config", tmp, "logout", "https://"+privateRegistryURL)
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T) {
|
||||
osPath := os.Getenv("PATH")
|
||||
defer os.Setenv("PATH", osPath)
|
||||
|
||||
|
@ -440,8 +438,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *check.C) {
|
|||
|
||||
b, err := ioutil.ReadFile(configPath)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
|
||||
|
||||
assert.Assert(c, !strings.Contains(string(b), "\"auth\":"))
|
||||
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
|
||||
dockerCmd(c, "--config", tmp, "push", repoName)
|
||||
|
||||
|
@ -449,7 +446,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *check.C) {
|
|||
}
|
||||
|
||||
// TestRunImplicitPullWithNoTag should pull implicitly only the default tag (latest)
|
||||
func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repo := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
repoTag1 := fmt.Sprintf("%v:latest", repo)
|
||||
|
@ -462,10 +459,9 @@ func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) {
|
|||
dockerCmd(c, "rmi", repoTag2)
|
||||
|
||||
out, _ := dockerCmd(c, "run", repo)
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Unable to find image '%s:latest' locally", repo)))
|
||||
// There should be only one line for repo, the one with repo:latest
|
||||
outImageCmd, _ := dockerCmd(c, "images", repo)
|
||||
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
|
||||
c.Assert(splitOutImageCmd, checker.HasLen, 2)
|
||||
assert.Equal(c, len(splitOutImageCmd), 2)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client
|
||||
// prints all expected output.
|
||||
func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out := s.Cmd(c, "pull", "hello-world")
|
||||
defer deleteImages("hello-world")
|
||||
|
@ -40,7 +40,7 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) {
|
|||
|
||||
// TestPullNonExistingImage pulls non-existing images from the central registry, with different
|
||||
// combinations of implicit tag and library prefix.
|
||||
func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullNonExistingImage(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
type entry struct {
|
||||
|
@ -115,7 +115,7 @@ func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) {
|
|||
// that pulling the same image with different combinations of implicit elements of the image
|
||||
// reference (tag, repository, central registry url, ...) doesn't trigger a new pull nor leads to
|
||||
// multiple images.
|
||||
func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
// Pull hello-world from v2
|
||||
|
@ -184,7 +184,7 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *chec
|
|||
}
|
||||
|
||||
// TestPullScratchNotAllowed verifies that pulling 'scratch' is rejected.
|
||||
func (s *DockerHubPullSuite) TestPullScratchNotAllowed(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullScratchNotAllowed(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, err := s.CmdWithError("pull", "scratch")
|
||||
assert.ErrorContains(c, err, "", "expected pull of scratch to fail")
|
||||
|
@ -194,7 +194,7 @@ func (s *DockerHubPullSuite) TestPullScratchNotAllowed(c *check.C) {
|
|||
|
||||
// TestPullAllTagsFromCentralRegistry pulls using `all-tags` for a given image and verifies that it
|
||||
// results in more images than a naked pull.
|
||||
func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
s.Cmd(c, "pull", "dockercore/engine-pull-all-test-fixture")
|
||||
outImageCmd := s.Cmd(c, "images", "dockercore/engine-pull-all-test-fixture")
|
||||
|
@ -238,7 +238,7 @@ func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
|
|||
// gets cancelled.
|
||||
//
|
||||
// Ref: docker/docker#15589
|
||||
func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TestPullClientDisconnect(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repoName := "hello-world:latest"
|
||||
|
||||
|
@ -263,14 +263,14 @@ func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) {
|
|||
}
|
||||
|
||||
// Regression test for https://github.com/docker/docker/issues/26429
|
||||
func (s *DockerSuite) TestPullLinuxImageFailsOnWindows(c *check.C) {
|
||||
func (s *DockerSuite) TestPullLinuxImageFailsOnWindows(c *testing.T) {
|
||||
testRequires(c, DaemonIsWindows, Network)
|
||||
_, _, err := dockerCmdWithError("pull", "ubuntu")
|
||||
assert.ErrorContains(c, err, "no matching manifest for windows")
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/docker/docker/issues/28892
|
||||
func (s *DockerSuite) TestPullWindowsImageFailsOnLinux(c *check.C) {
|
||||
func (s *DockerSuite) TestPullWindowsImageFailsOnLinux(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, Network)
|
||||
_, _, err := dockerCmdWithError("pull", "mcr.microsoft.com/windows/servercore:ltsc2019")
|
||||
assert.ErrorContains(c, err, "no matching manifest for linux")
|
||||
|
|
|
@ -9,16 +9,16 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// Pushing an image to a private registry.
|
||||
func testPushBusyboxImage(c *check.C) {
|
||||
func testPushBusyboxImage(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
// tag the image to upload it to the private registry
|
||||
dockerCmd(c, "tag", "busybox", repoName)
|
||||
|
@ -26,21 +26,21 @@ func testPushBusyboxImage(c *check.C) {
|
|||
dockerCmd(c, "push", repoName)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) {
|
||||
testPushBusyboxImage(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPushBusyboxImage(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPushBusyboxImage(c *testing.T) {
|
||||
testPushBusyboxImage(c)
|
||||
}
|
||||
|
||||
// pushing an image without a prefix should throw an error
|
||||
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
|
||||
func (s *DockerSuite) TestPushUnprefixedRepo(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("push", "busybox")
|
||||
assert.ErrorContains(c, err, "", "pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
||||
}
|
||||
|
||||
func testPushUntagged(c *check.C) {
|
||||
func testPushUntagged(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
expected := "An image does not exist locally with the tag"
|
||||
|
||||
|
@ -49,15 +49,15 @@ func testPushUntagged(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected), "pushing the image failed")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPushUntagged(c *testing.T) {
|
||||
testPushUntagged(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPushUntagged(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPushUntagged(c *testing.T) {
|
||||
testPushUntagged(c)
|
||||
}
|
||||
|
||||
func testPushBadTag(c *check.C) {
|
||||
func testPushBadTag(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
||||
expected := "does not exist"
|
||||
|
||||
|
@ -66,15 +66,15 @@ func testPushBadTag(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected), "pushing the image failed")
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPushBadTag(c *testing.T) {
|
||||
testPushBadTag(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPushBadTag(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPushBadTag(c *testing.T) {
|
||||
testPushBadTag(c)
|
||||
}
|
||||
|
||||
func testPushMultipleTags(c *check.C) {
|
||||
func testPushMultipleTags(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
|
||||
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
|
||||
|
@ -111,15 +111,15 @@ func testPushMultipleTags(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
|
||||
testPushMultipleTags(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPushMultipleTags(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPushMultipleTags(c *testing.T) {
|
||||
testPushMultipleTags(c)
|
||||
}
|
||||
|
||||
func testPushEmptyLayer(c *check.C) {
|
||||
func testPushEmptyLayer(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
||||
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
||||
assert.NilError(c, err, "Unable to create test file")
|
||||
|
@ -142,17 +142,17 @@ func testPushEmptyLayer(c *check.C) {
|
|||
assert.NilError(c, err, "pushing the image to the private registry has failed: %s", out)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *testing.T) {
|
||||
testPushEmptyLayer(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestPushEmptyLayer(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestPushEmptyLayer(c *testing.T) {
|
||||
testPushEmptyLayer(c)
|
||||
}
|
||||
|
||||
// testConcurrentPush pushes multiple tags to the same repo
|
||||
// concurrently.
|
||||
func testConcurrentPush(c *check.C) {
|
||||
func testConcurrentPush(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
|
||||
var repos []string
|
||||
|
@ -196,15 +196,15 @@ func testConcurrentPush(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestConcurrentPush(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestConcurrentPush(c *testing.T) {
|
||||
testConcurrentPush(c)
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestConcurrentPush(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestConcurrentPush(c *testing.T) {
|
||||
testConcurrentPush(c)
|
||||
}
|
||||
|
||||
func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
|
||||
sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
// tag the image to upload it to the private registry
|
||||
dockerCmd(c, "tag", "busybox", sourceRepoName)
|
||||
|
@ -246,7 +246,7 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *check.C) {
|
|||
assert.Equal(c, out4, "hello world")
|
||||
}
|
||||
|
||||
func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c *check.C) {
|
||||
func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c *testing.T) {
|
||||
sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
// tag the image to upload it to the private registry
|
||||
dockerCmd(c, "tag", "busybox", sourceRepoName)
|
||||
|
@ -279,7 +279,7 @@ func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c
|
|||
assert.Assert(c, out3 == "hello world")
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *check.C) {
|
||||
func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *testing.T) {
|
||||
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
||||
dockerCmd(c, "tag", "busybox", repoName)
|
||||
out, _, err := dockerCmdWithError("push", repoName)
|
||||
|
@ -289,7 +289,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *check.
|
|||
}
|
||||
|
||||
// This may be flaky but it's needed not to regress on unauthorized push, see #21054
|
||||
func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *check.C) {
|
||||
func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
repoName := "test/busybox"
|
||||
dockerCmd(c, "tag", "busybox", repoName)
|
||||
|
@ -316,7 +316,7 @@ func getTestTokenService(status int, body string, retries int) *httptest.Server
|
|||
}))
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *testing.T) {
|
||||
ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`, 0)
|
||||
defer ts.Close()
|
||||
s.setupRegistryWithTokenService(c, ts.URL)
|
||||
|
@ -328,7 +328,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *che
|
|||
assert.Assert(c, strings.Contains(out, "unauthorized: a message"))
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnauthorized(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnauthorized(c *testing.T) {
|
||||
ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`, 0)
|
||||
defer ts.Close()
|
||||
s.setupRegistryWithTokenService(c, ts.URL)
|
||||
|
@ -341,7 +341,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
|
|||
assert.Equal(c, split[len(split)-2], "unauthorized: authentication required")
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseError(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseError(c *testing.T) {
|
||||
ts := getTestTokenService(http.StatusTooManyRequests, `{"errors": [{"code":"TOOMANYREQUESTS","message":"out of tokens"}]}`, 3)
|
||||
defer ts.Close()
|
||||
s.setupRegistryWithTokenService(c, ts.URL)
|
||||
|
@ -356,7 +356,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
|
|||
assert.Equal(c, split[len(split)-2], "toomanyrequests: out of tokens")
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnparsable(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnparsable(c *testing.T) {
|
||||
ts := getTestTokenService(http.StatusForbidden, `no way`, 0)
|
||||
defer ts.Close()
|
||||
s.setupRegistryWithTokenService(c, ts.URL)
|
||||
|
@ -369,7 +369,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
|
|||
assert.Assert(c, strings.Contains(split[len(split)-2], "error parsing HTTP 403 response body: "))
|
||||
}
|
||||
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseNoToken(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseNoToken(c *testing.T) {
|
||||
ts := getTestTokenService(http.StatusOK, `{"something": "wrong"}`, 0)
|
||||
defer ts.Close()
|
||||
s.setupRegistryWithTokenService(c, ts.URL)
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/registry"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -29,7 +29,7 @@ func unescapeBackslashSemicolonParens(s string) string {
|
|||
return string(ret)
|
||||
}
|
||||
|
||||
func regexpCheckUA(c *check.C, ua string) {
|
||||
func regexpCheckUA(c *testing.T, ua string) {
|
||||
re := regexp.MustCompile("(?P<dockerUA>.+) UpstreamClient(?P<upstreamUA>.+)")
|
||||
substrArr := re.FindStringSubmatch(ua)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func registerUserAgentHandler(reg *registry.Mock, result *string) {
|
|||
// TestUserAgentPassThrough verifies that when an image is pulled from
|
||||
// a registry, the registry should see a User-Agent string of the form
|
||||
// [docker engine UA] UpstreamClientSTREAM-CLIENT([client UA])
|
||||
func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *testing.T) {
|
||||
var ua string
|
||||
|
||||
reg, err := registry.NewMock(c)
|
||||
|
|
|
@ -4,15 +4,16 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartStoppedContainer(c *testing.T) {
|
||||
dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar")
|
||||
cleanedContainerID := getIDByName(c, "test")
|
||||
|
||||
|
@ -29,30 +30,30 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
|
|||
assert.Equal(c, out, "foobar\nfoobar\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartRunningContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartRunningContainer(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
assert.NilError(c, waitRun(cleanedContainerID))
|
||||
|
||||
getLogs := func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
getLogs := func(c *testing.T) (interface{}, string) {
|
||||
out, _ := dockerCmd(c, "logs", cleanedContainerID)
|
||||
return out, nil
|
||||
return out, ""
|
||||
}
|
||||
|
||||
// Wait 10 seconds for the 'echo' to appear in the logs
|
||||
waitAndAssert(c, 10*time.Second, getLogs, checker.Equals, "foobar\n")
|
||||
poll.WaitOn(c, pollCheck(c, getLogs, checker.Equals("foobar\n")), poll.WithTimeout(10*time.Second))
|
||||
|
||||
dockerCmd(c, "restart", "-t", "1", cleanedContainerID)
|
||||
assert.NilError(c, waitRun(cleanedContainerID))
|
||||
|
||||
// Wait 10 seconds for first 'echo' appear (again) in the logs
|
||||
waitAndAssert(c, 10*time.Second, getLogs, checker.Equals, "foobar\nfoobar\n")
|
||||
poll.WaitOn(c, pollCheck(c, getLogs, checker.Equals("foobar\nfoobar\n")), poll.WithTimeout(10*time.Second))
|
||||
}
|
||||
|
||||
// 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 *check.C) {
|
||||
func (s *DockerSuite) TestRestartWithVolumes(c *testing.T) {
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
out := runSleepingContainer(c, "-d", "-v", prefix+slash+"test")
|
||||
|
||||
|
@ -77,7 +78,7 @@ func (s *DockerSuite) TestRestartWithVolumes(c *check.C) {
|
|||
assert.Equal(c, source, sourceAfterRestart)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartDisconnectedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartDisconnectedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm)
|
||||
|
||||
// Run a container on the default bridge network
|
||||
|
@ -94,7 +95,7 @@ func (s *DockerSuite) TestRestartDisconnectedContainer(c *check.C) {
|
|||
assert.Assert(c, exitCode == 0, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartPolicyNO(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "--restart=no", "busybox")
|
||||
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
@ -102,7 +103,7 @@ func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
|||
assert.Equal(c, name, "no")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartPolicyAlways(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "--restart=always", "busybox")
|
||||
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
@ -115,7 +116,7 @@ func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
|||
assert.Equal(c, MaximumRetryCount, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartPolicyOnFailure(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("create", "--restart=on-failure:-1", "busybox")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
assert.Assert(c, strings.Contains(out, "maximum retry count cannot be negative"))
|
||||
|
@ -150,7 +151,7 @@ func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
|||
|
||||
// a good container with --restart=on-failure:3
|
||||
// MaximumRetryCount!=0; RestartCount=0
|
||||
func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true")
|
||||
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
@ -164,7 +165,7 @@ func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *check.C) {
|
|||
assert.Equal(c, MaximumRetryCount, "3")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartContainerSuccess(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartContainerSuccess(c *testing.T) {
|
||||
// Skipped for Hyper-V isolated containers. Test is currently written
|
||||
// such that it assumes there is a host process to kill. In Hyper-V
|
||||
// containers, the process is inside the utility VM, not on the host.
|
||||
|
@ -193,7 +194,7 @@ func (s *DockerSuite) TestRestartContainerSuccess(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *testing.T) {
|
||||
// TODO Windows. This may be portable following HNS integration post TP5.
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace, NotArm)
|
||||
dockerCmd(c, "network", "create", "-d", "bridge", "udNet")
|
||||
|
@ -237,7 +238,7 @@ func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartPolicyAfterRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartPolicyAfterRestart(c *testing.T) {
|
||||
// Skipped for Hyper-V isolated containers. Test is currently written
|
||||
// such that it assumes there is a host process to kill. In Hyper-V
|
||||
// containers, the process is inside the utility VM, not on the host.
|
||||
|
@ -270,7 +271,7 @@ func (s *DockerSuite) TestRestartPolicyAfterRestart(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *testing.T) {
|
||||
out1, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false")
|
||||
out2, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false")
|
||||
|
||||
|
@ -301,7 +302,7 @@ func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRestartAutoRemoveContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestRestartAutoRemoveContainer(c *testing.T) {
|
||||
out := runSleepingContainer(c, "--rm")
|
||||
|
||||
id := strings.TrimSpace(string(out))
|
||||
|
|
|
@ -3,18 +3,17 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiWithContainerFails(c *testing.T) {
|
||||
errSubstr := "is using it"
|
||||
|
||||
// create a container
|
||||
|
@ -27,43 +26,42 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) {
|
|||
// Container is using image, should not be able to rmi
|
||||
assert.ErrorContains(c, err, "")
|
||||
// Container is using image, error message should contain errSubstr
|
||||
c.Assert(out, checker.Contains, errSubstr, check.Commentf("Container: %q", cleanedContainerID))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, errSubstr), fmt.Sprintf("Container: %q", cleanedContainerID))
|
||||
// make sure it didn't delete the busybox name
|
||||
images, _ := dockerCmd(c, "images")
|
||||
// The name 'busybox' should not have been removed from images
|
||||
c.Assert(images, checker.Contains, "busybox")
|
||||
assert.Assert(c, strings.Contains(images, "busybox"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiTag(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiTag(c *testing.T) {
|
||||
imagesBefore, _ := dockerCmd(c, "images", "-a")
|
||||
dockerCmd(c, "tag", "busybox", "utest:tag1")
|
||||
dockerCmd(c, "tag", "busybox", "utest/docker:tag2")
|
||||
dockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3")
|
||||
{
|
||||
imagesAfter, _ := dockerCmd(c, "images", "-a")
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+3, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+3, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
}
|
||||
dockerCmd(c, "rmi", "utest/docker:tag2")
|
||||
{
|
||||
imagesAfter, _ := dockerCmd(c, "images", "-a")
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
}
|
||||
dockerCmd(c, "rmi", "utest:5000/docker:tag3")
|
||||
{
|
||||
imagesAfter, _ := dockerCmd(c, "images", "-a")
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+1, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+1, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
|
||||
}
|
||||
dockerCmd(c, "rmi", "utest:tag1")
|
||||
{
|
||||
imagesAfter, _ := dockerCmd(c, "images", "-a")
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n"), check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n"), fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *testing.T) {
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined()
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
|
@ -81,7 +79,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
|||
|
||||
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
|
||||
// tag busybox to create 2 more images with same imageID
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, fmt.Sprintf("docker images shows: %q\n", imagesAfter))
|
||||
|
||||
imgID := inspectField(c, "busybox-one:tag1", "Id")
|
||||
|
||||
|
@ -101,10 +99,10 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
|||
|
||||
imagesAfter = cli.DockerCmd(c, "images", "-a").Combined()
|
||||
// rmi -f failed, image still exists
|
||||
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
|
||||
assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]), fmt.Sprintf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiImgIDForce(c *testing.T) {
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined()
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
|
@ -123,7 +121,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
|||
cli.DockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4")
|
||||
{
|
||||
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
|
||||
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+4, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
||||
}
|
||||
imgID := inspectField(c, "busybox-test", "Id")
|
||||
|
||||
|
@ -137,12 +135,12 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
|||
{
|
||||
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
|
||||
// rmi failed, image still exists
|
||||
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12])
|
||||
assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]))
|
||||
}
|
||||
}
|
||||
|
||||
// See https://github.com/docker/docker/issues/14116
|
||||
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *testing.T) {
|
||||
dockerfile := "FROM busybox\nRUN echo test 14116\n"
|
||||
buildImageSuccessfully(c, "test-14116", build.WithDockerfile(dockerfile))
|
||||
imgID := getIDByName(c, "test-14116")
|
||||
|
@ -154,10 +152,10 @@ func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c
|
|||
out, _, err := dockerCmdWithError("rmi", "-f", imgID)
|
||||
// rmi -f should not delete image with running containers
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "(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 *check.C) {
|
||||
func (s *DockerSuite) TestRmiTagWithExistingContainers(c *testing.T) {
|
||||
container := "test-delete-tag"
|
||||
newtag := "busybox:newtag"
|
||||
bb := "busybox:latest"
|
||||
|
@ -166,10 +164,10 @@ func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
|
|||
dockerCmd(c, "run", "--name", container, bb, "/bin/true")
|
||||
|
||||
out, _ := dockerCmd(c, "rmi", newtag)
|
||||
c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1)
|
||||
assert.Equal(c, strings.Count(out, "Untagged: "), 1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *testing.T) {
|
||||
image := "busybox-clone"
|
||||
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
|
@ -183,7 +181,7 @@ MAINTAINER foo`),
|
|||
dockerCmd(c, "rmi", "-f", image)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiWithMultipleRepositories(c *testing.T) {
|
||||
newRepo := "127.0.0.1:5000/busybox"
|
||||
oldRepo := "busybox"
|
||||
newTag := "busybox:test"
|
||||
|
@ -194,10 +192,10 @@ func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
|
|||
dockerCmd(c, "commit", "test", newTag)
|
||||
|
||||
out, _ := dockerCmd(c, "rmi", newTag)
|
||||
c.Assert(out, checker.Contains, "Untagged: "+newTag)
|
||||
assert.Assert(c, strings.Contains(out, "Untagged: "+newTag))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *testing.T) {
|
||||
imageName := "rmiimage"
|
||||
tag1 := imageName + ":tag1"
|
||||
tag2 := imageName + ":tag2"
|
||||
|
@ -207,25 +205,24 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
|
|||
dockerCmd(c, "tag", tag1, tag2)
|
||||
|
||||
out, _ := dockerCmd(c, "rmi", "-f", tag2)
|
||||
c.Assert(out, checker.Contains, "Untagged: "+tag2)
|
||||
c.Assert(out, checker.Not(checker.Contains), "Untagged: "+tag1)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "Untagged: "+tag2))
|
||||
assert.Assert(c, !strings.Contains(out, "Untagged: "+tag1))
|
||||
// Check built image still exists
|
||||
images, _ := dockerCmd(c, "images", "-a")
|
||||
c.Assert(images, checker.Contains, imageName, check.Commentf("Built image missing %q; Images: %q", imageName, images))
|
||||
assert.Assert(c, strings.Contains(images, imageName), fmt.Sprintf("Built image missing %q; Images: %q", imageName, images))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiBlank(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiBlank(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("rmi", " ")
|
||||
// Should have failed to delete ' ' image
|
||||
assert.ErrorContains(c, err, "")
|
||||
// Wrong error message generated
|
||||
c.Assert(out, checker.Not(checker.Contains), "no such id", check.Commentf("out: %s", out))
|
||||
assert.Assert(c, !strings.Contains(out, "no such id"), fmt.Sprintf("out: %s", out))
|
||||
// Expected error message not generated
|
||||
c.Assert(out, checker.Contains, "image name cannot be blank", check.Commentf("out: %s", out))
|
||||
assert.Assert(c, strings.Contains(out, "image name cannot be blank"), fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiContainerImageNotFound(c *testing.T) {
|
||||
// Build 2 images for testing.
|
||||
imageNames := []string{"test1", "test2"}
|
||||
imageIds := make([]string, 2)
|
||||
|
@ -247,11 +244,11 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
|
|||
out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0])
|
||||
// The image of the running container should not be removed.
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "image is being used by running container", check.Commentf("out: %s", out))
|
||||
assert.Assert(c, strings.Contains(out, "image is being used by running container"), fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
||||
// #13422
|
||||
func (s *DockerSuite) TestRmiUntagHistoryLayer(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiUntagHistoryLayer(c *testing.T) {
|
||||
image := "tmp1"
|
||||
// Build an image for testing.
|
||||
dockerfile := `FROM busybox
|
||||
|
@ -274,7 +271,7 @@ RUN echo 2 #layer2
|
|||
// See if the "tmp2" can be untagged.
|
||||
out, _ = dockerCmd(c, "rmi", newTag)
|
||||
// Expected 1 untagged entry
|
||||
c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1, check.Commentf("out: %s", out))
|
||||
assert.Equal(c, strings.Count(out, "Untagged: "), 1, fmt.Sprintf("out: %s", out))
|
||||
|
||||
// Now let's add the tag again and create a container based on it.
|
||||
dockerCmd(c, "tag", idToTag, newTag)
|
||||
|
@ -286,16 +283,15 @@ RUN echo 2 #layer2
|
|||
out, _, err := dockerCmdWithError("rmi", newTag)
|
||||
// should not be untagged without the -f flag
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, cid[:12])
|
||||
c.Assert(out, checker.Contains, "(must force)")
|
||||
|
||||
assert.Assert(c, strings.Contains(out, cid[:12]))
|
||||
assert.Assert(c, strings.Contains(out, "(must force)"))
|
||||
// Add the -f flag and test again.
|
||||
out, _ = dockerCmd(c, "rmi", "-f", newTag)
|
||||
// should be allowed to untag with the -f flag
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("Untagged: %s:latest", newTag))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Untagged: %s:latest", newTag)))
|
||||
}
|
||||
|
||||
func (*DockerSuite) TestRmiParentImageFail(c *check.C) {
|
||||
func (*DockerSuite) TestRmiParentImageFail(c *testing.T) {
|
||||
buildImageSuccessfully(c, "test", build.WithDockerfile(`
|
||||
FROM busybox
|
||||
RUN echo hello`))
|
||||
|
@ -308,7 +304,7 @@ func (*DockerSuite) TestRmiParentImageFail(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmiWithParentInUse(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiWithParentInUse(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "create", "busybox")
|
||||
cID := strings.TrimSpace(out)
|
||||
|
||||
|
@ -325,7 +321,7 @@ func (s *DockerSuite) TestRmiWithParentInUse(c *check.C) {
|
|||
}
|
||||
|
||||
// #18873
|
||||
func (s *DockerSuite) TestRmiByIDHardConflict(c *check.C) {
|
||||
func (s *DockerSuite) TestRmiByIDHardConflict(c *testing.T) {
|
||||
dockerCmd(c, "create", "busybox")
|
||||
|
||||
imgID := inspectField(c, "busybox:latest", "Id")
|
||||
|
@ -335,5 +331,5 @@ func (s *DockerSuite) TestRmiByIDHardConflict(c *check.C) {
|
|||
|
||||
// check that tag was not removed
|
||||
imgID2 := inspectField(c, "busybox:latest", "Id")
|
||||
c.Assert(imgID, checker.Equals, imgID2)
|
||||
assert.Equal(c, imgID, imgID2)
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,27 +15,26 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/pkg/homedir"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// #6509
|
||||
func (s *DockerSuite) TestRunRedirectStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestRunRedirectStdout(c *testing.T) {
|
||||
checkRedirect := func(command string) {
|
||||
_, tty, err := pty.Open()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Could not open pty"))
|
||||
assert.Assert(c, err == nil, "Could not open pty")
|
||||
cmd := exec.Command("sh", "-c", command)
|
||||
cmd.Stdin = tty
|
||||
cmd.Stdout = tty
|
||||
|
@ -51,7 +50,7 @@ func (s *DockerSuite) TestRunRedirectStdout(c *check.C) {
|
|||
case <-time.After(10 * time.Second):
|
||||
c.Fatal("command timeout")
|
||||
case err := <-ch:
|
||||
c.Assert(err, checker.IsNil, check.Commentf("wait err"))
|
||||
assert.Assert(c, err == nil, "wait err")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +59,7 @@ func (s *DockerSuite) TestRunRedirectStdout(c *check.C) {
|
|||
}
|
||||
|
||||
// Test recursive bind mount works by default
|
||||
func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *testing.T) {
|
||||
// /tmp gets permission denied
|
||||
testRequires(c, NotUserNamespace, testEnv.IsLocalDaemon)
|
||||
tmpDir, err := ioutil.TempDir("", "docker_recursive_mount_test")
|
||||
|
@ -70,32 +69,31 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
|
|||
|
||||
// Create a temporary tmpfs mount.
|
||||
tmpfsDir := filepath.Join(tmpDir, "tmpfs")
|
||||
c.Assert(os.MkdirAll(tmpfsDir, 0777), checker.IsNil, check.Commentf("failed to mkdir at %s", tmpfsDir))
|
||||
c.Assert(mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""), checker.IsNil, check.Commentf("failed to create a tmpfs mount at %s", tmpfsDir))
|
||||
assert.Assert(c, os.MkdirAll(tmpfsDir, 0777) == nil, fmt.Sprintf("failed to mkdir at %s", tmpfsDir))
|
||||
assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", "") == nil, fmt.Sprintf("failed to create a tmpfs mount at %s", tmpfsDir))
|
||||
|
||||
f, err := ioutil.TempFile(tmpfsDir, "touch-me")
|
||||
assert.NilError(c, err)
|
||||
defer f.Close()
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
|
||||
c.Assert(out, checker.Contains, filepath.Base(f.Name()), check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestRunDeviceDirectory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm)
|
||||
if _, err := os.Stat("/dev/snd"); err != nil {
|
||||
c.Skip("Host does not have /dev/snd")
|
||||
}
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/")
|
||||
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "timer", check.Commentf("expected output /dev/snd/timer"))
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.Trim(out, "\r\n"), "timer"), "expected output /dev/snd/timer")
|
||||
out, _ = dockerCmd(c, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/")
|
||||
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "seq", check.Commentf("expected output /dev/othersnd/seq"))
|
||||
assert.Assert(c, strings.Contains(strings.Trim(out, "\r\n"), "seq"), "expected output /dev/othersnd/seq")
|
||||
}
|
||||
|
||||
// TestRunAttachDetach checks attaching and detaching with the default escape sequence.
|
||||
func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachDetach(c *testing.T) {
|
||||
name := "attach-detach"
|
||||
|
||||
dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat")
|
||||
|
@ -108,7 +106,7 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
|||
defer cpty.Close()
|
||||
cmd.Stdin = tty
|
||||
assert.NilError(c, cmd.Start())
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
_, err = cpty.Write([]byte("hello\n"))
|
||||
assert.NilError(c, err)
|
||||
|
@ -137,16 +135,16 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
|||
}
|
||||
|
||||
running := inspectField(c, name, "State.Running")
|
||||
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
|
||||
assert.Equal(c, running, "true", "expected container to still be running")
|
||||
|
||||
out, _ = dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container="+name)
|
||||
// attach and detach event should be monitored
|
||||
c.Assert(out, checker.Contains, "attach")
|
||||
c.Assert(out, checker.Contains, "detach")
|
||||
assert.Assert(c, strings.Contains(out, "attach"))
|
||||
assert.Assert(c, strings.Contains(out, "detach"))
|
||||
}
|
||||
|
||||
// TestRunAttachDetachFromFlag checks attaching and detaching with the escape sequence specified via flags.
|
||||
func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachDetachFromFlag(c *testing.T) {
|
||||
name := "attach-detach"
|
||||
keyCtrlA := []byte{1}
|
||||
keyA := []byte{97}
|
||||
|
@ -167,7 +165,7 @@ func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) {
|
|||
if err := cmd.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
if _, err := cpty.Write([]byte("hello\n")); err != nil {
|
||||
c.Fatal(err)
|
||||
|
@ -203,14 +201,14 @@ func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) {
|
|||
}
|
||||
|
||||
running := inspectField(c, name, "State.Running")
|
||||
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
|
||||
assert.Equal(c, running, "true", "expected container to still be running")
|
||||
}
|
||||
|
||||
// TestRunAttachDetachFromInvalidFlag checks attaching and detaching with the escape sequence specified via flags.
|
||||
func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *testing.T) {
|
||||
name := "attach-detach"
|
||||
dockerCmd(c, "run", "--name", name, "-itd", "busybox", "top")
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
// specify an invalid detach key, container will ignore it and use default
|
||||
cmd := exec.Command(dockerBinary, "attach", "--detach-keys=ctrl-A,a", name)
|
||||
|
@ -240,7 +238,7 @@ func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *check.C) {
|
|||
}
|
||||
|
||||
// TestRunAttachDetachFromConfig checks attaching and detaching with the escape sequence specified via config file.
|
||||
func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachDetachFromConfig(c *testing.T) {
|
||||
keyCtrlA := []byte{1}
|
||||
keyA := []byte{97}
|
||||
|
||||
|
@ -283,7 +281,7 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) {
|
|||
if err := cmd.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
if _, err := cpty.Write([]byte("hello\n")); err != nil {
|
||||
c.Fatal(err)
|
||||
|
@ -319,11 +317,11 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) {
|
|||
}
|
||||
|
||||
running := inspectField(c, name, "State.Running")
|
||||
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
|
||||
assert.Equal(c, running, "true", "expected container to still be running")
|
||||
}
|
||||
|
||||
// TestRunAttachDetachKeysOverrideConfig checks attaching and detaching with the detach flags, making sure it overrides config file
|
||||
func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) {
|
||||
keyCtrlA := []byte{1}
|
||||
keyA := []byte{97}
|
||||
|
||||
|
@ -366,7 +364,7 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) {
|
|||
if err := cmd.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
if _, err := cpty.Write([]byte("hello\n")); err != nil {
|
||||
c.Fatal(err)
|
||||
|
@ -402,10 +400,10 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) {
|
|||
}
|
||||
|
||||
running := inspectField(c, name, "State.Running")
|
||||
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
|
||||
assert.Equal(c, running, "true", "expected container to still be running")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C) {
|
||||
func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *testing.T) {
|
||||
name := "attach-detach"
|
||||
keyA := []byte{97}
|
||||
keyB := []byte{98}
|
||||
|
@ -427,7 +425,7 @@ func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C)
|
|||
c.Fatal(err)
|
||||
}
|
||||
go cmd.Wait()
|
||||
c.Assert(waitRun(name), check.IsNil)
|
||||
assert.Assert(c, waitRun(name) == nil)
|
||||
|
||||
// Invalid escape sequence aba, should print aba in output
|
||||
if _, err := cpty.Write(keyA); err != nil {
|
||||
|
@ -456,7 +454,7 @@ func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C)
|
|||
}
|
||||
|
||||
// "test" should be printed
|
||||
func (s *DockerSuite) TestRunWithCPUQuota(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithCPUQuota(c *testing.T) {
|
||||
testRequires(c, cpuCfsQuota)
|
||||
|
||||
file := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
|
||||
|
@ -467,7 +465,7 @@ func (s *DockerSuite) TestRunWithCPUQuota(c *check.C) {
|
|||
assert.Equal(c, out, "8000", "setting the CPU CFS quota failed")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithCpuPeriod(c *testing.T) {
|
||||
testRequires(c, cpuCfsPeriod)
|
||||
|
||||
file := "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
|
||||
|
@ -481,7 +479,7 @@ func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
|||
assert.Equal(c, out, "50000", "setting the CPU CFS period failed")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *testing.T) {
|
||||
testRequires(c, cpuCfsPeriod)
|
||||
out, _, err := dockerCmdWithError("run", "--cpu-period", "900", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
|
@ -497,7 +495,7 @@ func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithKernelMemory(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithKernelMemory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
||||
|
||||
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes"
|
||||
|
@ -510,7 +508,7 @@ func (s *DockerSuite) TestRunWithKernelMemory(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidKernelMemory(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidKernelMemory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
||||
|
||||
out, _, err := dockerCmdWithError("run", "--kernel-memory", "2M", "busybox", "true")
|
||||
|
@ -524,7 +522,7 @@ func (s *DockerSuite) TestRunWithInvalidKernelMemory(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithCPUShares(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithCPUShares(c *testing.T) {
|
||||
testRequires(c, cpuShare)
|
||||
|
||||
file := "/sys/fs/cgroup/cpu/cpu.shares"
|
||||
|
@ -536,7 +534,7 @@ func (s *DockerSuite) TestRunWithCPUShares(c *check.C) {
|
|||
}
|
||||
|
||||
// "test" should be printed
|
||||
func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *testing.T) {
|
||||
testRequires(c, cpuShare)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
cli.DockerCmd(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test").Assert(c, icmd.Expected{
|
||||
|
@ -544,7 +542,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithCpusetCpus(c *testing.T) {
|
||||
testRequires(c, cgroupCpuset)
|
||||
|
||||
file := "/sys/fs/cgroup/cpuset/cpuset.cpus"
|
||||
|
@ -555,7 +553,7 @@ func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) {
|
|||
assert.Equal(c, out, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithCpusetMems(c *testing.T) {
|
||||
testRequires(c, cgroupCpuset)
|
||||
|
||||
file := "/sys/fs/cgroup/cpuset/cpuset.mems"
|
||||
|
@ -566,7 +564,7 @@ func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) {
|
|||
assert.Equal(c, out, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithBlkioWeight(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
|
||||
file := "/sys/fs/cgroup/blkio/blkio.weight"
|
||||
|
@ -577,7 +575,7 @@ func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) {
|
|||
assert.Equal(c, out, "300")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--blkio-weight", "5", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
|
@ -585,37 +583,37 @@ func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioWeightDevice(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioWeightDevice(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--blkio-weight-device", "/dev/sdX:100", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadBps(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadBps(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--device-read-bps", "/dev/sdX:500", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteBps(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteBps(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--device-write-bps", "/dev/sdX:500", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadIOps(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadIOps(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--device-read-iops", "/dev/sdX:500", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteIOps(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteIOps(c *testing.T) {
|
||||
testRequires(c, blkioWeight)
|
||||
out, _, err := dockerCmdWithError("run", "--device-write-iops", "/dev/sdX:500", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
||||
func (s *DockerSuite) TestRunOOMExitCode(c *testing.T) {
|
||||
testRequires(c, memoryLimitSupport, swapMemorySupport, NotPpc64le)
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
|
@ -635,7 +633,7 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithMemoryLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithMemoryLimit(c *testing.T) {
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
||||
|
@ -651,14 +649,14 @@ func (s *DockerSuite) TestRunWithMemoryLimit(c *check.C) {
|
|||
// memory limit, this means the processes in the container can use
|
||||
// 16M memory and as much swap memory as they need (if the host
|
||||
// supports swap memory).
|
||||
func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, swapMemorySupport)
|
||||
dockerCmd(c, "run", "-m", "32m", "--memory-swap", "-1", "busybox", "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithSwappiness(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithSwappiness(c *testing.T) {
|
||||
testRequires(c, memorySwappinessSupport)
|
||||
file := "/sys/fs/cgroup/memory/memory.swappiness"
|
||||
out, _ := dockerCmd(c, "run", "--memory-swappiness", "0", "--name", "test", "busybox", "cat", file)
|
||||
|
@ -668,19 +666,18 @@ func (s *DockerSuite) TestRunWithSwappiness(c *check.C) {
|
|||
assert.Equal(c, out, "0")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithSwappinessInvalid(c *testing.T) {
|
||||
testRequires(c, memorySwappinessSupport)
|
||||
out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
expected := "Valid memory swappiness range is 0-100"
|
||||
c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, expected), fmt.Sprintf("Expected output to contain %q, not %q", out, expected))
|
||||
out, _, err = dockerCmdWithError("run", "--memory-swappiness", "-10", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
|
||||
assert.Assert(c, strings.Contains(out, expected), fmt.Sprintf("Expected output to contain %q, not %q", out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithMemoryReservation(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport)
|
||||
|
||||
file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"
|
||||
|
@ -691,33 +688,32 @@ func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
|
|||
assert.Equal(c, out, "209715200")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *testing.T) {
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, testEnv.IsLocalDaemon, memoryReservationSupport)
|
||||
out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
expected := "Minimum memory limit can not be less than memory reservation limit"
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("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")
|
||||
out, _, err = dockerCmdWithError("run", "--memory-reservation", "1k", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
expected = "Minimum memory reservation allowed is 4MB"
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) 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`)
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
c.Assert(waitRun(containerID), checker.IsNil)
|
||||
assert.Assert(c, waitRun(containerID) == nil)
|
||||
|
||||
dockerCmd(c, "stop", containerID)
|
||||
out, _ = dockerCmd(c, "logs", containerID)
|
||||
|
||||
c.Assert(out, checker.Contains, "exit trapped", check.Commentf("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 *check.C) {
|
||||
func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *testing.T) {
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, swapMemorySupport)
|
||||
out, _, err := dockerCmdWithError("run", "-m", "16m", "--memory-swap", "15m", "busybox", "echo", "test")
|
||||
|
@ -727,7 +723,7 @@ func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *check.C) {
|
||||
func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) {
|
||||
testRequires(c, cgroupCpuset, testEnv.IsLocalDaemon)
|
||||
|
||||
sysInfo := sysinfo.New(true)
|
||||
|
@ -746,7 +742,7 @@ func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *check.C) {
|
||||
func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *testing.T) {
|
||||
testRequires(c, cgroupCpuset)
|
||||
|
||||
sysInfo := sysinfo.New(true)
|
||||
|
@ -765,7 +761,7 @@ func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunInvalidCPUShares(c *check.C) {
|
||||
func (s *DockerSuite) TestRunInvalidCPUShares(c *testing.T) {
|
||||
testRequires(c, cpuShare, DaemonIsLinux)
|
||||
out, _, err := dockerCmdWithError("run", "--cpu-shares", "1", "busybox", "echo", "test")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
|
@ -783,7 +779,7 @@ func (s *DockerSuite) TestRunInvalidCPUShares(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithDefaultShmSize(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithDefaultShmSize(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
name := "shm-default"
|
||||
|
@ -793,10 +789,10 @@ func (s *DockerSuite) TestRunWithDefaultShmSize(c *check.C) {
|
|||
c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
|
||||
}
|
||||
shmSize := inspectField(c, name, "HostConfig.ShmSize")
|
||||
c.Assert(shmSize, check.Equals, "67108864")
|
||||
assert.Equal(c, shmSize, "67108864")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithShmSize(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithShmSize(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
name := "shm"
|
||||
|
@ -806,18 +802,18 @@ func (s *DockerSuite) TestRunWithShmSize(c *check.C) {
|
|||
c.Fatalf("Expected shm of 1GB in mount command, got %v", out)
|
||||
}
|
||||
shmSize := inspectField(c, name, "HostConfig.ShmSize")
|
||||
c.Assert(shmSize, check.Equals, "1073741824")
|
||||
assert.Equal(c, shmSize, "1073741824")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *check.C) {
|
||||
func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *testing.T) {
|
||||
tmpFile, err := ioutil.TempFile("", "test")
|
||||
assert.NilError(c, err)
|
||||
defer tmpFile.Close()
|
||||
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", "-v", tmpFile.Name()+":/run/test", "busybox", "ls", "/run")
|
||||
c.Assert(out, checker.Contains, "test")
|
||||
assert.Assert(c, strings.Contains(out, "test"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
|
||||
func (s *DockerSuite) TestRunTmpfsMounts(c *testing.T) {
|
||||
// TODO Windows (Post TP5): This test cannot run on a Windows daemon as
|
||||
// Windows does not support tmpfs mounts.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -838,7 +834,7 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
|
||||
func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *testing.T) {
|
||||
name := "img-with-volumes"
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`
|
||||
FROM busybox
|
||||
|
@ -846,37 +842,35 @@ func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
|
|||
RUN touch /run/stuff
|
||||
`))
|
||||
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run")
|
||||
c.Assert(out, checker.Not(checker.Contains), "stuff")
|
||||
assert.Assert(c, !strings.Contains(out, "stuff"))
|
||||
}
|
||||
|
||||
// Test case for #22420
|
||||
func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
|
||||
func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
expectedOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime"}
|
||||
out, _ := dockerCmd(c, "run", "--tmpfs", "/tmp", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
|
||||
for _, option := range expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
c.Assert(out, checker.Not(checker.Contains), "size=")
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, "size="))
|
||||
expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime"}
|
||||
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
|
||||
for _, option := range expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
c.Assert(out, checker.Not(checker.Contains), "size=")
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, "size="))
|
||||
expectedOptions = []string{"rw", "nosuid", "nodev", "relatime", "size=8192k"}
|
||||
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,exec,size=8192k", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
|
||||
for _, option := range expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
|
||||
expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k"}
|
||||
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,size=8192k,exec,size=4096k,noexec", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
|
||||
for _, option := range expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
|
||||
// We use debian:jessie as there is no findmnt in busybox. Also the output will be in the format of
|
||||
|
@ -886,32 +880,32 @@ func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
|
|||
expectedOptions = []string{"shared"}
|
||||
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:shared", "debian:jessie", "findmnt", "-o", "TARGET,PROPAGATION", "/tmp")
|
||||
for _, option := range expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
assert.Assert(c, strings.Contains(out, option))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunSysctls(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSysctls(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
var err error
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=1", "--name", "test", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "1")
|
||||
assert.Equal(c, strings.TrimSpace(out), "1")
|
||||
|
||||
out = inspectFieldJSON(c, "test", "HostConfig.Sysctls")
|
||||
|
||||
sysctls := make(map[string]string)
|
||||
err = json.Unmarshal([]byte(out), &sysctls)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "1")
|
||||
assert.Equal(c, sysctls["net.ipv4.ip_forward"], "1")
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=0", "--name", "test1", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "0")
|
||||
assert.Equal(c, strings.TrimSpace(out), "0")
|
||||
|
||||
out = inspectFieldJSON(c, "test1", "HostConfig.Sysctls")
|
||||
|
||||
err = json.Unmarshal([]byte(out), &sysctls)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0")
|
||||
assert.Equal(c, sysctls["net.ipv4.ip_forward"], "0")
|
||||
|
||||
icmd.RunCommand(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2",
|
||||
"busybox", "cat", "/proc/sys/kernel/foobar").Assert(c, icmd.Expected{
|
||||
|
@ -921,7 +915,7 @@ func (s *DockerSuite) TestRunSysctls(c *check.C) {
|
|||
}
|
||||
|
||||
// TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:jessie unshare' exits with operation not permitted.
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor)
|
||||
jsonData := `{
|
||||
"defaultAction": "SCMP_ACT_ALLOW",
|
||||
|
@ -950,7 +944,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *check.C) {
|
|||
}
|
||||
|
||||
// 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 *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
|
||||
jsonData := `{
|
||||
"defaultAction": "SCMP_ACT_ALLOW",
|
||||
|
@ -985,7 +979,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *check.C) {
|
|||
|
||||
// TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:jessie unshare --map-root-user --user sh -c whoami' with a specific profile to
|
||||
// deny unshare of a userns exits with operation not permitted.
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotArm, Apparmor)
|
||||
// from sched.h
|
||||
jsonData := fmt.Sprintf(`{
|
||||
|
@ -1023,7 +1017,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *check.C) {
|
|||
|
||||
// TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test'
|
||||
// with a the default seccomp profile exits with operation not permitted.
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1035,7 +1029,7 @@ func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *check.C) {
|
|||
|
||||
// TestRunSeccompUnconfinedCloneUserns checks that
|
||||
// 'docker run --security-opt seccomp=unconfined syscall-test' allows creating a userns.
|
||||
func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace, unprivilegedUsernsClone)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1048,7 +1042,7 @@ func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *check.C) {
|
|||
|
||||
// TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test'
|
||||
// allows creating a userns.
|
||||
func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1060,7 +1054,7 @@ func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *check.C) {
|
|||
|
||||
// TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64
|
||||
// with the default seccomp profile.
|
||||
func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, IsAmd64)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1068,14 +1062,14 @@ func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *check.C) {
|
|||
}
|
||||
|
||||
// TestRunSeccompAllowSetrlimit checks that 'docker run debian:jessie ulimit -v 1048510' succeeds.
|
||||
func (s *DockerSuite) TestRunSeccompAllowSetrlimit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompAllowSetrlimit(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
|
||||
|
||||
// ulimit uses setrlimit, so we want to make sure we don't break it
|
||||
icmd.RunCommand(dockerBinary, "run", "debian:jessie", "bash", "-c", "ulimit -v 1048510").Assert(c, icmd.Success)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1105,7 +1099,7 @@ func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, NotUserNamespace)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1142,7 +1136,7 @@ func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *check.C) {
|
|||
|
||||
// TestRunNoNewPrivSetuid checks that --security-opt='no-new-privileges=true' prevents
|
||||
// effective uid transitions on executing setuid binaries.
|
||||
func (s *DockerSuite) TestRunNoNewPrivSetuid(c *check.C) {
|
||||
func (s *DockerSuite) TestRunNoNewPrivSetuid(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
|
||||
ensureNNPTest(c)
|
||||
|
||||
|
@ -1155,7 +1149,7 @@ func (s *DockerSuite) TestRunNoNewPrivSetuid(c *check.C) {
|
|||
|
||||
// TestLegacyRunNoNewPrivSetuid checks that --security-opt=no-new-privileges prevents
|
||||
// effective uid transitions on executing setuid binaries.
|
||||
func (s *DockerSuite) TestLegacyRunNoNewPrivSetuid(c *check.C) {
|
||||
func (s *DockerSuite) TestLegacyRunNoNewPrivSetuid(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
|
||||
ensureNNPTest(c)
|
||||
|
||||
|
@ -1166,7 +1160,7 @@ func (s *DockerSuite) TestLegacyRunNoNewPrivSetuid(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1184,7 +1178,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1197,7 +1191,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1213,7 +1207,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) {
|
|||
|
||||
// TODO CAP_KILL
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1231,7 +1225,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1251,7 +1245,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) {
|
|||
|
||||
// TODO CAP_SETPCAP
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1269,7 +1263,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *check.C)
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1287,7 +1281,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1305,7 +1299,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) {
|
||||
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace, testEnv.IsLocalDaemon)
|
||||
ensureSyscallTest(c)
|
||||
|
||||
|
@ -1327,7 +1321,7 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) {
|
|||
// TODO CAP_AUDIT_WRITE
|
||||
// TODO CAP_SETFCAP
|
||||
|
||||
func (s *DockerSuite) TestRunApparmorProcDirectory(c *check.C) {
|
||||
func (s *DockerSuite) TestRunApparmorProcDirectory(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, Apparmor)
|
||||
|
||||
// running w seccomp unconfined tests the apparmor profile
|
||||
|
@ -1346,7 +1340,7 @@ func (s *DockerSuite) TestRunApparmorProcDirectory(c *check.C) {
|
|||
|
||||
// make sure the default profile can be successfully parsed (using unshare as it is
|
||||
// something which we know is blocked in the default profile)
|
||||
func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *check.C) {
|
||||
func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled)
|
||||
|
||||
out, _, err := dockerCmdWithError("run", "--security-opt", "seccomp=../profiles/seccomp/default.json", "debian:jessie", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami")
|
||||
|
@ -1355,7 +1349,7 @@ func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *check.C) {
|
|||
}
|
||||
|
||||
// TestRunDeviceSymlink checks run with device that follows symlink (#13840 and #22271)
|
||||
func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) {
|
||||
func (s *DockerSuite) TestRunDeviceSymlink(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm, testEnv.IsLocalDaemon)
|
||||
if _, err := os.Stat("/dev/zero"); err != nil {
|
||||
c.Skip("Host does not have /dev/zero")
|
||||
|
@ -1391,20 +1385,18 @@ func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) {
|
|||
|
||||
// md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23
|
||||
out, _ := dockerCmd(c, "run", "--device", symZero+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
|
||||
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.Trim(out, "\r\n"), "bb7df04e1b0a2570657527a7e108ae23"), "expected output bb7df04e1b0a2570657527a7e108ae23")
|
||||
// symlink "tmpDir/file" to a file "tmpDir/temp" will result in an error as it is not a device.
|
||||
out, _, err = dockerCmdWithError("run", "--device", symFile+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "not a device node", check.Commentf("expected output 'not a device node'"))
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.Trim(out, "\r\n"), "not a device node"), "expected output 'not a device node'")
|
||||
// md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23 (this time check with relative path backed, see #22271)
|
||||
out, _ = dockerCmd(c, "run", "--device", "/dev/symzero:/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
|
||||
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
|
||||
assert.Assert(c, strings.Contains(strings.Trim(out, "\r\n"), "bb7df04e1b0a2570657527a7e108ae23"), "expected output bb7df04e1b0a2570657527a7e108ae23")
|
||||
}
|
||||
|
||||
// TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit
|
||||
func (s *DockerSuite) TestRunPIDsLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestRunPIDsLimit(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, pidsLimit)
|
||||
|
||||
file := "/sys/fs/cgroup/pids/pids.max"
|
||||
|
@ -1415,7 +1407,7 @@ func (s *DockerSuite) TestRunPIDsLimit(c *check.C) {
|
|||
assert.Equal(c, out, "4", "setting the pids limit failed")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *check.C) {
|
||||
func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
||||
file := "/sys/fs/cgroup/devices/devices.list"
|
||||
|
@ -1424,7 +1416,7 @@ func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "a *:* rwm")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunUserDeviceAllowed(c *check.C) {
|
||||
func (s *DockerSuite) TestRunUserDeviceAllowed(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
fi, err := os.Stat("/dev/snd/timer")
|
||||
|
@ -1438,10 +1430,10 @@ func (s *DockerSuite) TestRunUserDeviceAllowed(c *check.C) {
|
|||
|
||||
file := "/sys/fs/cgroup/devices/devices.list"
|
||||
out, _ := dockerCmd(c, "run", "--device", "/dev/snd/timer:w", "busybox", "cat", file)
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("c %d:%d w", stat.Rdev/256, stat.Rdev%256))
|
||||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("c %d:%d w", stat.Rdev/256, stat.Rdev%256)))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *testing.T) {
|
||||
testRequires(c, seccompEnabled)
|
||||
|
||||
s.d.StartWithBusybox(c)
|
||||
|
@ -1463,10 +1455,10 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Operation not permitted")
|
||||
assert.Assert(c, strings.Contains(out, "Operation not permitted"))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *testing.T) {
|
||||
testRequires(c, seccompEnabled)
|
||||
|
||||
s.d.StartWithBusybox(c)
|
||||
|
@ -1489,10 +1481,10 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
|
||||
assert.Assert(c, strings.Contains(out, "'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'"))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *testing.T) {
|
||||
testRequires(c, seccompEnabled)
|
||||
|
||||
s.d.StartWithBusybox(c)
|
||||
|
@ -1526,10 +1518,10 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'")
|
||||
assert.Assert(c, strings.Contains(out, "'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'"))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *testing.T) {
|
||||
testRequires(c, seccompEnabled)
|
||||
|
||||
s.d.StartWithBusybox(c)
|
||||
|
@ -1562,10 +1554,10 @@ func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("run", "busybox", "chmod", "777", ".")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Operation not permitted")
|
||||
assert.Assert(c, strings.Contains(out, "Operation not permitted"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
|
||||
func (s *DockerSuite) TestRunWithNanoCPUs(c *testing.T) {
|
||||
testRequires(c, cpuCfsQuota, cpuCfsPeriod)
|
||||
|
||||
file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
|
||||
|
@ -1577,7 +1569,7 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
inspect, err := clt.ContainerInspect(context.Background(), "test")
|
||||
assert.NilError(c, err)
|
||||
c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
|
||||
assert.Equal(c, inspect.HostConfig.NanoCPUs, int64(500000000))
|
||||
|
||||
out = inspectField(c, "test", "HostConfig.CpuQuota")
|
||||
assert.Equal(c, out, "0", "CPU CFS quota should be 0")
|
||||
|
@ -1586,5 +1578,5 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
|
|||
|
||||
out, _, err = dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set")
|
||||
assert.Assert(c, strings.Contains(out, "Conflicting options: Nano CPUs and CPU Period cannot both be set"))
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import (
|
|||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
|
@ -25,7 +24,7 @@ import (
|
|||
)
|
||||
|
||||
// save a repo using gz compression and try to load it using stdout
|
||||
func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-save-xz-and-load-repo-stdout"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
@ -54,7 +53,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
|||
}
|
||||
|
||||
// save a repo using xz+gz compression and try to load it using stdout
|
||||
func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-save-xz-gz-and-load-repo-stdout"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
@ -83,7 +82,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
|||
assert.ErrorContains(c, err, "", "the repo should not exist: %v", after)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveSingleTag(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repoName := "foobar-save-single-tag-test"
|
||||
dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
|
||||
|
@ -98,7 +97,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
|||
assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveCheckTimes(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repoName := "busybox:latest"
|
||||
out, _ := dockerCmd(c, "inspect", repoName)
|
||||
|
@ -117,7 +116,7 @@ func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
|||
assert.NilError(c, err, "failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveImageId(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repoName := "foobar-save-image-id-test"
|
||||
dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
|
||||
|
@ -129,21 +128,21 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
|||
cleanedShortImageID := strings.TrimSpace(out)
|
||||
|
||||
// Make sure IDs are not empty
|
||||
c.Assert(cleanedLongImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
||||
c.Assert(cleanedShortImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
||||
assert.Assert(c, cleanedLongImageID != "", "Id should not be empty.")
|
||||
assert.Assert(c, cleanedShortImageID != "", "Id should not be empty.")
|
||||
|
||||
saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
|
||||
tarCmd := exec.Command("tar", "t")
|
||||
|
||||
var err error
|
||||
tarCmd.Stdin, err = saveCmd.StdoutPipe()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for tar: %v", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("cannot set stdout pipe for tar: %v", err))
|
||||
grepCmd := exec.Command("grep", cleanedLongImageID)
|
||||
grepCmd.Stdin, err = tarCmd.StdoutPipe()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for grep: %v", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("cannot set stdout pipe for grep: %v", err))
|
||||
|
||||
c.Assert(tarCmd.Start(), checker.IsNil, check.Commentf("tar failed with error: %v", err))
|
||||
c.Assert(saveCmd.Start(), checker.IsNil, check.Commentf("docker save failed with error: %v", err))
|
||||
assert.Assert(c, tarCmd.Start() == nil, fmt.Sprintf("tar failed with error: %v", err))
|
||||
assert.Assert(c, saveCmd.Start() == nil, fmt.Sprintf("docker save failed with error: %v", err))
|
||||
defer func() {
|
||||
saveCmd.Wait()
|
||||
tarCmd.Wait()
|
||||
|
@ -152,11 +151,11 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
|||
|
||||
out, _, err = runCommandWithOutput(grepCmd)
|
||||
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID: %s, %v", out, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to save repo with image ID: %s, %v", out, err))
|
||||
}
|
||||
|
||||
// save a repo and try to load it using flags
|
||||
func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-save-and-load-repo-flags"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
@ -177,7 +176,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
|||
assert.Equal(c, before, after, "inspect is not the same after a save / load")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveWithNoExistImage(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveWithNoExistImage(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
imgName := "foobar-non-existing-image"
|
||||
|
@ -187,7 +186,7 @@ func (s *DockerSuite) TestSaveWithNoExistImage(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, fmt.Sprintf("No such image: %s", imgName)))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveMultipleNames(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
repoName := "foobar-save-multi-name-test"
|
||||
|
||||
|
@ -205,7 +204,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
|||
assert.NilError(c, err, "failed to save multiple repos: %s, %v", out, err)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
makeImage := func(from string, tag string) string {
|
||||
var (
|
||||
|
@ -257,14 +256,14 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
|||
}
|
||||
|
||||
// Issue #6722 #5892 ensure directories are included in changes
|
||||
func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveDirectoryPermissions(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
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"}
|
||||
|
||||
name := "save-directory-permissions"
|
||||
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary directory: %s", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to create temporary directory: %s", err))
|
||||
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
||||
os.Mkdir(extractionDirectory, 0777)
|
||||
|
||||
|
@ -331,7 +330,7 @@ func listTar(f io.Reader) ([]string, error) {
|
|||
// 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.
|
||||
// See issue: 18170
|
||||
func (s *DockerSuite) TestLoadZeroSizeLayer(c *check.C) {
|
||||
func (s *DockerSuite) TestLoadZeroSizeLayer(c *testing.T) {
|
||||
// this will definitely not work if using remote daemon
|
||||
// very weird test
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
|
@ -339,7 +338,7 @@ func (s *DockerSuite) TestLoadZeroSizeLayer(c *check.C) {
|
|||
dockerCmd(c, "load", "-i", "testdata/emptyLayer.tar")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveLoadParents(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveLoadParents(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
makeImage := func(from string, addfile string) string {
|
||||
|
@ -378,7 +377,7 @@ func (s *DockerSuite) TestSaveLoadParents(c *check.C) {
|
|||
assert.Equal(c, inspectOut, "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveLoadNoTag(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
name := "saveloadnotag"
|
||||
|
@ -393,16 +392,15 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|||
assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
|
||||
|
||||
// Should not show 'name' but should show the image ID during the load
|
||||
c.Assert(out, checker.Not(checker.Contains), "Loaded image: ")
|
||||
c.Assert(out, checker.Contains, "Loaded image ID:")
|
||||
c.Assert(out, checker.Contains, id)
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, "Loaded image: "))
|
||||
assert.Assert(c, strings.Contains(out, "Loaded image ID:"))
|
||||
assert.Assert(c, strings.Contains(out, id))
|
||||
// Test to make sure that save by name shows that name during load
|
||||
out, err = RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", name),
|
||||
exec.Command(dockerBinary, "load"))
|
||||
assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
|
||||
|
||||
c.Assert(out, checker.Contains, "Loaded image: "+name+":latest")
|
||||
c.Assert(out, checker.Not(checker.Contains), "Loaded image ID:")
|
||||
assert.Assert(c, strings.Contains(out, "Loaded image: "+name+":latest"))
|
||||
assert.Assert(c, !strings.Contains(out, "Loaded image ID:"))
|
||||
}
|
||||
|
|
|
@ -9,17 +9,17 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// save a repo and try to load it using stdout
|
||||
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
|
||||
name := "test-save-and-load-repo-stdout"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
||||
|
@ -70,7 +70,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(string(buf[:n]), "cowardly refusing"), "help output is not being yielded")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) {
|
||||
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *testing.T) {
|
||||
name := "test-load"
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM busybox
|
||||
RUN touch aa
|
||||
|
@ -88,7 +88,7 @@ func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) {
|
|||
}
|
||||
|
||||
// fail because load didn't receive data from stdin
|
||||
func (s *DockerSuite) TestLoadNoStdinFail(c *check.C) {
|
||||
func (s *DockerSuite) TestLoadNoStdinFail(c *testing.T) {
|
||||
pty, tty, err := pty.Open()
|
||||
assert.NilError(c, err)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
|
|
@ -3,18 +3,18 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// search for repos named "registry" on the central registry
|
||||
func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
|
||||
func (s *DockerSuite) TestSearchOnCentralRegistry(c *testing.T) {
|
||||
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.'")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
|
||||
func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox")
|
||||
assert.ErrorContains(c, err, "", out)
|
||||
assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
|
||||
|
@ -32,7 +32,7 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
|
||||
func (s *DockerSuite) TestSearchCmdOptions(c *testing.T) {
|
||||
outSearchCmd, _ := dockerCmd(c, "search", "busybox")
|
||||
assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd)
|
||||
|
||||
|
@ -60,12 +60,12 @@ func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
|
|||
}
|
||||
|
||||
// search for repos which start with "ubuntu-" on the central registry
|
||||
func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
|
||||
func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *testing.T) {
|
||||
dockerCmd(c, "search", "ubuntu-")
|
||||
}
|
||||
|
||||
// test case for #23055
|
||||
func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestSearchWithLimit(c *testing.T) {
|
||||
for _, limit := range []int{10, 50, 100} {
|
||||
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
|
||||
assert.NilError(c, err)
|
||||
|
|
|
@ -7,64 +7,65 @@ import (
|
|||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--mount", "type=volume,source=foo,target=/foo,volume-nocopy", "busybox", "top")
|
||||
assert.NilError(c, err, out)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, id)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container mount config
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
var mountConfig []mount.Mount
|
||||
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
||||
c.Assert(mountConfig, checker.HasLen, 1)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig) == nil)
|
||||
assert.Equal(c, len(mountConfig), 1)
|
||||
|
||||
c.Assert(mountConfig[0].Source, checker.Equals, "foo")
|
||||
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
|
||||
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeVolume)
|
||||
c.Assert(mountConfig[0].VolumeOptions, checker.NotNil)
|
||||
c.Assert(mountConfig[0].VolumeOptions.NoCopy, checker.True)
|
||||
assert.Equal(c, mountConfig[0].Source, "foo")
|
||||
assert.Equal(c, mountConfig[0].Target, "/foo")
|
||||
assert.Equal(c, mountConfig[0].Type, mount.TypeVolume)
|
||||
assert.Assert(c, mountConfig[0].VolumeOptions != nil)
|
||||
assert.Assert(c, mountConfig[0].VolumeOptions.NoCopy)
|
||||
|
||||
// check container mounts actual
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
var mounts []types.MountPoint
|
||||
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
||||
c.Assert(mounts, checker.HasLen, 1)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil)
|
||||
assert.Equal(c, len(mounts), 1)
|
||||
|
||||
c.Assert(mounts[0].Type, checker.Equals, mount.TypeVolume)
|
||||
c.Assert(mounts[0].Name, checker.Equals, "foo")
|
||||
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
|
||||
c.Assert(mounts[0].RW, checker.Equals, true)
|
||||
assert.Equal(c, mounts[0].Type, mount.TypeVolume)
|
||||
assert.Equal(c, mounts[0].Name, "foo")
|
||||
assert.Equal(c, mounts[0].Destination, "/foo")
|
||||
assert.Equal(c, mounts[0].RW, true)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
serviceName := "test-service-secret"
|
||||
|
@ -75,7 +76,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
|
|||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
|
||||
|
||||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", testName, "busybox", "top")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -84,21 +85,21 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.SecretReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), 1)
|
||||
|
||||
c.Assert(refs[0].SecretName, checker.Equals, testName)
|
||||
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
||||
c.Assert(refs[0].File.Name, checker.Equals, testName)
|
||||
c.Assert(refs[0].File.UID, checker.Equals, "0")
|
||||
c.Assert(refs[0].File.GID, checker.Equals, "0")
|
||||
assert.Equal(c, refs[0].SecretName, testName)
|
||||
assert.Assert(c, refs[0].File != nil)
|
||||
assert.Equal(c, refs[0].File.Name, testName)
|
||||
assert.Equal(c, refs[0].File.UID, "0")
|
||||
assert.Equal(c, refs[0].File.GID, "0")
|
||||
|
||||
out, err = d.Cmd("service", "rm", serviceName)
|
||||
assert.NilError(c, err, out)
|
||||
d.DeleteSecret(c, testName)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testPaths := map[string]string{
|
||||
|
@ -117,7 +118,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
|
|||
},
|
||||
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
|
||||
|
||||
secretFlags = append(secretFlags, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
||||
}
|
||||
|
@ -133,22 +134,22 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.SecretReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), len(testPaths))
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, serviceName)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for testName, testTarget := range testPaths {
|
||||
path := testTarget
|
||||
|
@ -164,7 +165,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
id := d.CreateSecret(c, swarm.SecretSpec{
|
||||
|
@ -173,7 +174,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
|
|||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
|
||||
|
||||
serviceName := "svc"
|
||||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", "source=mysecret,target=target1", "--secret", "source=mysecret,target=target2", "busybox", "top")
|
||||
|
@ -183,22 +184,22 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.SecretReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), 2)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, serviceName)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for _, target := range []string{"target1", "target2"} {
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -212,7 +213,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
serviceName := "test-service-config"
|
||||
|
@ -223,7 +224,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
|
|||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
|
||||
|
||||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", testName, "busybox", "top")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -232,21 +233,21 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.ConfigReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), 1)
|
||||
|
||||
c.Assert(refs[0].ConfigName, checker.Equals, testName)
|
||||
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
||||
c.Assert(refs[0].File.Name, checker.Equals, testName)
|
||||
c.Assert(refs[0].File.UID, checker.Equals, "0")
|
||||
c.Assert(refs[0].File.GID, checker.Equals, "0")
|
||||
assert.Equal(c, refs[0].ConfigName, testName)
|
||||
assert.Assert(c, refs[0].File != nil)
|
||||
assert.Equal(c, refs[0].File.Name, testName)
|
||||
assert.Equal(c, refs[0].File.UID, "0")
|
||||
assert.Equal(c, refs[0].File.GID, "0")
|
||||
|
||||
out, err = d.Cmd("service", "rm", serviceName)
|
||||
assert.NilError(c, err, out)
|
||||
d.DeleteConfig(c, testName)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testPaths := map[string]string{
|
||||
|
@ -264,7 +265,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
|
|||
},
|
||||
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
|
||||
|
||||
configFlags = append(configFlags, "--config", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
||||
}
|
||||
|
@ -280,22 +281,22 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.ConfigReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), len(testPaths))
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, serviceName)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for testName, testTarget := range testPaths {
|
||||
path := testTarget
|
||||
|
@ -311,7 +312,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
id := d.CreateConfig(c, swarm.ConfigSpec{
|
||||
|
@ -320,7 +321,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
|
|||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
||||
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
|
||||
|
||||
serviceName := "svc"
|
||||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", "source=myconfig,target=target1", "--config", "source=myconfig,target=target2", "busybox", "top")
|
||||
|
@ -330,22 +331,22 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
|
|||
assert.NilError(c, err)
|
||||
|
||||
var refs []swarm.ConfigReference
|
||||
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil)
|
||||
assert.Equal(c, len(refs), 2)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, serviceName)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for _, target := range []string{"target1", "target2"} {
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -359,52 +360,52 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
|
|||
assert.NilError(c, err, out)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--mount", "type=tmpfs,target=/foo,tmpfs-size=1MB", "busybox", "sh", "-c", "mount | grep foo; tail -f /dev/null")
|
||||
assert.NilError(c, err, out)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, id)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container mount config
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
var mountConfig []mount.Mount
|
||||
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
||||
c.Assert(mountConfig, checker.HasLen, 1)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig) == nil)
|
||||
assert.Equal(c, len(mountConfig), 1)
|
||||
|
||||
c.Assert(mountConfig[0].Source, checker.Equals, "")
|
||||
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
|
||||
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
|
||||
c.Assert(mountConfig[0].TmpfsOptions, checker.NotNil)
|
||||
c.Assert(mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
|
||||
assert.Equal(c, mountConfig[0].Source, "")
|
||||
assert.Equal(c, mountConfig[0].Target, "/foo")
|
||||
assert.Equal(c, mountConfig[0].Type, mount.TypeTmpfs)
|
||||
assert.Assert(c, mountConfig[0].TmpfsOptions != nil)
|
||||
assert.Equal(c, mountConfig[0].TmpfsOptions.SizeBytes, int64(1048576))
|
||||
|
||||
// check container mounts actual
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
var mounts []types.MountPoint
|
||||
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
||||
c.Assert(mounts, checker.HasLen, 1)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil)
|
||||
assert.Equal(c, len(mounts), 1)
|
||||
|
||||
c.Assert(mounts[0].Type, checker.Equals, mount.TypeTmpfs)
|
||||
c.Assert(mounts[0].Name, checker.Equals, "")
|
||||
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
|
||||
c.Assert(mounts[0].RW, checker.Equals, true)
|
||||
assert.Equal(c, mounts[0].Type, mount.TypeTmpfs)
|
||||
assert.Equal(c, mounts[0].Name, "")
|
||||
assert.Equal(c, mounts[0].Destination, "/foo")
|
||||
assert.Equal(c, mounts[0].RW, true)
|
||||
|
||||
out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID)
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -412,7 +413,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "size=1024k"))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
out, err := d.Cmd("network", "create", "--scope=swarm", "test_swarm_br")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -422,18 +423,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, id)
|
||||
return len(tasks) > 0, nil
|
||||
}, checker.Equals, true)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||
}, checker.Equals, true)
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container alias config
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .NetworkSettings.Networks.test_swarm_br.Aliases}}", task.Status.ContainerStatus.ContainerID)
|
||||
|
@ -441,8 +442,8 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
|||
|
||||
// Make sure the only alias seen is the container-id
|
||||
var aliases []string
|
||||
c.Assert(json.Unmarshal([]byte(out), &aliases), checker.IsNil)
|
||||
c.Assert(aliases, checker.HasLen, 1)
|
||||
assert.Assert(c, json.Unmarshal([]byte(out), &aliases) == nil)
|
||||
assert.Equal(c, len(aliases), 1)
|
||||
|
||||
c.Assert(task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
|
||||
assert.Assert(c, strings.Contains(task.Status.ContainerStatus.ContainerID, aliases[0]))
|
||||
}
|
||||
|
|
|
@ -5,20 +5,21 @@ package main
|
|||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/daemon/cluster/executor/container"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
// start a service, and then make its task unhealthy during running
|
||||
// finally, unhealthy task should be detected and killed
|
||||
func (s *DockerSwarmSuite) TestServiceHealthRun(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
@ -39,39 +40,40 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *check.C) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, id)
|
||||
return tasks, nil
|
||||
}, checker.HasLen, 1)
|
||||
return tasks, ""
|
||||
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
|
||||
// wait for task to start
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
task = d.GetTask(c, task.ID)
|
||||
return task.Status.State, nil
|
||||
}, checker.Equals, swarm.TaskStateRunning)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containerID := task.Status.ContainerStatus.ContainerID
|
||||
|
||||
// wait for container to be healthy
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
|
||||
return strings.TrimSpace(out), nil
|
||||
}, checker.Equals, "healthy")
|
||||
return strings.TrimSpace(out), ""
|
||||
}, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it fail
|
||||
d.Cmd("exec", containerID, "rm", "/status")
|
||||
// wait for container to be unhealthy
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
|
||||
return strings.TrimSpace(out), nil
|
||||
}, checker.Equals, "unhealthy")
|
||||
return strings.TrimSpace(out), ""
|
||||
}, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Task should be terminated
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
task = d.GetTask(c, task.ID)
|
||||
return task.Status.State, nil
|
||||
}, checker.Equals, swarm.TaskStateFailed)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.Error()) {
|
||||
c.Fatal("unhealthy task exits because of other error")
|
||||
|
@ -80,7 +82,7 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *check.C) {
|
|||
|
||||
// start a service whose task is unhealthy at beginning
|
||||
// its tasks should be blocked in starting stage, until health check is passed
|
||||
func (s *DockerSwarmSuite) TestServiceHealthStart(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
@ -100,38 +102,39 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *check.C) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
var tasks []swarm.Task
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
tasks = d.GetServiceTasks(c, id)
|
||||
return tasks, nil
|
||||
}, checker.HasLen, 1)
|
||||
return tasks, ""
|
||||
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
|
||||
// wait for task to start
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
task = d.GetTask(c, task.ID)
|
||||
return task.Status.State, nil
|
||||
}, checker.Equals, swarm.TaskStateStarting)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containerID := task.Status.ContainerStatus.ContainerID
|
||||
|
||||
// wait for health check to work
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID)
|
||||
failingStreak, _ := strconv.Atoi(strings.TrimSpace(out))
|
||||
return failingStreak, nil
|
||||
}, checker.GreaterThan, 0)
|
||||
return failingStreak, ""
|
||||
}, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// task should be blocked at starting status
|
||||
task = d.GetTask(c, task.ID)
|
||||
c.Assert(task.Status.State, check.Equals, swarm.TaskStateStarting)
|
||||
assert.Equal(c, task.Status.State, swarm.TaskStateStarting)
|
||||
|
||||
// make it healthy
|
||||
d.Cmd("exec", containerID, "touch", "/status")
|
||||
|
||||
// Task should be at running status
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
||||
task = d.GetTask(c, task.ID)
|
||||
return task.Status.State, nil
|
||||
}, checker.Equals, swarm.TaskStateRunning)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
|
@ -8,13 +8,14 @@ import (
|
|||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
type logMessage struct {
|
||||
|
@ -22,7 +23,7 @@ type logMessage struct {
|
|||
data []byte
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogs(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogs(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
// we have multiple services here for detecting the goroutine issue #28915
|
||||
|
@ -39,9 +40,8 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *check.C) {
|
|||
}
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout,
|
||||
d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{"busybox:latest": len(services)})
|
||||
poll.WaitOn(c, pollCheck(c,
|
||||
d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{"busybox:latest": len(services)})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for name, message := range services {
|
||||
out, err := d.Cmd("service", "logs", name)
|
||||
|
@ -54,22 +54,22 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *check.C) {
|
|||
// countLogLines returns a closure that can be used with waitAndAssert to
|
||||
// verify that a minimum number of expected container log messages have been
|
||||
// output.
|
||||
func countLogLines(d *daemon.Daemon, name string) func(*check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
func countLogLines(d *daemon.Daemon, name string) func(*testing.T) (interface{}, string) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
result := icmd.RunCmd(d.Command("service", "logs", "-t", "--raw", name))
|
||||
result.Assert(c, icmd.Expected{})
|
||||
// if this returns an emptystring, trying to split it later will return
|
||||
// an array containing emptystring. a valid log line will NEVER be
|
||||
// emptystring because we ask for the timestamp.
|
||||
if result.Stdout() == "" {
|
||||
return 0, check.Commentf("Empty stdout")
|
||||
return 0, "Empty stdout"
|
||||
}
|
||||
lines := strings.Split(strings.TrimSpace(result.Stdout()), "\n")
|
||||
return len(lines), check.Commentf("output, %q", string(result.Stdout()))
|
||||
return len(lines), fmt.Sprintf("output, %q", string(result.Stdout()))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsCompleteness"
|
||||
|
@ -80,9 +80,9 @@ func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *check.C) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// and make sure we have all the log lines
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6)
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
out, err = d.Cmd("service", "logs", name)
|
||||
assert.NilError(c, err)
|
||||
|
@ -96,7 +96,7 @@ func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTail(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTail(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsTail"
|
||||
|
@ -107,8 +107,8 @@ func (s *DockerSwarmSuite) TestServiceLogsTail(c *check.C) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
out, err = d.Cmd("service", "logs", "--tail=2", name)
|
||||
assert.NilError(c, err)
|
||||
|
@ -120,7 +120,7 @@ func (s *DockerSwarmSuite) TestServiceLogsTail(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsSince(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsSince(c *testing.T) {
|
||||
// See DockerSuite.TestLogsSince, which is where this comes from
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
|
@ -129,9 +129,9 @@ func (s *DockerSwarmSuite) TestServiceLogsSince(c *check.C) {
|
|||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", "for i in $(seq 1 3); do sleep .1; echo log$i; done; sleep 10000000")
|
||||
assert.NilError(c, err)
|
||||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// wait a sec for the logs to come in
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 3)
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
out, err = d.Cmd("service", "logs", "-t", name)
|
||||
assert.NilError(c, err)
|
||||
|
@ -155,7 +155,7 @@ func (s *DockerSwarmSuite) TestServiceLogsSince(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsFollow(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsFollow"
|
||||
|
@ -165,7 +165,7 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *check.C) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
args := []string{"service", "logs", "-f", name}
|
||||
cmd := exec.Command(dockerBinary, d.PrependHostArg(args)...)
|
||||
|
@ -201,7 +201,7 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *check.C) {
|
|||
assert.NilError(c, cmd.Process.Kill())
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTaskLogs(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTaskLogs(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServicelogsTaskLogs"
|
||||
|
@ -228,8 +228,8 @@ func (s *DockerSwarmSuite) TestServiceLogsTaskLogs(c *check.C) {
|
|||
result.Assert(c, icmd.Expected{Out: id})
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, replicas)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6*replicas)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(replicas)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6*replicas)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// get the task ids
|
||||
result = icmd.RunCmd(d.Command("service", "ps", "-q", name))
|
||||
|
@ -254,7 +254,7 @@ func (s *DockerSwarmSuite) TestServiceLogsTaskLogs(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTTY(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsTTY(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsTTY"
|
||||
|
@ -281,9 +281,9 @@ func (s *DockerSwarmSuite) TestServiceLogsTTY(c *check.C) {
|
|||
result.Assert(c, icmd.Expected{Out: id})
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// and make sure we have all the log lines
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 2)
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
cmd := d.Command("service", "logs", "--raw", name)
|
||||
result = icmd.RunCmd(cmd)
|
||||
|
@ -292,7 +292,7 @@ func (s *DockerSwarmSuite) TestServiceLogsTTY(c *check.C) {
|
|||
result.Assert(c, icmd.Expected{Out: "out\r\nerr\r\n"})
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsNoHangDeletedContainer"
|
||||
|
@ -315,9 +315,9 @@ func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *check.C) {
|
|||
assert.Assert(c, id != "")
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// and make sure we have all the log lines
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 2)
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// now find and nuke the container
|
||||
result = icmd.RunCmd(d.Command("ps", "-q"))
|
||||
|
@ -341,7 +341,7 @@ func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *check.C) {
|
|||
result.Assert(c, icmd.Expected{})
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceLogsDetails(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceLogsDetails(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "TestServiceLogsDetails"
|
||||
|
@ -368,9 +368,9 @@ func (s *DockerSwarmSuite) TestServiceLogsDetails(c *check.C) {
|
|||
assert.Assert(c, id != "")
|
||||
|
||||
// make sure task has been deployed
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
// and make sure we have all the log lines
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// First, test without pretty printing
|
||||
// call service logs with details. set raw to skip pretty printing
|
||||
|
|
|
@ -5,12 +5,12 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceScale(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestServiceScale(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
service1Name := "TestService1"
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"net/url"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestClientSetsTLSServerName(c *check.C) {
|
||||
func (s *DockerSuite) TestClientSetsTLSServerName(c *testing.T) {
|
||||
c.Skip("Flakey test")
|
||||
// there may be more than one hit to the server for each registry request
|
||||
var serverNameReceived []string
|
||||
|
|
|
@ -3,17 +3,16 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
// Regression test for https://github.com/docker/docker/issues/7843
|
||||
func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
|
||||
func (s *DockerSuite) TestStartAttachReturnsOnError(c *testing.T) {
|
||||
// Windows does not support link
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "--name", "test", "busybox")
|
||||
|
@ -21,7 +20,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
|
|||
// Expect this to fail because the above container is stopped, this is what we want
|
||||
out, _, err := dockerCmdWithError("run", "--name", "test2", "--link", "test:test", "busybox")
|
||||
// err shouldn't be nil because container test2 try to link to stopped container
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
|
||||
ch := make(chan error)
|
||||
go func() {
|
||||
|
@ -42,7 +41,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
|
|||
}
|
||||
|
||||
// gh#8555: Exit code should be passed through when using start -a
|
||||
func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
|
||||
func (s *DockerSuite) TestStartAttachCorrectExitCode(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1").Stdout()
|
||||
out = strings.TrimSpace(out)
|
||||
|
@ -55,7 +54,7 @@ func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
|
||||
func (s *DockerSuite) TestStartAttachSilent(c *testing.T) {
|
||||
name := "teststartattachcorrectexitcode"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "echo", "test")
|
||||
|
||||
|
@ -64,35 +63,34 @@ func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
|
|||
|
||||
startOut, _ := dockerCmd(c, "start", "-a", name)
|
||||
// start -a produced unexpected output
|
||||
c.Assert(startOut, checker.Equals, "test\n")
|
||||
assert.Equal(c, startOut, "test\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartRecordError(c *check.C) {
|
||||
func (s *DockerSuite) TestStartRecordError(c *testing.T) {
|
||||
// TODO Windows CI: Requires further porting work. Should be possible.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// when container runs successfully, we should not have state.Error
|
||||
dockerCmd(c, "run", "-d", "-p", "9999:9999", "--name", "test", "busybox", "top")
|
||||
stateErr := inspectField(c, "test", "State.Error")
|
||||
// Expected to not have state error
|
||||
c.Assert(stateErr, checker.Equals, "")
|
||||
assert.Equal(c, stateErr, "")
|
||||
|
||||
// Expect this to fail and records error because of ports conflict
|
||||
out, _, err := dockerCmdWithError("run", "-d", "--name", "test2", "-p", "9999:9999", "busybox", "top")
|
||||
// err shouldn't be nil because docker run will fail
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
|
||||
stateErr = inspectField(c, "test2", "State.Error")
|
||||
c.Assert(stateErr, checker.Contains, "port is already allocated")
|
||||
|
||||
assert.Assert(c, strings.Contains(stateErr, "port is already allocated"))
|
||||
// Expect the conflict to be resolved when we stop the initial container
|
||||
dockerCmd(c, "stop", "test")
|
||||
dockerCmd(c, "start", "test2")
|
||||
stateErr = inspectField(c, "test2", "State.Error")
|
||||
// Expected to not have state error but got one
|
||||
c.Assert(stateErr, checker.Equals, "")
|
||||
assert.Equal(c, stateErr, "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestStartPausedContainer(c *testing.T) {
|
||||
// Windows does not support pausing containers
|
||||
testRequires(c, IsPausable)
|
||||
|
||||
|
@ -102,12 +100,12 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
|
|||
|
||||
out, _, err := dockerCmdWithError("start", "testing")
|
||||
// an error should have been shown that you cannot start paused container
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
// an error should have been shown that you cannot start paused container
|
||||
c.Assert(strings.ToLower(out), checker.Contains, "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 *check.C) {
|
||||
func (s *DockerSuite) TestStartMultipleContainers(c *testing.T) {
|
||||
// Windows does not support --link
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// run a container named 'parent' and create two container link to `parent`
|
||||
|
@ -130,7 +128,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
|
|||
expErr := "failed to start containers: [child_first]"
|
||||
out, _, err := dockerCmdWithError("start", "child_first", "parent", "child_second")
|
||||
// err shouldn't be nil because start will fail
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
// output does not correspond to what was expected
|
||||
if !(strings.Contains(out, expOut) || strings.Contains(err.Error(), expErr)) {
|
||||
c.Fatalf("Expected out: %v with err: %v but got out: %v with err: %v", expOut, expErr, out, err)
|
||||
|
@ -143,7 +141,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
|
||||
func (s *DockerSuite) TestStartAttachMultipleContainers(c *testing.T) {
|
||||
// run multiple containers to test
|
||||
for _, container := range []string{"test1", "test2", "test3"} {
|
||||
runSleepingContainer(c, "--name", container)
|
||||
|
@ -158,9 +156,9 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
|
|||
for _, option := range []string{"-a", "-i", "-ai"} {
|
||||
out, _, err := dockerCmdWithError("start", option, "test1", "test2", "test3")
|
||||
// err shouldn't be nil because start will fail
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
|
||||
// output does not correspond to what was expected
|
||||
c.Assert(out, checker.Contains, "you cannot start and attach multiple containers at once")
|
||||
assert.Assert(c, strings.Contains(out, "you cannot start and attach multiple containers at once"))
|
||||
}
|
||||
|
||||
// confirm the state of all the containers be stopped
|
||||
|
@ -172,7 +170,7 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
|
|||
}
|
||||
|
||||
// Test case for #23716
|
||||
func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
|
||||
func (s *DockerSuite) TestStartAttachWithRename(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
cli.DockerCmd(c, "create", "-t", "--name", "before", "busybox")
|
||||
go func() {
|
||||
|
@ -184,18 +182,18 @@ func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
|
|||
result := cli.Docker(cli.Args("start", "-a", "before")).Assert(c, icmd.Expected{
|
||||
ExitCode: 137,
|
||||
})
|
||||
c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container")
|
||||
assert.Assert(c, !strings.Contains(result.Stderr(), "No such container"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) {
|
||||
func (s *DockerSuite) TestStartReturnCorrectExitCode(c *testing.T) {
|
||||
dockerCmd(c, "create", "--restart=on-failure:2", "--name", "withRestart", "busybox", "sh", "-c", "exit 11")
|
||||
dockerCmd(c, "create", "--rm", "--name", "withRm", "busybox", "sh", "-c", "exit 12")
|
||||
|
||||
out, exitCode, err := dockerCmdWithError("start", "-a", "withRestart")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(exitCode, checker.Equals, 11, check.Commentf("out: %s", out))
|
||||
assert.Equal(c, exitCode, 11, fmt.Sprintf("out: %s", out))
|
||||
|
||||
out, exitCode, err = dockerCmdWithError("start", "-a", "withRm")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(exitCode, checker.Equals, 12, check.Commentf("out: %s", out))
|
||||
assert.Equal(c, exitCode, 12, fmt.Sprintf("out: %s", out))
|
||||
}
|
||||
|
|
|
@ -5,15 +5,15 @@ import (
|
|||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestStatsNoStream(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsNoStream(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
|
@ -42,7 +42,7 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsContainerNotFound(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -55,7 +55,7 @@ func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
|
|||
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 *check.C) {
|
||||
func (s *DockerSuite) TestStatsAllRunningNoStream(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -91,7 +91,7 @@ func (s *DockerSuite) TestStatsAllRunningNoStream(c *check.C) {
|
|||
assert.Assert(c, realData != nil, "stat result are empty: %s", out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStatsAllNoStream(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsAllNoStream(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -121,7 +121,7 @@ func (s *DockerSuite) TestStatsAllNoStream(c *check.C) {
|
|||
assert.Assert(c, realData == nil, "stat result of %s should be empty : %s", id1, out)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStatsAllNewContainersAdded(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsAllNewContainersAdded(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
@ -162,7 +162,7 @@ func (s *DockerSuite) TestStatsAllNewContainersAdded(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStatsFormatAll(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsFormatAll(c *testing.T) {
|
||||
// Windows does not support stats
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,22 +5,23 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--mount", "type=volume,source=my-volume,destination=/foo,volume-driver=customvolumedriver", "--name", "top", "busybox", "top")
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
// Make sure task stays pending before plugin is available
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
plugin := newVolumePlugin(c, "customvolumedriver")
|
||||
defer plugin.Close()
|
||||
|
@ -34,7 +35,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
|
|||
// this long delay.
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
out, err = d.Cmd("ps", "-q")
|
||||
assert.NilError(c, err)
|
||||
|
@ -55,7 +56,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
|
|||
}
|
||||
|
||||
// Test network plugin filter in swarm
|
||||
func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) {
|
||||
func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *testing.T) {
|
||||
testRequires(c, IsAmd64)
|
||||
d1 := s.AddDaemon(c, true, true)
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
|
@ -80,7 +81,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 2)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// remove service
|
||||
_, err = d1.Cmd("service", "rm", serviceName)
|
||||
|
@ -88,7 +89,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) {
|
|||
|
||||
// wait to ensure all containers have exited before removing the plugin. Else there's a
|
||||
// possibility of container exits erroring out due to plugins being unavailable.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// disable plugin on worker
|
||||
_, err = d2.Cmd("plugin", "disable", "-f", pluginName)
|
||||
|
@ -101,6 +102,6 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) {
|
|||
_, err = d1.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--mode=global", "--network", networkName, image, "top")
|
||||
assert.NilError(c, err)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image: 1})
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@ package main
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
||||
func (s *DockerSuite) TestTopMultipleArgs(c *testing.T) {
|
||||
out := runSleepingContainer(c, "-d")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
|
@ -23,7 +23,7 @@ func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
|||
result.Assert(c, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
||||
func (s *DockerSuite) TestTopNonPrivileged(c *testing.T) {
|
||||
out := runSleepingContainer(c, "-d")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
|||
// TestTopWindowsCoreProcesses validates that there are lines for the critical
|
||||
// processes which are found in a Windows container. Note Windows is architecturally
|
||||
// very different to Linux in this regard.
|
||||
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *check.C) {
|
||||
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *testing.T) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
out := runSleepingContainer(c, "-d")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
@ -58,7 +58,7 @@ func (s *DockerSuite) TestTopWindowsCoreProcesses(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestTopPrivileged(c *check.C) {
|
||||
func (s *DockerSuite) TestTopPrivileged(c *testing.T) {
|
||||
// Windows does not support --privileged
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/creack/pty"
|
||||
|
@ -15,11 +16,10 @@ import (
|
|||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateRunningContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
|
@ -34,7 +34,7 @@ func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateStoppedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
|
@ -65,7 +65,7 @@ func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdatePausedContainer(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, cpuShare)
|
||||
|
||||
|
@ -82,7 +82,7 @@ func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "500")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateWithUntouchedFields(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateWithUntouchedFields(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, cpuShare)
|
||||
|
@ -100,7 +100,7 @@ func (s *DockerSuite) TestUpdateWithUntouchedFields(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "800")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateContainerInvalidValue(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateContainerInvalidValue(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
|
@ -112,7 +112,7 @@ func (s *DockerSuite) TestUpdateContainerInvalidValue(c *check.C) {
|
|||
assert.Assert(c, strings.Contains(out, expected))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
|
||||
|
@ -122,7 +122,7 @@ func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *check.C) {
|
|||
assert.ErrorContains(c, err, "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateKernelMemory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
||||
|
||||
name := "test-update-container"
|
||||
|
@ -136,7 +136,7 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "104857600")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
||||
|
||||
isNewKernel := CheckKernelVersion(4, 6, 0)
|
||||
|
@ -183,7 +183,7 @@ func CheckKernelVersion(k, major, minor int) bool {
|
|||
return kernel.CompareKernelVersion(*GetKernelVersion(), kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) >= 0
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, swapMemorySupport)
|
||||
|
@ -199,7 +199,7 @@ func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "629145600")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, swapMemorySupport)
|
||||
|
@ -224,7 +224,7 @@ func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *check.C) {
|
|||
assert.Equal(c, strings.TrimSpace(out), "629145600")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateStats(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateStats(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, cpuCfsQuota)
|
||||
|
@ -253,7 +253,7 @@ func (s *DockerSuite) TestUpdateStats(c *check.C) {
|
|||
assert.Equal(c, preMemLimit, curMemLimit)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
testRequires(c, memoryLimitSupport)
|
||||
testRequires(c, swapMemorySupport)
|
||||
|
@ -267,7 +267,7 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
|
|||
dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, cpuShare)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
|
||||
|
@ -295,7 +295,7 @@ func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) {
|
|||
assert.NilError(c, waitRun(id))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateWithNanoCPUs(c *check.C) {
|
||||
func (s *DockerSuite) TestUpdateWithNanoCPUs(c *testing.T) {
|
||||
testRequires(c, cpuCfsQuota, cpuCfsPeriod)
|
||||
|
||||
file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
|
||||
|
|
|
@ -11,18 +11,17 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// user namespaces test: run daemon with remapped root setting
|
||||
// 1. validate uid/gid maps are set properly
|
||||
// 2. verify that files created are owned by remapped root
|
||||
func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
||||
func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
|
||||
testRequires(c, UserNamespaceInKernel)
|
||||
|
||||
s.d.StartWithBusybox(c, "--userns-remap", "default")
|
||||
|
@ -38,7 +37,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
|||
|
||||
// we need to find the uid and gid of the remapped root from the daemon's root dir info
|
||||
uidgid := strings.Split(filepath.Base(s.d.Root), ".")
|
||||
c.Assert(uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
|
||||
assert.Equal(c, len(uidgid), 2, fmt.Sprintf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
|
||||
uid, err := strconv.Atoi(uidgid[0])
|
||||
assert.NilError(c, err, "Can't parse uid")
|
||||
gid, err := strconv.Atoi(uidgid[1])
|
||||
|
@ -51,16 +50,16 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
|||
assert.NilError(c, err, "Output: %s", out)
|
||||
|
||||
user := s.findUser(c, "userns")
|
||||
c.Assert(uidgid[0], checker.Equals, user)
|
||||
assert.Equal(c, uidgid[0], user)
|
||||
|
||||
// check that the created directory is owned by remapped uid:gid
|
||||
statNotExists, err := system.Stat(tmpDirNotExists)
|
||||
assert.NilError(c, err)
|
||||
c.Assert(statNotExists.UID(), checker.Equals, uint32(uid), check.Commentf("Created directory not owned by remapped root UID"))
|
||||
c.Assert(statNotExists.GID(), checker.Equals, uint32(gid), check.Commentf("Created directory not owned by remapped root GID"))
|
||||
assert.Equal(c, statNotExists.UID(), uint32(uid), "Created directory not owned by remapped root UID")
|
||||
assert.Equal(c, statNotExists.GID(), uint32(gid), "Created directory not owned by remapped root GID")
|
||||
|
||||
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Could not inspect running container: out: %q", pid))
|
||||
// check the uid and gid maps for the PID to ensure root is remapped
|
||||
// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')
|
||||
_, err = RunCommandPipelineWithOutput(
|
||||
|
@ -76,21 +75,21 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
|||
// check that the touched file is owned by remapped uid:gid
|
||||
stat, err := system.Stat(filepath.Join(tmpDir, "testfile"))
|
||||
assert.NilError(c, err)
|
||||
c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID"))
|
||||
c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID"))
|
||||
assert.Equal(c, stat.UID(), uint32(uid), "Touched file not owned by remapped root UID")
|
||||
assert.Equal(c, stat.GID(), uint32(gid), "Touched file not owned by remapped root GID")
|
||||
|
||||
// use host usernamespace
|
||||
out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; top")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out))
|
||||
user = s.findUser(c, "userns_skip")
|
||||
// userns are skipped, user is root
|
||||
c.Assert(user, checker.Equals, "root")
|
||||
assert.Equal(c, user, "root")
|
||||
}
|
||||
|
||||
// findUser finds the uid or name of the user of the first process that runs in a container
|
||||
func (s *DockerDaemonSuite) findUser(c *check.C, container string) string {
|
||||
func (s *DockerDaemonSuite) findUser(c *testing.T, container string) string {
|
||||
out, err := s.d.Cmd("top", container)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out))
|
||||
rows := strings.Split(out, "\n")
|
||||
if len(rows) < 2 {
|
||||
// No process rows founds
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/registry"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -25,7 +25,7 @@ func makefile(path string, contents string) (string, error) {
|
|||
|
||||
// TestV2Only ensures that a daemon does not
|
||||
// attempt to contact any v1 registry endpoints.
|
||||
func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
||||
func (s *DockerRegistrySuite) TestV2Only(c *testing.T) {
|
||||
reg, err := registry.NewMock(c)
|
||||
defer reg.Close()
|
||||
assert.NilError(c, err)
|
||||
|
|
|
@ -8,19 +8,18 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLICreate(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLICreate(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create")
|
||||
|
||||
_, _, err := dockerCmdWithError("volume", "create", "-d", "nosuchdriver")
|
||||
|
@ -29,31 +28,26 @@ func (s *DockerSuite) TestVolumeCLICreate(c *check.C) {
|
|||
// test using hidden --name option
|
||||
out, _ := dockerCmd(c, "volume", "create", "--name=test")
|
||||
name := strings.TrimSpace(out)
|
||||
c.Assert(name, check.Equals, "test")
|
||||
assert.Equal(c, name, "test")
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "create", "test2")
|
||||
name = strings.TrimSpace(out)
|
||||
c.Assert(name, check.Equals, "test2")
|
||||
assert.Equal(c, name, "test2")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIInspect(c *check.C) {
|
||||
c.Assert(
|
||||
exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run(),
|
||||
check.Not(check.IsNil),
|
||||
check.Commentf("volume inspect should error on non-existent volume"),
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIInspect(c *testing.T) {
|
||||
assert.Assert(c, exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run() != nil, "volume inspect should error on non-existent volume")
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
name := strings.TrimSpace(out)
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", name)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, name)
|
||||
assert.Equal(c, strings.TrimSpace(out), name)
|
||||
|
||||
dockerCmd(c, "volume", "create", "test")
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", "test")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "test")
|
||||
assert.Equal(c, strings.TrimSpace(out), "test")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIInspectMulti(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "test1")
|
||||
dockerCmd(c, "volume", "create", "test2")
|
||||
dockerCmd(c, "volume", "create", "test3")
|
||||
|
@ -65,12 +59,12 @@ func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) {
|
|||
})
|
||||
|
||||
out := result.Stdout()
|
||||
c.Assert(out, checker.Contains, "test1")
|
||||
c.Assert(out, checker.Contains, "test2")
|
||||
c.Assert(out, checker.Contains, "test3")
|
||||
assert.Assert(c, strings.Contains(out, "test1"))
|
||||
assert.Assert(c, strings.Contains(out, "test2"))
|
||||
assert.Assert(c, strings.Contains(out, "test3"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILs(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILs(c *testing.T) {
|
||||
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
||||
dockerCmd(c, "volume", "create", "aaa")
|
||||
|
||||
|
@ -83,7 +77,7 @@ func (s *DockerSuite) TestVolumeCLILs(c *check.C) {
|
|||
assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeLsFormat(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "aaa")
|
||||
dockerCmd(c, "volume", "create", "test")
|
||||
dockerCmd(c, "volume", "create", "soo")
|
||||
|
@ -92,7 +86,7 @@ func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
|
|||
assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *testing.T) {
|
||||
dockerCmd(c, "volume", "create", "aaa")
|
||||
dockerCmd(c, "volume", "create", "test")
|
||||
dockerCmd(c, "volume", "create", "soo")
|
||||
|
@ -111,7 +105,7 @@ func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) {
|
|||
assertVolumesInList(c, out, []string{"aaa default", "soo default", "test default"})
|
||||
}
|
||||
|
||||
func assertVolumesInList(c *check.C, out string, expected []string) {
|
||||
func assertVolumesInList(c *testing.T, out string, expected []string) {
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
for _, expect := range expected {
|
||||
found := false
|
||||
|
@ -125,7 +119,7 @@ func assertVolumesInList(c *check.C, out string, expected []string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *testing.T) {
|
||||
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
||||
dockerCmd(c, "volume", "create", "testnotinuse1")
|
||||
dockerCmd(c, "volume", "create", "testisinuse1")
|
||||
|
@ -139,55 +133,50 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
|
|||
out, _ := dockerCmd(c, "volume", "ls")
|
||||
|
||||
// No filter, all volumes should show
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse1\n"), "expected volume 'testisinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output")
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false")
|
||||
|
||||
// Explicitly disabling dangling
|
||||
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse1\n"), "expected volume 'testisinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output")
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true")
|
||||
|
||||
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), fmt.Sprintf("volume 'testisinuse1' in output, but not expected"))
|
||||
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), fmt.Sprintf("volume 'testisinuse2' in output, but not expected"))
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=1")
|
||||
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output, dangling also accept 1
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), fmt.Sprintf("volume 'testisinuse1' in output, but not expected"))
|
||||
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), fmt.Sprintf("volume 'testisinuse2' in output, but not expected"))
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=0")
|
||||
// dangling=0 is same as dangling=false case
|
||||
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
|
||||
assert.Assert(c, !strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse1\n"), "expected volume 'testisinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output")
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "name=testisin")
|
||||
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
assert.Assert(c, !strings.Contains(out, "testnotinuse1\n"), "expected volume 'testnotinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse1\n"), "expected volume 'testisinuse1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testisinuse2\n"), "expected volume 'testisinuse2' in output")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Invalid filter")
|
||||
assert.Assert(c, strings.Contains(out, "Invalid filter"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILsWithIncorrectFilterValue(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILsWithIncorrectFilterValue(c *testing.T) {
|
||||
out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid")
|
||||
assert.ErrorContains(c, err, "")
|
||||
c.Assert(out, checker.Contains, "Invalid filter")
|
||||
assert.Assert(c, strings.Contains(out, "Invalid filter"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIRm(c *testing.T) {
|
||||
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -205,30 +194,25 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
|
|||
})
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
|
||||
assert.Equal(c, strings.TrimSpace(out), "hello")
|
||||
dockerCmd(c, "rm", "-fv", "test2")
|
||||
dockerCmd(c, "volume", "inspect", volumeID)
|
||||
dockerCmd(c, "rm", "-f", "test")
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--name=test2", "-v", volumeID+":"+prefix+"/foo", "busybox", "sh", "-c", "cat /foo/bar")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "hello", check.Commentf("volume data was removed"))
|
||||
assert.Equal(c, strings.TrimSpace(out), "hello", "volume data was removed")
|
||||
dockerCmd(c, "rm", "test2")
|
||||
|
||||
dockerCmd(c, "volume", "rm", volumeID)
|
||||
c.Assert(
|
||||
exec.Command("volume", "rm", "doesnotexist").Run(),
|
||||
check.Not(check.IsNil),
|
||||
check.Commentf("volume rm should fail with non-existent volume"),
|
||||
)
|
||||
assert.Assert(c, exec.Command("volume", "rm", "doesnotexist").Run() != nil, "volume rm should fail with non-existent volume")
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test in cli/command/volume package
|
||||
func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLINoArgs(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "volume")
|
||||
// no args should produce the cmd usage output
|
||||
usage := "Usage: docker volume COMMAND"
|
||||
c.Assert(out, checker.Contains, usage)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, usage))
|
||||
// invalid arg should error and show the command usage on stderr
|
||||
icmd.RunCommand(dockerBinary, "volume", "somearg").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
|
@ -243,20 +227,20 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
|
|||
Error: "exit status 125",
|
||||
Err: usage,
|
||||
})
|
||||
c.Assert(result.Stderr(), checker.Contains, "unknown flag: --no-such-flag")
|
||||
assert.Assert(c, strings.Contains(result.Stderr(), "unknown flag: --no-such-flag"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
name := strings.TrimSpace(out)
|
||||
|
||||
out, exitCode, err := dockerCmdWithError("volume", "inspect", "--format='{{ .FooBar }}'", name)
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Output: %s", out))
|
||||
c.Assert(exitCode, checker.Equals, 1, check.Commentf("Output: %s", out))
|
||||
c.Assert(out, checker.Contains, "Template parsing error")
|
||||
assert.Assert(c, err != nil, fmt.Sprintf("Output: %s", out))
|
||||
assert.Equal(c, exitCode, 1, fmt.Sprintf("Output: %s", out))
|
||||
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
dockerCmd(c, "volume", "create", "-d", "local", "test", "--opt=type=tmpfs", "--opt=device=tmpfs", "--opt=o=size=1m,uid=1000")
|
||||
|
@ -269,18 +253,18 @@ func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *check.C) {
|
|||
found = true
|
||||
info := strings.Fields(m)
|
||||
// tmpfs on <path> type tmpfs (rw,relatime,size=1024k,uid=1000)
|
||||
c.Assert(info[0], checker.Equals, "tmpfs")
|
||||
c.Assert(info[2], checker.Equals, "/foo")
|
||||
c.Assert(info[4], checker.Equals, "tmpfs")
|
||||
c.Assert(info[5], checker.Contains, "uid=1000")
|
||||
c.Assert(info[5], checker.Contains, "size=1024k")
|
||||
assert.Equal(c, info[0], "tmpfs")
|
||||
assert.Equal(c, info[2], "/foo")
|
||||
assert.Equal(c, info[4], "tmpfs")
|
||||
assert.Assert(c, strings.Contains(info[5], "uid=1000"))
|
||||
assert.Assert(c, strings.Contains(info[5], "size=1024k"))
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Assert(found, checker.Equals, true)
|
||||
assert.Equal(c, found, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLICreateLabel(c *testing.T) {
|
||||
testVol := "testvolcreatelabel"
|
||||
testLabel := "foo"
|
||||
testValue := "bar"
|
||||
|
@ -289,10 +273,10 @@ func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, testValue)
|
||||
assert.Equal(c, strings.TrimSpace(out), testValue)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *testing.T) {
|
||||
testVol := "testvolcreatelabel"
|
||||
|
||||
testLabels := map[string]string{
|
||||
|
@ -315,11 +299,11 @@ func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) {
|
|||
|
||||
for k, v := range testLabels {
|
||||
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, v)
|
||||
assert.Equal(c, strings.TrimSpace(out), v)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *testing.T) {
|
||||
testVol1 := "testvolcreatelabel-1"
|
||||
_, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1)
|
||||
assert.NilError(c, err)
|
||||
|
@ -331,25 +315,23 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
|
|||
out, _ := dockerCmd(c, "volume", "ls", "--filter", "label=foo")
|
||||
|
||||
// filter with label=key
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testvolcreatelabel-1\n"), "expected volume 'testvolcreatelabel-1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testvolcreatelabel-2\n"), "expected volume 'testvolcreatelabel-2' in output")
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=bar1")
|
||||
|
||||
// filter with label=key=value
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2 in output"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testvolcreatelabel-1\n"), "expected volume 'testvolcreatelabel-1' in output")
|
||||
assert.Assert(c, !strings.Contains(out, "testvolcreatelabel-2\n"), "expected volume 'testvolcreatelabel-2 in output")
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=non-exist")
|
||||
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist")
|
||||
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *testing.T) {
|
||||
// using default volume driver local to create volumes
|
||||
testVol1 := "testvol-1"
|
||||
_, _, err := dockerCmdWithError("volume", "create", testVol1)
|
||||
|
@ -361,26 +343,25 @@ func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
|
|||
|
||||
// filter with driver=local
|
||||
out, _ := dockerCmd(c, "volume", "ls", "--filter", "driver=local")
|
||||
c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
|
||||
c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
|
||||
|
||||
assert.Assert(c, strings.Contains(out, "testvol-1\n"), "expected volume 'testvol-1' in output")
|
||||
assert.Assert(c, strings.Contains(out, "testvol-2\n"), "expected volume 'testvol-2' in output")
|
||||
// filter with driver=invaliddriver
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
|
||||
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
|
||||
|
||||
// filter with driver=loca
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
|
||||
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
|
||||
|
||||
// filter with driver=
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
|
||||
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *testing.T) {
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
|
@ -388,13 +369,13 @@ func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
|
|||
dockerCmd(c, "volume", "rm", "--force", "nonexist")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIRmForce(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
name := "test"
|
||||
out, _ := dockerCmd(c, "volume", "create", name)
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(id, checker.Equals, name)
|
||||
assert.Equal(c, id, name)
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format", "{{.Mountpoint}}", name)
|
||||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
@ -404,19 +385,19 @@ func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {
|
|||
|
||||
dockerCmd(c, "volume", "rm", "-f", name)
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
assert.Assert(c, !strings.Contains(out, name))
|
||||
dockerCmd(c, "volume", "create", name)
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Contains, name)
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
}
|
||||
|
||||
// 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
|
||||
func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *testing.T) {
|
||||
name := "testvolume"
|
||||
out, _ := dockerCmd(c, "volume", "create", name)
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(id, checker.Equals, name)
|
||||
assert.Equal(c, id, name)
|
||||
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
out, _ = dockerCmd(c, "create", "-v", "testvolume:"+prefix+slash+"foo", "busybox")
|
||||
|
@ -426,8 +407,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
|
|||
assert.ErrorContains(c, err, "")
|
||||
assert.ErrorContains(c, err, "volume is in use")
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Contains, name)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
// The original issue did not _remove_ the volume from the list
|
||||
// the first time. But a second call to `volume rm` removed it.
|
||||
// Calling `volume rm` a second time to confirm it's not removed
|
||||
|
@ -436,29 +416,27 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
|
|||
assert.ErrorContains(c, err, "")
|
||||
assert.ErrorContains(c, err, "volume is in use")
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Contains, name)
|
||||
|
||||
assert.Assert(c, strings.Contains(out, name))
|
||||
// Verify removing the volume after the container is removed works
|
||||
_, e := dockerCmd(c, "rm", cid)
|
||||
c.Assert(e, check.Equals, 0)
|
||||
assert.Equal(c, e, 0)
|
||||
|
||||
_, e = dockerCmd(c, "volume", "rm", "-f", name)
|
||||
c.Assert(e, check.Equals, 0)
|
||||
assert.Equal(c, e, 0)
|
||||
|
||||
out, e = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(e, check.Equals, 0)
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
assert.Equal(c, e, 0)
|
||||
assert.Assert(c, !strings.Contains(out, name))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) {
|
||||
func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
// Without options
|
||||
name := "test1"
|
||||
dockerCmd(c, "volume", "create", "-d", "local", name)
|
||||
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "map[]")
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "map[]"))
|
||||
// With options
|
||||
name = "test2"
|
||||
k1, v1 := "type", "tmpfs"
|
||||
|
@ -466,13 +444,13 @@ func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) {
|
|||
k3, v3 := "o", "size=1m,uid=1000"
|
||||
dockerCmd(c, "volume", "create", "-d", "local", name, "--opt", fmt.Sprintf("%s=%s", k1, v1), "--opt", fmt.Sprintf("%s=%s", k2, v2), "--opt", fmt.Sprintf("%s=%s", k3, v3))
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k1, v1))
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k2, v2))
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k3, v3))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), fmt.Sprintf("%s:%s", k1, v1)))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), fmt.Sprintf("%s:%s", k2, v2)))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), fmt.Sprintf("%s:%s", k3, v3)))
|
||||
}
|
||||
|
||||
// Test case (1) for 21845: duplicate targets for --volumes-from
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *check.C) {
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
image := "vimage"
|
||||
|
@ -485,19 +463,18 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *check.C) {
|
|||
|
||||
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
|
||||
data1 := strings.TrimSpace(out)
|
||||
c.Assert(data1, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data1 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
|
||||
data2 := strings.TrimSpace(out)
|
||||
c.Assert(data2, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data2 != "")
|
||||
|
||||
// Both volume should exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data2))
|
||||
out, _, err := dockerCmdWithError("run", "--name=app", "--volumes-from=data1", "--volumes-from=data2", "-d", "busybox", "top")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Out: %s", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Out: %s", out))
|
||||
|
||||
// Only the second volume will be referenced, this is backward compatible
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
|
||||
|
@ -509,12 +486,12 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *check.C) {
|
|||
|
||||
// Both volume should not exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data2))
|
||||
}
|
||||
|
||||
// Test case (2) for 21845: duplicate targets for --volumes-from and -v (bind)
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *check.C) {
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
image := "vimage"
|
||||
|
@ -527,38 +504,36 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *check.C)
|
|||
|
||||
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
|
||||
data1 := strings.TrimSpace(out)
|
||||
c.Assert(data1, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data1 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
|
||||
data2 := strings.TrimSpace(out)
|
||||
c.Assert(data2, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data2 != "")
|
||||
|
||||
// Both volume should exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data2))
|
||||
// /tmp/data is automatically created, because we are not using the modern mount API here
|
||||
out, _, err := dockerCmdWithError("run", "--name=app", "--volumes-from=data1", "--volumes-from=data2", "-v", "/tmp/data:/tmp/data", "-d", "busybox", "top")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Out: %s", out))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("Out: %s", out))
|
||||
|
||||
// No volume will be referenced (mount is /tmp/data), this is backward compatible
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data2))
|
||||
dockerCmd(c, "rm", "-f", "-v", "app")
|
||||
dockerCmd(c, "rm", "-f", "-v", "data1")
|
||||
dockerCmd(c, "rm", "-f", "-v", "data2")
|
||||
|
||||
// Both volume should not exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data2))
|
||||
}
|
||||
|
||||
// Test case (3) for 21845: duplicate targets for --volumes-from and `Mounts` (API only)
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C) {
|
||||
func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *testing.T) {
|
||||
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
||||
|
||||
image := "vimage"
|
||||
|
@ -571,17 +546,16 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C
|
|||
|
||||
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
|
||||
data1 := strings.TrimSpace(out)
|
||||
c.Assert(data1, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data1 != "")
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
|
||||
data2 := strings.TrimSpace(out)
|
||||
c.Assert(data2, checker.Not(checker.Equals), "")
|
||||
assert.Assert(c, data2 != "")
|
||||
|
||||
// Both volume should exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
|
||||
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data2))
|
||||
err := os.MkdirAll("/tmp/data", 0755)
|
||||
assert.NilError(c, err)
|
||||
// Mounts is available in API
|
||||
|
@ -610,15 +584,14 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C
|
|||
|
||||
// No volume will be referenced (mount is /tmp/data), this is backward compatible
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
|
||||
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data2))
|
||||
dockerCmd(c, "rm", "-f", "-v", "app")
|
||||
dockerCmd(c, "rm", "-f", "-v", "data1")
|
||||
dockerCmd(c, "rm", "-f", "-v", "data2")
|
||||
|
||||
// Both volume should not exist
|
||||
out, _ = dockerCmd(c, "volume", "ls", "-q")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data1))
|
||||
assert.Assert(c, !strings.Contains(strings.TrimSpace(out), data2))
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ package main
|
|||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func formatV123StartAPIURL(url string) string {
|
|||
return "/v1.23" + url
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) {
|
||||
name := "test-deprecated-api-124"
|
||||
dockerCmd(c, "create", "--name", name, "busybox")
|
||||
config := map[string]interface{}{
|
||||
|
@ -37,7 +37,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *testing.T) {
|
||||
// TODO Windows CI: Investigate further why this fails on Windows to Windows CI.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
path := "/foo"
|
||||
|
@ -68,7 +68,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
|
|||
}
|
||||
|
||||
// Test for GH#10618
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *testing.T) {
|
||||
// TODO Windows to Windows CI - Port this
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testdups"
|
||||
|
@ -101,7 +101,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C)
|
|||
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 *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T) {
|
||||
// TODO Windows to Windows CI - Port this
|
||||
testRequires(c, DaemonIsLinux)
|
||||
volName := "voltst"
|
||||
|
@ -134,7 +134,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *check.C) {
|
|||
}
|
||||
|
||||
// #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 *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) {
|
||||
// TODO Windows to Windows CI - Port this
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
|
||||
|
@ -154,7 +154,7 @@ func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *check.C) {
|
|||
assert.Equal(c, fooDir2, fooDir, "expected volume path to be %s, got: %s", fooDir, fooDir2)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) {
|
||||
// TODO Windows: Port once memory is supported
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "create", "busybox")
|
||||
|
@ -179,7 +179,7 @@ func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) {
|
|||
}
|
||||
|
||||
// #14640
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *testing.T) {
|
||||
// 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
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -196,7 +196,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(
|
|||
}
|
||||
|
||||
// #14640
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *testing.T) {
|
||||
// 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
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
@ -214,7 +214,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *
|
|||
}
|
||||
|
||||
// #14640
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) {
|
||||
// Windows does not support links
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-host-config-links"
|
||||
|
@ -233,7 +233,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLi
|
|||
b.Close()
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *check.C) {
|
||||
func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *testing.T) {
|
||||
// TODO Windows: Add once DNS is supported
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "create", "busybox")
|
||||
|
|
|
@ -4,14 +4,14 @@ package main
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// #19100 This is a deprecated feature test, it should be removed in Docker 1.12
|
||||
func (s *DockerNetworkSuite) TestDeprecatedDockerNetworkStartAPIWithHostconfig(c *check.C) {
|
||||
func (s *DockerNetworkSuite) TestDeprecatedDockerNetworkStartAPIWithHostconfig(c *testing.T) {
|
||||
netName := "test"
|
||||
conName := "foo"
|
||||
dockerCmd(c, "network", "create", netName)
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
|
||||
// Windows to Linux CI @icecrime
|
||||
if runtime.GOOS != "windows" {
|
||||
check.Suite(newDockerHubPullSuite())
|
||||
}
|
||||
}
|
||||
|
||||
// DockerHubPullSuite provides an isolated daemon that doesn't have all the
|
||||
// images that are baked into our 'global' test environment daemon (e.g.,
|
||||
// busybox, httpserver, ...).
|
||||
|
@ -39,26 +31,26 @@ func newDockerHubPullSuite() *DockerHubPullSuite {
|
|||
}
|
||||
|
||||
// SetUpSuite starts the suite daemon.
|
||||
func (s *DockerHubPullSuite) SetUpSuite(c *check.C) {
|
||||
func (s *DockerHubPullSuite) SetUpSuite(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
||||
s.d.Start(c)
|
||||
}
|
||||
|
||||
// TearDownSuite stops the suite daemon.
|
||||
func (s *DockerHubPullSuite) TearDownSuite(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TearDownSuite(c *testing.T) {
|
||||
if s.d != nil {
|
||||
s.d.Stop(c)
|
||||
}
|
||||
}
|
||||
|
||||
// SetUpTest declares that all tests of this suite require network.
|
||||
func (s *DockerHubPullSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerHubPullSuite) SetUpTest(c *testing.T) {
|
||||
testRequires(c, Network)
|
||||
}
|
||||
|
||||
// TearDownTest removes all images from the suite daemon.
|
||||
func (s *DockerHubPullSuite) TearDownTest(c *check.C) {
|
||||
func (s *DockerHubPullSuite) TearDownTest(c *testing.T) {
|
||||
out := s.Cmd(c, "images", "-aq")
|
||||
images := strings.Split(out, "\n")
|
||||
images = append([]string{"rmi", "-f"}, images...)
|
||||
|
@ -68,9 +60,9 @@ func (s *DockerHubPullSuite) TearDownTest(c *check.C) {
|
|||
|
||||
// Cmd executes a command against the suite daemon and returns the combined
|
||||
// output. The function fails the test when the command returns an error.
|
||||
func (s *DockerHubPullSuite) Cmd(c *check.C, name string, arg ...string) string {
|
||||
func (s *DockerHubPullSuite) Cmd(c *testing.T, name string, arg ...string) string {
|
||||
out, err := s.CmdWithError(name, arg...)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
|
||||
return out
|
||||
}
|
||||
|
||||
|
|
|
@ -12,15 +12,17 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func deleteImages(images ...string) error {
|
||||
|
@ -38,7 +40,7 @@ func dockerCmdWithError(args ...string) (string, int, error) {
|
|||
}
|
||||
|
||||
// Deprecated: use cli.Docker or cli.DockerCmd
|
||||
func dockerCmd(c *check.C, args ...string) (string, int) {
|
||||
func dockerCmd(c testing.TB, args ...string) (string, int) {
|
||||
result := cli.DockerCmd(c, args...)
|
||||
return result.Combined(), result.ExitCode
|
||||
}
|
||||
|
@ -48,12 +50,14 @@ func dockerCmdWithResult(args ...string) *icmd.Result {
|
|||
return cli.Docker(cli.Args(args...))
|
||||
}
|
||||
|
||||
func findContainerIP(c *check.C, id string, network string) string {
|
||||
func findContainerIP(c *testing.T, id string, network string) string {
|
||||
c.Helper()
|
||||
out, _ := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
|
||||
return strings.Trim(out, " \r\n'")
|
||||
}
|
||||
|
||||
func getContainerCount(c *check.C) int {
|
||||
func getContainerCount(c *testing.T) int {
|
||||
c.Helper()
|
||||
const containers = "Containers:"
|
||||
|
||||
result := icmd.RunCommand(dockerBinary, "info")
|
||||
|
@ -73,11 +77,12 @@ func getContainerCount(c *check.C) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) {
|
||||
func inspectFieldAndUnmarshall(c *testing.T, name, field string, output interface{}) {
|
||||
c.Helper()
|
||||
str := inspectFieldJSON(c, name, field)
|
||||
err := json.Unmarshal([]byte(str), output)
|
||||
if c != nil {
|
||||
c.Assert(err, check.IsNil, check.Commentf("failed to unmarshal: %v", err))
|
||||
assert.Assert(c, err == nil, fmt.Sprintf("failed to unmarshal: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +102,8 @@ func inspectFieldWithError(name, field string) (string, error) {
|
|||
}
|
||||
|
||||
// Deprecated: use cli.Inspect
|
||||
func inspectField(c *check.C, name, field string) string {
|
||||
func inspectField(c *testing.T, name, field string) string {
|
||||
c.Helper()
|
||||
out, err := inspectFilter(name, fmt.Sprintf(".%s", field))
|
||||
if c != nil {
|
||||
assert.NilError(c, err)
|
||||
|
@ -106,7 +112,8 @@ func inspectField(c *check.C, name, field string) string {
|
|||
}
|
||||
|
||||
// Deprecated: use cli.Inspect
|
||||
func inspectFieldJSON(c *check.C, name, field string) string {
|
||||
func inspectFieldJSON(c *testing.T, name, field string) string {
|
||||
c.Helper()
|
||||
out, err := inspectFilter(name, fmt.Sprintf("json .%s", field))
|
||||
if c != nil {
|
||||
assert.NilError(c, err)
|
||||
|
@ -115,7 +122,8 @@ func inspectFieldJSON(c *check.C, name, field string) string {
|
|||
}
|
||||
|
||||
// Deprecated: use cli.Inspect
|
||||
func inspectFieldMap(c *check.C, name, path, field string) string {
|
||||
func inspectFieldMap(c *testing.T, name, path, field string) string {
|
||||
c.Helper()
|
||||
out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field))
|
||||
if c != nil {
|
||||
assert.NilError(c, err)
|
||||
|
@ -167,7 +175,8 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
|
|||
}
|
||||
|
||||
// Deprecated: use cli.Inspect
|
||||
func inspectImage(c *check.C, name, filter string) string {
|
||||
func inspectImage(c *testing.T, name, filter string) string {
|
||||
c.Helper()
|
||||
args := []string{"inspect", "--type", "image"}
|
||||
if filter != "" {
|
||||
format := fmt.Sprintf("{{%s}}", filter)
|
||||
|
@ -179,14 +188,16 @@ func inspectImage(c *check.C, name, filter string) string {
|
|||
return strings.TrimSpace(result.Combined())
|
||||
}
|
||||
|
||||
func getIDByName(c *check.C, name string) string {
|
||||
func getIDByName(c *testing.T, name string) string {
|
||||
c.Helper()
|
||||
id, err := inspectFieldWithError(name, "Id")
|
||||
assert.NilError(c, err)
|
||||
return id
|
||||
}
|
||||
|
||||
// Deprecated: use cli.Build
|
||||
func buildImageSuccessfully(c *check.C, name string, cmdOperators ...cli.CmdOperator) {
|
||||
func buildImageSuccessfully(c *testing.T, name string, cmdOperators ...cli.CmdOperator) {
|
||||
c.Helper()
|
||||
buildImage(name, cmdOperators...).Assert(c, icmd.Success)
|
||||
}
|
||||
|
||||
|
@ -199,9 +210,10 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
|
|||
// as well as any missing directories.
|
||||
// The file is truncated if it already exists.
|
||||
// Fail the test when error occurs.
|
||||
func writeFile(dst, content string, c *check.C) {
|
||||
func writeFile(dst, content string, c *testing.T) {
|
||||
c.Helper()
|
||||
// Create subdirectories if necessary
|
||||
c.Assert(os.MkdirAll(path.Dir(dst), 0700), check.IsNil)
|
||||
assert.Assert(c, os.MkdirAll(path.Dir(dst), 0700) == nil)
|
||||
f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
|
||||
assert.NilError(c, err)
|
||||
defer f.Close()
|
||||
|
@ -212,7 +224,8 @@ func writeFile(dst, content string, c *check.C) {
|
|||
|
||||
// Return the contents of file at path `src`.
|
||||
// Fail the test when error occurs.
|
||||
func readFile(src string, c *check.C) (content string) {
|
||||
func readFile(src string, c *testing.T) (content string) {
|
||||
c.Helper()
|
||||
data, err := ioutil.ReadFile(src)
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -224,7 +237,8 @@ func containerStorageFile(containerID, basename string) string {
|
|||
}
|
||||
|
||||
// docker commands that use this function must be run with the '-d' switch.
|
||||
func runCommandAndReadContainerFile(c *check.C, filename string, command string, args ...string) []byte {
|
||||
func runCommandAndReadContainerFile(c *testing.T, filename string, command string, args ...string) []byte {
|
||||
c.Helper()
|
||||
result := icmd.RunCommand(command, args...)
|
||||
result.Assert(c, icmd.Success)
|
||||
contID := strings.TrimSpace(result.Combined())
|
||||
|
@ -234,7 +248,8 @@ func runCommandAndReadContainerFile(c *check.C, filename string, command string,
|
|||
return readContainerFile(c, contID, filename)
|
||||
}
|
||||
|
||||
func readContainerFile(c *check.C, containerID, filename string) []byte {
|
||||
func readContainerFile(c *testing.T, containerID, filename string) []byte {
|
||||
c.Helper()
|
||||
f, err := os.Open(containerStorageFile(containerID, filename))
|
||||
assert.NilError(c, err)
|
||||
defer f.Close()
|
||||
|
@ -244,14 +259,16 @@ func readContainerFile(c *check.C, containerID, filename string) []byte {
|
|||
return content
|
||||
}
|
||||
|
||||
func readContainerFileWithExec(c *check.C, containerID, filename string) []byte {
|
||||
func readContainerFileWithExec(c *testing.T, containerID, filename string) []byte {
|
||||
c.Helper()
|
||||
result := icmd.RunCommand(dockerBinary, "exec", containerID, "cat", filename)
|
||||
result.Assert(c, icmd.Success)
|
||||
return []byte(result.Combined())
|
||||
}
|
||||
|
||||
// daemonTime provides the current time on the daemon host
|
||||
func daemonTime(c *check.C) time.Time {
|
||||
func daemonTime(c *testing.T) time.Time {
|
||||
c.Helper()
|
||||
if testEnv.IsLocalDaemon() {
|
||||
return time.Now()
|
||||
}
|
||||
|
@ -263,13 +280,14 @@ func daemonTime(c *check.C) time.Time {
|
|||
assert.NilError(c, err)
|
||||
|
||||
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
|
||||
c.Assert(err, check.IsNil, check.Commentf("invalid time format in GET /info response"))
|
||||
assert.Assert(c, err == nil, "invalid time format in GET /info response")
|
||||
return dt
|
||||
}
|
||||
|
||||
// daemonUnixTime returns the current time on the daemon host with nanoseconds precision.
|
||||
// It return the time formatted how the client sends timestamps to the server.
|
||||
func daemonUnixTime(c *check.C) string {
|
||||
func daemonUnixTime(c *testing.T) string {
|
||||
c.Helper()
|
||||
return parseEventTime(daemonTime(c))
|
||||
}
|
||||
|
||||
|
@ -304,7 +322,8 @@ func appendBaseEnv(isTLS bool, env ...string) []string {
|
|||
return env
|
||||
}
|
||||
|
||||
func createTmpFile(c *check.C, content string) string {
|
||||
func createTmpFile(c *testing.T, content string) string {
|
||||
c.Helper()
|
||||
f, err := ioutil.TempFile("", "testfile")
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -335,7 +354,8 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg
|
|||
return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout, arg...)
|
||||
}
|
||||
|
||||
func getInspectBody(c *check.C, version, id string) []byte {
|
||||
func getInspectBody(c *testing.T, version, id string) []byte {
|
||||
c.Helper()
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(version))
|
||||
assert.NilError(c, err)
|
||||
defer cli.Close()
|
||||
|
@ -346,13 +366,15 @@ func getInspectBody(c *check.C, version, id string) []byte {
|
|||
|
||||
// Run a long running idle task in a background container using the
|
||||
// system-specific default image and command.
|
||||
func runSleepingContainer(c *check.C, extraArgs ...string) string {
|
||||
func runSleepingContainer(c *testing.T, extraArgs ...string) string {
|
||||
c.Helper()
|
||||
return runSleepingContainerInImage(c, "busybox", extraArgs...)
|
||||
}
|
||||
|
||||
// Run a long running idle task in a background container using the specified
|
||||
// image and the system-specific command.
|
||||
func runSleepingContainerInImage(c *check.C, image string, extraArgs ...string) string {
|
||||
func runSleepingContainerInImage(c *testing.T, image string, extraArgs ...string) string {
|
||||
c.Helper()
|
||||
args := []string{"run", "-d"}
|
||||
args = append(args, extraArgs...)
|
||||
args = append(args, image)
|
||||
|
@ -406,54 +428,50 @@ func waitForGoroutines(expected int) error {
|
|||
}
|
||||
|
||||
// getErrorMessage returns the error message from an error API response
|
||||
func getErrorMessage(c *check.C, body []byte) string {
|
||||
func getErrorMessage(c *testing.T, body []byte) string {
|
||||
c.Helper()
|
||||
var resp types.ErrorResponse
|
||||
c.Assert(json.Unmarshal(body, &resp), check.IsNil)
|
||||
assert.Assert(c, json.Unmarshal(body, &resp) == nil)
|
||||
return strings.TrimSpace(resp.Message)
|
||||
}
|
||||
|
||||
func waitAndAssert(c *check.C, timeout time.Duration, f checkF, checker check.Checker, args ...interface{}) {
|
||||
t1 := time.Now()
|
||||
defer func() {
|
||||
t2 := time.Now()
|
||||
c.Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
|
||||
}()
|
||||
type checkF func(*testing.T) (interface{}, string)
|
||||
type reducer func(...interface{}) interface{}
|
||||
|
||||
after := time.After(timeout)
|
||||
for {
|
||||
v, comment := f(c)
|
||||
assert, _ := checker.Check(append([]interface{}{v}, args...), checker.Info().Params)
|
||||
select {
|
||||
case <-after:
|
||||
assert = true
|
||||
default:
|
||||
}
|
||||
if assert {
|
||||
if comment != nil {
|
||||
args = append(args, comment)
|
||||
func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
|
||||
return func(poll.LogT) poll.Result {
|
||||
t.Helper()
|
||||
v, comment := f(t)
|
||||
r := compare(v)
|
||||
switch r := r.(type) {
|
||||
case bool:
|
||||
if r {
|
||||
return poll.Success()
|
||||
}
|
||||
c.Assert(v, checker, args...)
|
||||
return
|
||||
case cmp.Comparison:
|
||||
if r().Success() {
|
||||
return poll.Success()
|
||||
}
|
||||
default:
|
||||
panic(fmt.Errorf("pollCheck: type %T not implemented", r))
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
return poll.Continue(comment)
|
||||
}
|
||||
}
|
||||
|
||||
type checkF func(*check.C) (interface{}, check.CommentInterface)
|
||||
type reducer func(...interface{}) interface{}
|
||||
|
||||
func reducedCheck(r reducer, funcs ...checkF) checkF {
|
||||
return func(c *check.C) (interface{}, check.CommentInterface) {
|
||||
return func(c *testing.T) (interface{}, string) {
|
||||
c.Helper()
|
||||
var values []interface{}
|
||||
var comments []string
|
||||
for _, f := range funcs {
|
||||
v, comment := f(c)
|
||||
values = append(values, v)
|
||||
if comment != nil {
|
||||
comments = append(comments, comment.CheckCommentString())
|
||||
if len(comment) > 0 {
|
||||
comments = append(comments, comment)
|
||||
}
|
||||
}
|
||||
return r(values...), check.Commentf("%v", strings.Join(comments, ", "))
|
||||
return r(values...), fmt.Sprintf("%v", strings.Join(comments, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
eventstestutils "github.com/docker/docker/daemon/events/testutils"
|
||||
"github.com/go-check/check"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
@ -35,13 +35,13 @@ type eventObserver struct {
|
|||
|
||||
// newEventObserver creates the observer and initializes the command
|
||||
// without running it. Users must call `eventObserver.Start` to start the command.
|
||||
func newEventObserver(c *check.C, args ...string) (*eventObserver, error) {
|
||||
func newEventObserver(c *testing.T, args ...string) (*eventObserver, error) {
|
||||
since := daemonTime(c).Unix()
|
||||
return newEventObserverWithBacklog(c, since, args...)
|
||||
}
|
||||
|
||||
// newEventObserverWithBacklog creates a new observer changing the start time of the backlog to return.
|
||||
func newEventObserverWithBacklog(c *check.C, since int64, args ...string) (*eventObserver, error) {
|
||||
func newEventObserverWithBacklog(c *testing.T, since int64, args ...string) (*eventObserver, error) {
|
||||
startTime := strconv.FormatInt(since, 10)
|
||||
cmdArgs := []string{"events", "--since", startTime}
|
||||
if len(args) > 0 {
|
||||
|
@ -93,7 +93,7 @@ func (e *eventObserver) Match(match eventMatcher, process eventMatchProcessor) {
|
|||
e.disconnectionError = err
|
||||
}
|
||||
|
||||
func (e *eventObserver) CheckEventError(c *check.C, id, event string, match eventMatcher) {
|
||||
func (e *eventObserver) CheckEventError(c *testing.T, id, event string, match eventMatcher) {
|
||||
var foundEvent bool
|
||||
scannerOut := e.buffer.String()
|
||||
|
||||
|
@ -144,14 +144,14 @@ func processEventMatch(actions map[string]chan bool) eventMatchProcessor {
|
|||
|
||||
// parseEventAction parses an event text and returns the action.
|
||||
// It fails if the text is not in the event format.
|
||||
func parseEventAction(c *check.C, text string) string {
|
||||
func parseEventAction(c *testing.T, text string) string {
|
||||
matches := eventstestutils.ScanMap(text)
|
||||
return matches["action"]
|
||||
}
|
||||
|
||||
// eventActionsByIDAndType returns the actions for a given id and type.
|
||||
// It fails if the text is not in the event format.
|
||||
func eventActionsByIDAndType(c *check.C, events []string, id, eventType string) []string {
|
||||
func eventActionsByIDAndType(c *testing.T, events []string, id, eventType string) []string {
|
||||
var filtered []string
|
||||
for _, event := range events {
|
||||
matches := eventstestutils.ScanMap(event)
|
||||
|
@ -183,7 +183,7 @@ func matchEventID(matches map[string]string, id string) bool {
|
|||
return matchID
|
||||
}
|
||||
|
||||
func parseEvents(c *check.C, out, match string) {
|
||||
func parseEvents(c *testing.T, out, match string) {
|
||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||
for _, event := range events {
|
||||
matches := eventstestutils.ScanMap(event)
|
||||
|
@ -193,7 +193,7 @@ func parseEvents(c *check.C, out, match string) {
|
|||
}
|
||||
}
|
||||
|
||||
func parseEventsWithID(c *check.C, out, match, id string) {
|
||||
func parseEventsWithID(c *testing.T, out, match, id string) {
|
||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||
for _, event := range events {
|
||||
matches := eventstestutils.ScanMap(event)
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/fixtures/load"
|
||||
"github.com/go-check/check"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ type logT interface {
|
|||
Logf(string, ...interface{})
|
||||
}
|
||||
|
||||
func ensureSyscallTest(c *check.C) {
|
||||
func ensureSyscallTest(c *testing.T) {
|
||||
defer testEnv.ProtectImage(c, "syscall-test:latest")
|
||||
|
||||
// If the image already exists, there's nothing left to do.
|
||||
|
@ -73,7 +73,7 @@ func ensureSyscallTest(c *check.C) {
|
|||
dockerCmd(c, buildArgs...)
|
||||
}
|
||||
|
||||
func ensureSyscallTestBuild(c *check.C) {
|
||||
func ensureSyscallTestBuild(c *testing.T) {
|
||||
err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie")
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
@ -86,7 +86,7 @@ func ensureSyscallTestBuild(c *check.C) {
|
|||
dockerCmd(c, buildArgs...)
|
||||
}
|
||||
|
||||
func ensureNNPTest(c *check.C) {
|
||||
func ensureNNPTest(c *testing.T) {
|
||||
defer testEnv.ProtectImage(c, "nnp-test:latest")
|
||||
|
||||
// If the image already exists, there's nothing left to do.
|
||||
|
@ -128,7 +128,7 @@ func ensureNNPTest(c *check.C) {
|
|||
dockerCmd(c, buildArgs...)
|
||||
}
|
||||
|
||||
func ensureNNPTestBuild(c *check.C) {
|
||||
func ensureNNPTestBuild(c *testing.T) {
|
||||
err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie")
|
||||
assert.NilError(c, err)
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue