Compare commits

...

106 Commits

Author SHA1 Message Date
Andrew Hsu
20afdcca5b vndr hcsshim to 79062a5
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:31 +01:00
Brian Goff
013d32fbb4 Make sure plugin container is removed on failure
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit f81172b903)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:31 +01:00
Brian Goff
c2cd49a8c5 Limit authz response buffer
When the authz response buffer limit is hit, perform a flush.
This prevents excessive buffer sizes, especially on large responses
(e.g. `/containers/<id>/archive` or `/containers/<id>/export`).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 74f8e47352)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Brian Goff
542579765f Relax global client lock on containerd restore.
This unblocks the client to take other restore requests and makes sure
that a long/stuck request can't block the client forever.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 806700e410)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Anshul Pundir
a67faac16c Increase raft ElectionTick to 10xHeartbeatTick
Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
(cherry picked from commit 6abee2008b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Michael Crosby
4539f775e6 Don't make container mount unbindable
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
(cherry picked from commit 4c000662fe)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Dennis Chen
c32b5dfc1d Fix a misused network object name
A minor nit. `test01` never been created and used in
`TestDockerNetworkInspectCustomSpecified()` function, so correct it.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit f041953d04)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Anda Xu
06fd90daf2 remove the retries for service update
Signed-off-by: Anda Xu <anda.xu@docker.com>
(cherry picked from commit 7380935331)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Yong Tang
6713f305bb Migrate image tag tests from integration-cli to api tests
This fix migrates image tag tests from integration-cli to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 9bcb960508)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Vincent Demeester
00f955e7a6 Move fakecontext, fakegit and fakestorage to internal/test
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 062564084a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:30 +01:00
Yong Tang
c7b1f41608 Some enhancement in integration tests
This fix converts some `client.ContainerCreate` to `container.Create`,
and removes some unneeded `name` fields when test containers are created.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit ab9bb47b05)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:29 +01:00
Vincent Demeester
e1b115372b Small daemon refactoring and add swarm init/join helpers
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 239a8a5189)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:29 +01:00
Vincent Demeester
b265f7730a Migrate test-integration-cli experimental build tests to integration
All `docker build` tests that require an `ExperimentalDaemon` are
migrated to `integration/build` package and start an experimental
daemon to test on it.

The end goal being to remove the `experimental` builds.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 183076e89d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:29 +01:00
Vincent Demeester
fef9c5a3b3 Clean some integration-cli/fixtures package/files
- Move go package used by both `integration-cli` and `integration` to
  `internal/test/fixtures`.
- Remove fixtures that are not used anymore (moved to `docker/cli` a
  while ago) : deploy, notary, secrets.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 5f56503f58)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:29 +01:00
Vincent Demeester
0e948a6988 Move and refactor integration-cli/registry to internal/test
- Move the code from `integration-cli` to `internal/test`.
- Use `testingT` and `assert` when creating the registry.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 66de2e6e3b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:29 +01:00
Vincent Demeester
c206c134f2 Move ipvlan and macvlan tests on their own folder…
… making each folder/suites quicker to run

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit a3323d2e43)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Vincent Demeester
015cf3b51e Refactor macvlan tests a bit
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 0ab6116ce8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Vincent Demeester
ecd848d6ad Migrate test-integration-cli experimental ipvlan test to integration
All `Ipvlan` related test on `DockerSuite` and `DockerNetworkSuite`
are migrated to `ipvlan_test.go`.

The end goal being to remove the `experimental` builds.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 24f9347511)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Vincent Demeester
e5289cabed Make internal/test/daemon.Daemon swarm aware
This remove the daemon.Swarm construction by make the new test Daemon
struct aware of swarm.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 83d18cf4e3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Dennis Chen
1ded34ecfb Using the default PollSettings function
Using the default PollSettings functions to adjust the timeout
value instead of changing the value each time when needed.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit b8912feeff)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Dennis Chen
c97859ba2d Add default pollSettings adjustment routines
Add the default function per resource to override the `pollSettings`
which will be re-used where it's needed.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit ee6959addc)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
selansen
98e2aa7a1a Fix for Flaky test TestServiceWithPredefinedNetwork
TestServiceWithPredefinedNetwork test case was failing
	at times. To fix the issue, added new API to check
	for services after we clean up all services. Tested
	multiple times and this sould fix flaky issue.

Signed-off-by: selansen <elango.siva@docker.com>
(cherry picked from commit dabffd806c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Vincent Demeester
420caf9e77 Move integration-cli daemon package to internal/test…
… and do not use the `docker` cli in it. One of the reason of this
move is to not make `integration` package using legacy
`integration-cli` package.

Next move will be to support swarm within this package *and* provide
some helper function using the api (compared to the one using cli in
`integration-cli/daemon` package).

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit f0d277fe84)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:28 +01:00
Vincent Demeester
29ed6af411 Migrate test-integration-cli experimental macvlan test to integration
All `Macvlan` related test on `DockerSuite` and `DockerNetworkSuite`
are migrated to `macvlan_test.go`.

Also, as `macvlan` seems to be out of experimental, this removes
the *skip* when the run is not experimental (and doesn't start a
daemon with experimental either).

The end goal being to remove the `experimental` builds.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit ef5bc60326)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Dennis Chen
30dd3df96b Network testing with busybox:glibc
Using the `busybox:glibc` instead of `busybox:latest` to the
network related test cases (`ping` issue).

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit 0d31dee5ec)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Dennis Chen
a80a0c0fb3 Add busybox:latest into the frozen images
Adding `busybox:latest` and `busybox:glibc` as the frozen images

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit 3ae45c5f17)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Vincent Demeester
85baafcd37 Skip some tests in certain condition to run with e2e image
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit e55d6fc857)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Arash Deshmeh
1606abcc04 use unique names for resources used by integration tests container/inspect_test, container/ps_test, container/stop_test
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
(cherry picked from commit 78e4be9133)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Vincent Demeester
a4d9a8057d integration/*: make e2e run without failure
… mainly by skipping if daemon is remote.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 6016e79d25)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:27 +01:00
Vincent Demeester
19a50e0ff1 Update e2e script
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 4bb0f24716)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:26 +01:00
Kir Kolyshkin
410ef229e1 integration/TestContainerShmNoLeak: use --iptables=false
As mentioned in commit 9e31938, test cases that use t.Parallel()
and start a docker daemon might step on each other toes as they
try to configure iptables during startup, resulting in flaky tests.

To avoid this, --iptables=false should be used while starting daemon.

Fixes: eaa5192856 ("Make container resource mounts unbindable")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit c125e10a04)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:26 +01:00
Daniel Nephin
ada463fc91 Update testing doc
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 58de627782)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:26 +01:00
Daniel Nephin
1c542223b5 Cleanup pkg/jsonmessage progress tests
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 7d8815ea70)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:26 +01:00
Daniel Nephin
a86457fd08 Post migration assertion fixes
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit c9e52bd0da)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:26 +01:00
Daniel Nephin
c41fd93e23 Automated migration using
gty-migrate-from-testify --ignore-build-tags

Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 6be0f70983)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:25 +01:00
Daniel Nephin
187d6c03fb Update vendor
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 073963e3b7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:25 +01:00
Daniel Nephin
0a5c5b0fb0 Cleanup some assertions
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit ef01dea893)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:25 +01:00
Brian Goff
a2d5fb894d Bump libnetwork commit
Full diff
5c1218c956...c15b372ef2

Fixes a panic on concurrent read/write to a map.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 248aed5766)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:25 +01:00
Akihiro Suda
819f792322 update libnetwork to improve scalabiltiy of bridge network isolation rules
* libnetwork#2121: Retry other external DNS servers on ServFail
* libnetwork#2125: Fix README flag and expose orphan network peers
* libnetwork#2126: Adding goreport card
* libnetwork#2130: Modify awk to use cut in check_ip_overlap
* libnetwork#2117: [Carry 1534] Improve scalabiltiy of bridge network isolation rules

Full changes: 2bf63300c5...5c1218c956

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
(cherry picked from commit b159da1973)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
Chris Telfer
276322ad7c Remove (now) extra call to sb.DisableService()
This call was added as part of commit a042e5a20 and at the time was
useful.  sandbox.DisableService() basically calls
endpoint.deleteServiceInfoFromCluster() for every endpoint in the
sandbox.  However, with the libnetwork change, endpoint.sbLeave()
invokes endpoint.deleteServiceInfoFromCluster(). The releaseNetwork()
call invokes sandbox.Delete() immediately after
sandbox.DisableService().  The sandbox.Delete() in turn ultimately
invokes endpoint.sbLeave() for every endpoint in the sandbox which thus
removes the endpoint's load balancing entry via
endpoint.deleteServiceInfoFromCluster().  So the call to
sandbox.DisableService() is now redundant.

It is noteworthy that, while redundant, the presence of the call would
not cause errors.  It would just be sub-optimal.  The DisableService()
call would cause libnetwork to down-weight the load balancing entries
while the call to sandbox.Delete() would cause it to remove the entries
immediately afterwards.  Aside from the wasted computation, the extra
call would also propagate an extra state change in the networkDB gossip
messages.  So, overall, it is much better to just avoid the extra
overhead.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
(cherry picked from commit c27417aa7d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
Chris Telfer
b91e896939 Import libnetwork fix for rolling updates
This patch allows endpoints to complete servicing connections while
being removed from a service.  The fix is entirely within libnetwork
and requires no changes to the moby codebase proper.  It operates
by initially down-weighting a container endpoint in the load balancer
to 0 while keeping the endpoint present in the load balancer.  This
allows traffic to continue to flow to the endpoint while preventing new
connections from going to the endpoint.  This allows the container
to complete requests during the "stop_grace_period" and then exit when
finished without interruption of service.

This change requires propagating the status of disabled service
endpoints via the networkDB.  Accordingly, the patch includes both code
to generate and handle service update messages.  It also augments the
service structure with a ServiceDisabled boolean to convey whether an
endpoint should ultimately be removed or just disabled.  This,
naturally, required a rebuild of the protocol buffer code.

The protocol buffer encoding is designed to support additions of fields
to messages in a backwards-compatible manner.  Protocol buffer
unmarshalling code automatically skips past any fields that it isn't
aware of.  As a result, an older moby daemon without this fix can
receive and will process correctly networkDB messages from newer moby
daemons with this patch.

As it turns out, the additional field is simply a bool that is otherwise
irrelevent on networkDB create and delete events.  So its absence in
older moby daemon processing has no impact.  However, the fix leverages
the "update" networkDB message which was previously unused in
libnetwork.  Although older libnetwork implementations parse the message
cleanly, they will see the message as unexpected and as such issue a log
at error level indicating the receipt of such.

Other than this there should be no other negative impact for use of this
patch in mixed environments. (Although older mobys won't be able to
gracefully downgrade connections on their nodes of course.)

Signed-off-by: Chris Telfer <ctelfer@docker.com>
(cherry picked from commit 50dbdeff9f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
慕陶
92de621938 fix(distribution): digest cache should not be moved if it was an auth
error

local digest cache will be removed when error occured on push image
but it should not be removed if it is an auth error while on auth was
provided

https://github.com/moby/moby/issues/36309
Signed-off-by: 慕陶 <jihui.xjh@alibaba-inc.com>
(cherry picked from commit 8b387b165a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
Anusha Ragunathan
1f2cae94cc Add missing error return for plugin creation.
Signed-off-by: Anusha Ragunathan <anusha.ragunathan@docker.com>
(cherry picked from commit 89a882e2f1)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
John Howard
58765fee80 Windows: Fix Hyper-V containers regression from 36586
Signed-off-by: John Howard <jhoward@microsoft.com>
(cherry picked from commit 0f5fe3f9cf)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
Kir Kolyshkin
c1d80ca005 integration/TestExportContainerAfterDaemonRestart: add
This test case checks that a container created before start
of the currently running dockerd can be exported (as reported
in #36561). To satisfy this condition, either a pre-existing
container is required, or a daemon restart after container
creation.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 6e7141c7a2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:24 +01:00
Kir Kolyshkin
d8581145e8 container.BaseFS: check for nil before deref
Commit 7a7357dae1 ("LCOW: Implemented support for docker cp + build")
changed `container.BaseFS` from being a string (that could be empty but
can't lead to nil pointer dereference) to containerfs.ContainerFS,
which could be be `nil` and so nil dereference is at least theoretically
possible, which leads to panic (i.e. engine crashes).

Such a panic can be avoided by carefully analysing the source code in all
the places that dereference a variable, to make the variable can't be nil.
Practically, this analisys are impossible as code is constantly
evolving.

Still, we need to avoid panics and crashes. A good way to do so is to
explicitly check that a variable is non-nil, returning an error
otherwise. Even in case such a check looks absolutely redundant,
further changes to the code might make it useful, and having an
extra check is not a big price to pay to avoid a panic.

This commit adds such checks for all the places where it is not obvious
that container.BaseFS is not nil (which in this case means we do not
call daemon.Mount() a few lines earlier).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit d6ea46ceda)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Kir Kolyshkin
e09841e3bd daemon.ContainerExport(): do not panic
In case ContainerExport() is called for an unmounted container, it leads
to a daemon panic as container.BaseFS, which is dereferenced here, is
nil.

To fix, do not rely on container.BaseFS; use the one returned from
rwlayer.Mount().

Fixes: 7a7357dae1 ("LCOW: Implemented support for docker cp + build")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 81f6307eda)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Brian Goff
e0e988afd6 Add some tests to the volume store
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 834d0e262a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Kir Kolyshkin
c6fc9160f8 TestLinksEtcHostsContentMatch: use container.Exec()
I am not quite sure why but this test is sometimes failing like this:

> 15:21:41 --- FAIL: TestLinksEtcHostsContentMatch (0.53s)
> 15:21:41 	assertions.go:226:
>
> 	Error Trace:	links_linux_test.go:46
> 15:21:41
> 	Error:      	Not equal:
> 15:21:41
> 	            	expected: "127.0.0.1\tlocalhost\n::1\tlocalhost
> ip6-localhost
> ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\n172.17.0.2\tf53feb6df161\n"
> 15:21:41
> 	            	received: ""

To eliminate some possible failures (like ignoring stderr from `cat` or
its exit code), let's use container.Exec() to read a file from a container.

Fixes: e6bd20edcb ("Migrate some integration-cli test to api tests")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit ad2f88d8cc)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Daniel Nephin
c8293365c8 Remove unnecessary diff tests
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 038f3add51)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Sebastiaan van Stijn
1666d8e917 Remove duplicate TestServiceUpdatePort
The TestAPIServiceUpdatePort test performs exactly
the same steps.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 36e1646e4f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Brian Goff
26fb91afed Adds a unit test for plugin request timeout
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 7ca971fb49)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Yong Tang
3881020096 Address expected vs actual in integration tests
This fix addresses `expected` vs `actual` in integration tests
so that they match `assert.Equal(t, expected, actual)`

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 8a854e933b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Yong Tang
e477c3b311 Remove unnecessary container.WithName in kill test
This fix removes several unnecessary `container.WithName`
usage in docker kill integration test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 1778719d6a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Yong Tang
c444c69278 Migrate docker rm tests to api tests
This fix migrates docker rm test in integration-cli
to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit ed58ba99fb)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:23 +01:00
Yong Tang
54625971f8 Improvement in integration tests
This fix adds several improvement:
1. No need for explicit ContainerRemove as it has been handled in setupTest()
2. Added `container.WithImage` helper function and used it in commit tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 6ab465804b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Vincent Demeester
e385bd3cf0 Fixes some integration/container test to run on remote daemon
```
docker build -f Dockerfile.e2e -t moby-e2e .
docker run -v /var/run/docker.sock:/var/run/docker.sock \
           -e TEST_INTEGRATION_DIR=/tests/integration/container \
           -e DOCKER_API_VERSION=1.36 moby-e2e
```

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 18dd1d9aba)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Yong Tang
a0a0951153 Migrate export tests to api tests
This fix migrates export tests in integration-cli to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 4e702cf70d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Sebastiaan van Stijn
f5ab52a7a9 Fix "expected" and "actual" being reversed
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a2517cbf62)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Yong Tang
2ca48b4ae4 Enhancement of replacing ContainerCreate with helper funcs in tests
This fix is a minor enhancement to replace several ContainerCreate with
helper funcs of `container.Create` in tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 6ad4720c78)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Yong Tang
3b15c04042 Remove docker_cli_secret_inspect_test.go
as the test (TestSecretInspectMultiple) seems to have been covered pretty well in cli:
https://github.com/docker/cli/blob/master/cli/command/secret/inspect_test.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 3d38adb20c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Yong Tang
fe3da58ea4 Migrate events tests to api tests
This fix migrates events tests in integration-cli to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 3a749157d2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
Yong Tang
51603e1335 Migrate config inspect test to api test
This fix migrates config inspect test in integration-cli
to api test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 4b99d78207)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:22 +01:00
mnussbaum
8224054799 Clean-up after container unit test
Remove temp directories and close file loggers in container unit tests.

Signed-off-by: mnussbaum <michael.nussbaum@getbraintree.com>
(cherry picked from commit 07d5446fe2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
junzhe and mnussbaum
a5f94a4d78 Fix empty LogPath with non-blocking logging mode
This fixes an issue where the container LogPath was empty when the
non-blocking logging mode was enabled. This change sets the LogPath on
the container as soon as the path is generated, instead of setting the
LogPath on a logger struct and then attempting to pull it off that
logger at a later point. That attempt to pull the LogPath off the logger
was error prone since it assumed that the logger would only ever be a
single type.

Prior to this change docker inspect returned an empty string for
LogPath. This caused issues with tools that rely on docker inspect
output to discover container logs, e.g. Kubernetes.

This commit also removes some LogPath methods that are now unnecessary
and are never invoked.

Signed-off-by: junzhe and mnussbaum <code@getbraintree.com>
(cherry picked from commit 20ca612a59)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Yong Tang
6d5f418116 Migrate some config secret tests to api test
This fix migrates some secret create tests to api tests,
and remove redundant TestConfigCreate.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 99e2818850)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Yong Tang
a42e8b93b6 Move containerIsStopped/containerIsInState to integration/internal/container
This fix moves helper functions containerIsStopped and
containerIsInState to integration/internal/container,
so that they could be used outside of integration/container.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit eda311c18f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Dennis Chen
240cb224a5 Clean the teardown process of network test
We need to clean the resources created in some test cases, else
in some cases we'll get below error for other tests:

> FAIL: docker_experimental_network_test.go:37: DockerNetworkSuite.TestDockerNetworkMacvlanPersistance
>  docker_experimental_network_test.go:44:
> ...
> Command:  ip link add dm-dummy0 type dummy
> ExitCode: 2
> Error:    exit status 2
> Stdout:
> Stderr:   RTNETLINK answers: File exists
> ...

Logically, each test case should be independent, the failure of previous
test case should not have side-effect for the test cases followed.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
(cherry picked from commit 57d85e7e54)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Yong Tang
84c0cd331b Update docker-py
This fix update docker-py so that containers from the tests run
could be cleaned up during teardown:
```diff
-ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
+ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
```

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 66935a0f64)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Yong Tang
ba88a29514 Migrate several docker rm tests to api tests
This fix migrates several docker rm tests to api tests

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 6bd4f4801b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Yong Tang
1ec5530cd4 Migrate volumes tests in integration-cli to api tests
This fix migrates volumes tests in integration-cli to api tests
in integration/

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit d896f87c05)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Stephen J Day
b3b4787dfd daemon/cluster: handle partial attachment entries during configure
We have seen a panic when re-joining a node to a swarm cluster. The
cause of the issue is unknown, so we just need to add a test for nil
objects and log when we get the condition. Hopefully this can prevent
the crash and we can recover the config at a later time.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
(cherry picked from commit 454128c6e8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:21 +01:00
Sebastiaan van Stijn
fdfa6f9ad2 Bump other Dockerfiles to Go 1.9.5
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Sebastiaan van Stijn
d33d5100e0 Update Golang to 1.9.5
go1.9.5 (released 2018/03/28) includes fixes to the compiler, go
command, and net/http/pprof package. See the Go 1.9.5 milestone on
the issue tracker for details:

https://github.com/golang/go/issues?q=milestone%3AGo1.9.5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 0b6f8a7eff)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Sebastiaan van Stijn
a03d87f0dc Fix stats collector spinning CPU if no stats are collected
Commit fd0e24b718 changed
the stats collection loop to use a `sleep()` instead
of `time.Tick()` in the for-loop.

This change caused a regression in situations where
no stats are being collected, or an error is hit
in the loop (in which case the loop would `continue`,
and the `sleep()` is not hit).

This patch puts the sleep at the start of the loop
to guarantee it's always hit.

This will delay the sampling, which is similar to the
behavior before fd0e24b718.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 481b8e54b4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Stephen J Day
61e39588a8 daemon/stats: more resilient cpu sampling
To avoid noise in sampling CPU usage metrics, we now sample the system
usage closer to the actual response from the underlying runtime. Because
the response from the runtime may be delayed, this makes the sampling
more resilient in loaded conditions. In addition to this, we also
replace the tick with a sleep to avoid situations where ticks can backup
under loaded conditions.

The trade off here is slightly more load reading the system CPU usage
for each container. There may be an optimization required for large
amounts of containers but the cost is on the order of 15 ms per 1000
containers. If this becomes a problem, we can time slot the sampling,
but the complexity may not be worth it unless we can test further.

Unfortunately, there aren't really any good tests for this condition.
Triggering this behavior is highly system dependent. As a matter of
course, we should qualify the fix with the users that are affected.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
(cherry picked from commit fd0e24b718)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Stephen J Day
3df2c022ac containerd: update to 1.0.3 release
Signed-off-by: Stephen J Day <stephen.day@docker.com>
(cherry picked from commit 554d657c1f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Sebastiaan van Stijn
055dc953e3 Fix AppArmor not being applied to Exec processes
Exec processes do not automatically inherit AppArmor
profiles from the container.

This patch sets the AppArmor profile for the exec
process.

Before this change:

    apparmor_parser -q -r <<EOF
    #include <tunables/global>
    profile deny-write flags=(attach_disconnected) {
      #include <abstractions/base>
      file,
      network,
      deny /tmp/** w,
      capability,
    }
    EOF

    docker run -dit --security-opt "apparmor=deny-write" --name aa busybox

    docker exec aa sh -c 'mkdir /tmp/test'
    (no error)

With this change applied:

    docker exec aa sh -c 'mkdir /tmp/test'
    mkdir: can't create directory '/tmp/test': Permission denied

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8f3308ae10)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Kir Kolyshkin
840a743fb3 Test for systemd cgroupdriver memory setting
This is a test case for issue https://github.com/moby/moby/issues/35123,
making sure we can set container's memory limit when using
`native.cgroupdriver=systemd`.

[v2: skip if no systemd present]
[v3: add --iptables=false to avoid flaky tests with t.Parallel()]
[v4: rebase after PR#36507 merge]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 4ca5c53610)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:20 +01:00
Brian Goff
560682a2d3 Don't sort plugin mounts slice
This was added as part of a53930a04f with
the intent to sort the mounts in the plugin config, but this was sorting
*all* the mounts from the default OCI spec which is problematic.

In reality we don't need to sort this because we are only adding a
self-binded mount to flag it as rshared.

We may want to look at sorting the plugin mounts before they are added
to the OCI spec in the future, but for now I think the existing behavior
is fine since the plugin author has control of the order (except for the
propagated mount).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit ec90839ca3)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-03-23 10:09:19 +01:00
Darren Stahl
230da9c20d Fix Windows layer leak when write fails
Signed-off-by: Darren Stahl <darst@microsoft.com>
(cherry picked from commit 1f28844d78)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Vincent Demeester
a390fb3030 Migrate DockerTrustSuite to docker/cli e2e tests
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 5433ceb12e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Sebastiaan van Stijn
e7007a958e Revert "update integration-cli tests for stderr output"
This reverts commit d5f8753b884085b96d9d828771ba23adf7d6700a.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Sebastiaan van Stijn
451fa9a644 Revert "Blacklist tests, will be rewritten later on"
This reverts commit a720337d2e359f9215422b47c9ef66421d582f24.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Sebastiaan van Stijn
56c18c6d94 Update libnetwork to fix stale HNS endpoints on Windows
Update libnetwork to 1b91bc94094ecfdae41daa465cc0c8df37dfb3dd to bring in a fix
for stale HNS endpoints on Windows:

When Windows Server 2016 is restarted with the Docker service running, it is
possible for endpoints to be deleted from the libnetwork store without being
deleted from HNS. This does not occur if the Docker service is stopped cleanly
first, or forcibly terminated (since the endpoints still exist in both). This
change works around the issue by removing any stale HNS endpoints for a network
when creating it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit fb364f0746)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:19 +01:00
Sebastiaan van Stijn
9cfa94b327 Update libnetwork with fixes for duplicate IP addresses
This updates libnetwork to 8892d7537c67232591f1f3af60587e3e77e61d41 to bring in
IPAM fixes for duplicate IP addresses.

- IPAM tests (libnetwork PR 2104) (no changes in vendored files)
- Fix for Duplicate IP issues  (libnetwork PR 2105)

Also bump golang/x/sync to match libnetwork (no code-changes, other
than the README being updated)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 55e0fe24db)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Kir Kolyshkin
172d8cfb0f daemon/oci_linux_test: add TestIpcPrivateVsReadonly
The test case checks that in case of IpcMode: private and
ReadonlyRootfs: true (as in "docker run --ipc private --read-only")
the resulting /dev/shm mount is NOT made read-only.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 33dd562e3a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:19 +01:00
Kir Kolyshkin
bde862d11e daemon/setMounts(): do not make /dev/shm ro
It has been pointed out that if --read-only flag is given, /dev/shm
also becomes read-only in case of --ipc private.

This happens because in this case the mount comes from OCI spec
(since commit 7120976d74), and is a regression caused by that
commit.

The meaning of --read-only flag is to only have a "main" container
filesystem read-only, not the auxiliary stuff (that includes /dev/shm,
other mounts and volumes, --tmpfs, /proc, /dev and so on).

So, let's make sure /dev/shm that comes from OCI spec is not made
read-only.

Fixes: 7120976d74 ("Implement none, private, and shareable ipc modes")

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit cad74056c0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Chris Telfer
49d487808f Update vendoring for libnetwork PR #2097
This PR prevents automatic removal of the load balancing sandbox
endpoint when the endpoint is the last one in the network but
the network is marked as ingress.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
(cherry picked from commit bebad150c9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Chris Telfer
dba33b041a Delete the load balancer endpoint in Ingress nets
Ingress networks will no longer automatically remove their
load-balancing endpoint (and sandbox) automatically when the network is
otherwise upopulated.   This is to prevent automatic removal of the
ingress networks when all the containers leave them.  Therefore
explicit removal of an ingress network also requires explicit removal
of its load-balancing endpoint.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
(cherry picked from commit 3da4ebf355)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Chris Telfer
3db5356b58 Add test for ingress removal on service removal
The commit https://github.com/moby/moby/pull/35422 had the result of
accidentally causing the removal of the ingress network when the
last member of a service left the network.  This did not appear
in swarm instances because the swarm manager would still maintain
and return cluster state about the network even though it had
removed its sandbox and endpoint.  This test verifies that after a
service gets added and removed that the ingress sandbox remains
in a functional state.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
(cherry picked from commit 805b6a7f74)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Christopher Jones
f833d6ccb1 [integration] skip ppc64le oom tests for now
These tests were enabled by changing a config option on the ci
machines, instead of from a patch, so let me disable them
for now on ppc64le and open up another patch to enable them, where I can find
out what the issues are with them.

Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
(cherry picked from commit 620ddc78a1)
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2020-03-23 10:09:18 +01:00
Eli Uriegas
b8ae001c8f buildmod => buildmode
There was a typo with the buildmode flag for containerd

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
(cherry picked from commit 5e4885b9af)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Eli Uriegas
9c23db048a Build containerd, runc, and proxy statically
These were originally static binaries in the first place, this changes
them back to that.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
(cherry picked from commit 63c7bb2463)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
Sebastiaan van Stijn
cc19775363 Engine: bump swarmkit to 11d7b06f48bc1d73fc6d8776c3552a4b11c94301
Ingress network should not be attachable

Ingress network is a special network used only to expose
ports. For this reason the network cannot be explicitly
attached during service create or service update

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:18 +01:00
selansen
aa334bf751 Fix to address regression caused by PR 30897
With the inclusion of PR 30897, creating service for host network
    fails in 18.02. Modified IsPreDefinedNetwork check and return
    NetworkNameError instead of errdefs.Forbidden to address this issue

Signed-off-by: selansen <elango.siva@docker.com>
(cherry picked from commit 7cf8b20762)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:17 +01:00
Andrew Hsu
22482c7de4 engine: vndr swarmkit 49a9d7f
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:17 +01:00
Tonis Tiigi
99e9effcaf builder: fix layer lifecycle leak
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 7ad41d53df)
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-03-23 10:09:17 +01:00
Sebastiaan van Stijn
c76f748e62 bump containerd/console to 2748ece16665b45a47f884001d5831ec79703880
Fix runc exec on big-endian, causing:

    container_linux.go:265: starting container process caused "open /dev/pts/4294967296: no such file or directory"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit aab5eaddcc)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:17 +01:00
Sebastiaan van Stijn
120ae64d02 Bump Runc to 1.0.0-rc5 / 4fc53a81fb7c994640722ac585fa9ca548971871
Release notes: https://github.com/opencontainers/runc/releases/tag/v1.0.0-rc5

Possibly relevant changes included:

- chroot when no mount namespaces is provided
- fix systemd slice expansion so that it could be consumed by cAdvisor
- libcontainer/capabilities_linux: Drop os.Getpid() call
- Update console dependency to fix runc exec on BE (causing: `container_linux.go:265: starting container process caused "open /dev/pts/4294967296: no such file or directory"`)
- libcontainer: setupUserNamespace is always called (fixes: Devices are mounted with wrong uid/gid)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a2f5a1a5b2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:17 +01:00
Brian Goff
8232dc173d Split binary installers/commit scripts
Originally I worked on this for the multi-stage build Dockerfile
changes. Decided to split this out as we are still waiting for
multi-stage to be available on CI and rebasing these is pretty annoying.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit b529d1b093)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:17 +01:00
Daniel Nephin
8bdf5fc525 Migrate some copy tests to integration
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 00d409f03e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-23 10:09:17 +01:00
Vincent Demeester
385a42156c Clean some docker_cli_build_tests that are cli-only
Remove TestBuildRenamedDockerfile and TestBuildDockerfileOutsideContext
that are cli-only tests (and already tested in the docker/cli
repository).

Also adds some comments on few tests that could be migrate to
docker/cli.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 894c213b3b)
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2020-03-23 10:09:17 +01:00
Riyaz Faizullabhoy
b61d45bb41 update integration-cli tests for stderr output
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
(cherry picked from commit 250b84ee8820d5ac28f223ef3affdffeff7ee026)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit d256539bf422fe6dc84c720c9153823c05396a3e)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit 5742bd3ccf41601e363cd0bc8d8e45cd54973eed)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit 1a2098cecfcdf93f3d8b8e203ffb6480973b172f)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:16 +01:00
Eli Uriegas
766fcb992c Blacklist tests, will be rewritten later on
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
(cherry picked from commit 4e81e4fa4edce70d1ce4e96c2181fcdfb88241bb)
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
(cherry picked from commit ec6b0a1a4a2e0d48f7338080f76b47fc3b022c74)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit fbfecebc0a5a2c75212b2c2d2b53a00255ce479e)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit e3571070d5502ac07e6c8a56867e21b2cfa3ae07)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit 9d7b9c23f54a082b1aa2f1206473adc1a266fb0a)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:16 +01:00
Daniel Nephin
27c443f09c Fix TestAttachAfterDetach to work with latest client
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 847b610620)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2020-03-23 10:09:16 +01:00
513 changed files with 12373 additions and 14604 deletions

View File

@@ -97,7 +97,7 @@ RUN apt-get update && apt-get install -y \
# will need updating, to avoid errors. Ping #docker-maintainers on IRC
# with a heads-up.
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
| tar -xzC /usr/local
@@ -142,7 +142,7 @@ RUN set -x \
&& rm -rf "$GOPATH"
# Get the "docker-py" source so we can run their integration tests
ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
# To run integration tests docker-pycreds is required.
RUN git clone https://github.com/docker/docker-py.git /docker-py \
&& cd /docker-py \
@@ -182,16 +182,18 @@ RUN echo "source $PWD/hack/make/.integration-test-helpers" >> /etc/bash.bashrc
COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
# Install tomlv, vndr, runc, containerd, tini, docker-proxy dockercli
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
# Install tomlv, vndr, runc, containerd, tini, proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in tomlv vndr tini gometalinter proxy dockercli runc containerd; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
# Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH

View File

@@ -74,7 +74,7 @@ RUN apt-get update && apt-get install -y \
# Install Go
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz" \
| tar -xzC /usr/local
@@ -106,7 +106,7 @@ RUN set -x \
&& rm -rf "$GOPATH"
# Get the "docker-py" source so we can run their integration tests
ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
# To run integration tests docker-pycreds is required.
RUN git clone https://github.com/docker/docker-py.git /docker-py \
&& cd /docker-py \
@@ -147,18 +147,22 @@ RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker
COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
#
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
# Install tomlv, vndr, runc, containerd, tini, proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in tomlv vndr tini gometalinter proxy dockercli runc containerd; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
# Wrap all commands in the "docker-in-docker" script to allow nested containers
ENTRYPOINT ["hack/dind"]

View File

@@ -64,7 +64,7 @@ RUN apt-get update && apt-get install -y \
# Install Go
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" \
| tar -xzC /usr/local
ENV PATH /go/bin:/usr/local/go/bin:$PATH
@@ -104,7 +104,7 @@ RUN set -x \
&& rm -rf "$GOPATH"
# Get the "docker-py" source so we can run their integration tests
ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
# To run integration tests docker-pycreds is required.
RUN git clone https://github.com/docker/docker-py.git /docker-py \
&& cd /docker-py \
@@ -133,16 +133,18 @@ RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker
COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
# Install tomlv, vndr, runc, containerd, tini, proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in tomlv vndr tini gometalinter proxy dockercli runc containerd; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
ENTRYPOINT ["hack/dind"]

View File

@@ -1,5 +1,5 @@
## Step 1: Build tests
FROM golang:1.9.4-alpine3.6 as builder
FROM golang:1.9.5-alpine3.6 as builder
RUN apk add --update \
bash \
@@ -17,13 +17,14 @@ WORKDIR /go/src/github.com/docker/docker/
COPY contrib/download-frozen-image-v2.sh contrib/download-frozen-image-v2.sh
RUN contrib/download-frozen-image-v2.sh /output/docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# Download Docker CLI binary
COPY hack/dockerfile hack/dockerfile
RUN hack/dockerfile/install-binaries.sh dockercli
RUN hack/dockerfile/install.sh dockercli
# Set tag and add sources
ARG DOCKER_GITCOMMIT

View File

@@ -65,7 +65,7 @@ RUN apt-get update && apt-get install -y \
# Install Go
# NOTE: official ppc64le go binaries weren't available until go 1.6.4 and 1.7.4
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \
| tar -xzC /usr/local
@@ -102,7 +102,7 @@ RUN set -x \
&& rm -rf "$GOPATH"
# Get the "docker-py" source so we can run their integration tests
ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
# To run integration tests docker-pycreds is required.
RUN git clone https://github.com/docker/docker-py.git /docker-py \
&& cd /docker-py \
@@ -131,16 +131,18 @@ RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker
COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
# Install tomlv, vndr, runc, containerd, tini, proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in tomlv vndr tini gometalinter proxy dockercli runc containerd; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
# Wrap all commands in the "docker-in-docker" script to allow nested containers

View File

@@ -59,7 +59,7 @@ RUN apt-get update && apt-get install -y \
--no-install-recommends
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \
| tar -xzC /usr/local
@@ -96,7 +96,7 @@ RUN set -x \
&& rm -rf "$GOPATH"
# Get the "docker-py" source so we can run their integration tests
ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
# To run integration tests docker-pycreds is required.
RUN git clone https://github.com/docker/docker-py.git /docker-py \
&& cd /docker-py \
@@ -125,16 +125,18 @@ RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker
COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:1.27-glibc@sha256:8c8f261a462eead45ab8e610d3e8f7a1e4fd1cd9bed5bc0a0c386784ab105d8e \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
# Install tomlv, vndr, runc, containerd, tini, proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in tomlv vndr tini gometalinter proxy dockercli runc containerd; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
# Wrap all commands in the "docker-in-docker" script to allow nested containers

View File

@@ -42,7 +42,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# will need updating, to avoid errors. Ping #docker-maintainers on IRC
# with a heads-up.
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
| tar -xzC /usr/local
ENV PATH /go/bin:/usr/local/go/bin:$PATH
@@ -50,10 +50,11 @@ ENV GOPATH /go
ENV CGO_LDFLAGS -L/lib
# Install runc, containerd, tini and docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh runc containerd tini proxy dockercli
# Please edit hack/dockerfile/install/<name>.installer to update them.
COPY hack/dockerfile/install hack/dockerfile/install
RUN for i in runc containerd tini proxy dockercli; \
do hack/dockerfile/install/install.sh $i; \
done
ENV PATH=/usr/local/cli:$PATH
ENV AUTO_GOPATH 1

View File

@@ -161,7 +161,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref
# Environment variable notes:
# - GO_VERSION must be consistent with 'Dockerfile' used by Linux.
# - FROM_DOCKERFILE is used for detection of building within a container.
ENV GO_VERSION=1.9.4 `
ENV GO_VERSION=1.9.5 `
GIT_VERSION=2.11.1 `
GOPATH=C:\go `
FROM_DOCKERFILE=1

View File

@@ -8,11 +8,11 @@ questions you may have as an aspiring Moby contributor.
Moby has two test suites (and one legacy test suite):
* Unit tests - use standard `go test` and
[testify](https://github.com/stretchr/testify) assertions. They are located in
[gotestyourself/assert](https://godoc.org/github.com/gotestyourself/gotestyourself/assert) assertions. They are located in
the package they test. Unit tests should be fast and test only their own
package.
* API integration tests - use standard `go test` and
[testify](https://github.com/stretchr/testify) assertions. They are located in
[gotestyourself/assert](https://godoc.org/github.com/gotestyourself/gotestyourself/assert) assertions. They are located in
`./integration/<component>` directories, where `component` is: container,
image, volume, etc. These tests perform HTTP requests to an API endpoint and
check the HTTP response and daemon state after the call.

View File

@@ -3,7 +3,8 @@ package middleware // import "github.com/docker/docker/api/server/middleware"
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestMaskSecretKeys(t *testing.T) {
@@ -53,6 +54,6 @@ func TestMaskSecretKeys(t *testing.T) {
for _, testcase := range tests {
maskSecretKeys(testcase.input, testcase.path)
assert.Equal(t, testcase.expected, testcase.input)
assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
}
}

View File

@@ -7,7 +7,8 @@ import (
"testing"
"github.com/docker/docker/api/server/httputils"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -17,7 +18,7 @@ func TestVersionMiddlewareVersion(t *testing.T) {
expectedVersion := defaultVersion
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
v := httputils.VersionFromContext(ctx)
assert.Equal(t, expectedVersion, v)
assert.Check(t, is.Equal(expectedVersion, v))
return nil
}
@@ -56,9 +57,9 @@ func TestVersionMiddlewareVersion(t *testing.T) {
err := h(ctx, resp, req, map[string]string{"version": test.reqVersion})
if test.errString != "" {
assert.EqualError(t, err, test.errString)
assert.Check(t, is.Error(err, test.errString))
} else {
assert.NoError(t, err)
assert.Check(t, err)
}
}
}
@@ -66,7 +67,7 @@ func TestVersionMiddlewareVersion(t *testing.T) {
func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
v := httputils.VersionFromContext(ctx)
assert.NotEmpty(t, v)
assert.Check(t, len(v) != 0)
return nil
}
@@ -81,11 +82,11 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
vars := map[string]string{"version": "0.1"}
err := h(ctx, resp, req, vars)
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
hdr := resp.Result().Header
assert.Contains(t, hdr.Get("Server"), "Docker/"+defaultVersion)
assert.Contains(t, hdr.Get("Server"), runtime.GOOS)
assert.Equal(t, hdr.Get("API-Version"), defaultVersion)
assert.Equal(t, hdr.Get("OSType"), runtime.GOOS)
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/"+defaultVersion))
assert.Check(t, is.Contains(hdr.Get("Server"), runtime.GOOS))
assert.Check(t, is.Equal(hdr.Get("API-Version"), defaultVersion))
assert.Check(t, is.Equal(hdr.Get("OSType"), runtime.GOOS))
}

View File

@@ -4,8 +4,8 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestParseArgs(t *testing.T) {
@@ -22,10 +22,10 @@ func TestParseArgs(t *testing.T) {
for i := range flagArgs {
args, err = ParseFlag(flagArgs[i], args)
require.NoError(t, err)
assert.NilError(t, err)
}
assert.Len(t, args.Get("created"), 1)
assert.Len(t, args.Get("image.name"), 2)
assert.Check(t, is.Len(args.Get("created"), 1))
assert.Check(t, is.Len(args.Get("image.name"), 2))
}
func TestParseArgsEdgeCase(t *testing.T) {
@@ -231,7 +231,7 @@ func TestArgsMatch(t *testing.T) {
}
for args, field := range matches {
assert.True(t, args.Match(field, source),
assert.Check(t, args.Match(field, source),
"Expected field %s to match %s", field, source)
}
@@ -255,8 +255,7 @@ func TestArgsMatch(t *testing.T) {
}
for args, field := range differs {
assert.False(t, args.Match(field, source),
"Expected field %s to not match %s", field, source)
assert.Check(t, !args.Match(field, source), "Expected field %s to not match %s", field, source)
}
}

View File

@@ -53,7 +53,7 @@ type Backend interface {
// ImageBackend are the interface methods required from an image component
type ImageBackend interface {
GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ReleaseableLayer, error)
GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ROLayer, error)
}
// ExecBackend contains the interface methods required for executing containers
@@ -100,10 +100,16 @@ type Image interface {
OperatingSystem() string
}
// ReleaseableLayer is an image layer that can be mounted and released
type ReleaseableLayer interface {
// ROLayer is a reference to image rootfs layer
type ROLayer interface {
Release() error
Mount() (containerfs.ContainerFS, error)
Commit() (ReleaseableLayer, error)
NewRWLayer() (RWLayer, error)
DiffID() layer.DiffID
}
// RWLayer is active layer that can be read/modified
type RWLayer interface {
Release() error
Root() containerfs.ContainerFS
Commit() (ROLayer, error)
}

View File

@@ -2,9 +2,11 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import (
"bytes"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func strPtr(source string) *string {
@@ -39,7 +41,7 @@ func TestGetAllAllowed(t *testing.T) {
"ArgFromMeta": "frommeta1",
"ArgFromMetaOverridden": "fromdockerfile3",
}
assert.Equal(t, expected, all)
assert.Check(t, is.DeepEqual(expected, all))
}
func TestGetAllMeta(t *testing.T) {
@@ -61,7 +63,7 @@ func TestGetAllMeta(t *testing.T) {
"ArgOverriddenByOptions": "fromopt2",
"ArgNoDefaultInMetaFromOptions": "fromopt3",
}
assert.Equal(t, expected, all)
assert.Check(t, is.DeepEqual(expected, all))
}
func TestWarnOnUnusedBuildArgs(t *testing.T) {
@@ -77,10 +79,10 @@ func TestWarnOnUnusedBuildArgs(t *testing.T) {
buffer := new(bytes.Buffer)
buildArgs.WarnOnUnusedBuildArgs(buffer)
out := buffer.String()
assert.NotContains(t, out, "ThisArgIsUsed")
assert.NotContains(t, out, "HTTPS_PROXY")
assert.NotContains(t, out, "HTTP_PROXY")
assert.Contains(t, out, "ThisArgIsNotUsed")
assert.Assert(t, !strings.Contains(out, "ThisArgIsUsed"), out)
assert.Assert(t, !strings.Contains(out, "HTTPS_PROXY"), out)
assert.Assert(t, !strings.Contains(out, "HTTP_PROXY"), out)
assert.Check(t, is.Contains(out, "ThisArgIsNotUsed"))
}
func TestIsUnreferencedBuiltin(t *testing.T) {
@@ -93,8 +95,8 @@ func TestIsUnreferencedBuiltin(t *testing.T) {
buildArgs.AddArg("ThisArgIsUsed", nil)
buildArgs.AddArg("HTTPS_PROXY", nil)
assert.True(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsUsed"))
assert.True(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsNotUsed"))
assert.True(t, buildArgs.IsReferencedOrNotBuiltin("HTTPS_PROXY"))
assert.False(t, buildArgs.IsReferencedOrNotBuiltin("HTTP_PROXY"))
assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsUsed"))
assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsNotUsed"))
assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("HTTPS_PROXY"))
assert.Check(t, !buildArgs.IsReferencedOrNotBuiltin("HTTP_PROXY"))
}

View File

@@ -5,13 +5,14 @@ import (
"testing"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestAddNodesForLabelOption(t *testing.T) {
dockerfile := "FROM scratch"
result, err := parser.Parse(strings.NewReader(dockerfile))
assert.NoError(t, err)
assert.Check(t, err)
labels := map[string]string{
"org.e": "cli-e",
@@ -27,8 +28,8 @@ func TestAddNodesForLabelOption(t *testing.T) {
"FROM scratch",
`LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`,
}
assert.Len(t, nodes.Children, 2)
assert.Check(t, is.Len(nodes.Children, 2))
for i, v := range nodes.Children {
assert.Equal(t, expected[i], v.Original)
assert.Check(t, is.Equal(expected[i], v.Original))
}
}

View File

@@ -72,8 +72,12 @@ type copier struct {
source builder.Source
pathCache pathCache
download sourceDownloader
tmpPaths []string
platform string
// for cleanup. TODO: having copier.cleanup() is error prone and hard to
// follow. Code calling performCopy should manage the lifecycle of its params.
// Copier should take override source as input, not imageMount.
activeLayer builder.RWLayer
tmpPaths []string
}
func copierFromDispatchRequest(req dispatchRequest, download sourceDownloader, imageSource *imageMount) copier {
@@ -155,6 +159,10 @@ func (o *copier) Cleanup() {
os.RemoveAll(path)
}
o.tmpPaths = []string{}
if o.activeLayer != nil {
o.activeLayer.Release()
o.activeLayer = nil
}
}
// TODO: allowWildcards can probably be removed by refactoring this function further.
@@ -166,9 +174,15 @@ func (o *copier) calcCopyInfo(origPath string, allowWildcards bool) ([]copyInfo,
// done on image Source?
if imageSource != nil {
var err error
o.source, err = imageSource.Source()
rwLayer, err := imageSource.NewRWLayer()
if err != nil {
return nil, errors.Wrapf(err, "failed to copy from %s", imageSource.ImageID())
return nil, err
}
o.activeLayer = rwLayer
o.source, err = remotecontext.NewLazySource(rwLayer.Root())
if err != nil {
return nil, errors.Wrapf(err, "failed to create context for copy from %s", rwLayer.Root().Path())
}
}

View File

@@ -5,8 +5,9 @@ import (
"testing"
"github.com/docker/docker/pkg/containerfs"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
)
func TestIsExistingDirectory(t *testing.T) {
@@ -39,10 +40,10 @@ func TestIsExistingDirectory(t *testing.T) {
for _, testcase := range testcases {
result, err := isExistingDirectory(&copyEndpoint{driver: containerfs.NewLocalDriver(), path: testcase.path})
if !assert.NoError(t, err) {
if !assert.Check(t, err) {
continue
}
assert.Equal(t, testcase.expected, result, testcase.doc)
assert.Check(t, is.Equal(testcase.expected, result), testcase.doc)
}
}
@@ -142,6 +143,6 @@ func TestGetFilenameForDownload(t *testing.T) {
resp.Header.Add("Content-Disposition", testcase.disposition)
}
filename := getFilenameForDownload(testcase.path, &resp)
assert.Equal(t, testcase.expected, filename)
assert.Check(t, is.Equal(testcase.expected, filename))
}
}

View File

@@ -16,8 +16,8 @@ import (
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/system"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func newBuilderWithMockBackend() *Builder {
@@ -49,13 +49,13 @@ func TestEnv2Variables(t *testing.T) {
},
}
err := dispatch(sb, envCommand)
require.NoError(t, err)
assert.NilError(t, err)
expected := []string{
"var1=val1",
"var2=val2",
}
assert.Equal(t, expected, sb.state.runConfig.Env)
assert.Check(t, is.DeepEqual(expected, sb.state.runConfig.Env))
}
func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
@@ -68,12 +68,12 @@ func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
},
}
err := dispatch(sb, envCommand)
require.NoError(t, err)
assert.NilError(t, err)
expected := []string{
"var1=val1",
"var2=fromenv",
}
assert.Equal(t, expected, sb.state.runConfig.Env)
assert.Check(t, is.DeepEqual(expected, sb.state.runConfig.Env))
}
func TestMaintainer(t *testing.T) {
@@ -82,8 +82,8 @@ func TestMaintainer(t *testing.T) {
sb := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), newStagesBuildResults())
cmd := &instructions.MaintainerCommand{Maintainer: maintainerEntry}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.Equal(t, maintainerEntry, sb.state.maintainer)
assert.NilError(t, err)
assert.Check(t, is.Equal(maintainerEntry, sb.state.maintainer))
}
func TestLabel(t *testing.T) {
@@ -98,10 +98,10 @@ func TestLabel(t *testing.T) {
},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
require.Contains(t, sb.state.runConfig.Labels, labelName)
assert.Equal(t, sb.state.runConfig.Labels[labelName], labelValue)
assert.Assert(t, is.Contains(sb.state.runConfig.Labels, labelName))
assert.Check(t, is.Equal(sb.state.runConfig.Labels[labelName], labelValue))
}
func TestFromScratch(t *testing.T) {
@@ -113,22 +113,22 @@ func TestFromScratch(t *testing.T) {
err := initializeStage(sb, cmd)
if runtime.GOOS == "windows" && !system.LCOWSupported() {
assert.EqualError(t, err, "Windows does not support FROM scratch")
assert.Check(t, is.Error(err, "Windows does not support FROM scratch"))
return
}
require.NoError(t, err)
assert.True(t, sb.state.hasFromImage())
assert.Equal(t, "", sb.state.imageID)
assert.NilError(t, err)
assert.Check(t, sb.state.hasFromImage())
assert.Check(t, is.Equal("", sb.state.imageID))
expected := "PATH=" + system.DefaultPathEnv(runtime.GOOS)
assert.Equal(t, []string{expected}, sb.state.runConfig.Env)
assert.Check(t, is.DeepEqual([]string{expected}, sb.state.runConfig.Env))
}
func TestFromWithArg(t *testing.T) {
tag, expected := ":sometag", "expectedthisid"
getImage := func(name string) (builder.Image, builder.ReleaseableLayer, error) {
assert.Equal(t, "alpine"+tag, name)
getImage := func(name string) (builder.Image, builder.ROLayer, error) {
assert.Check(t, is.Equal("alpine"+tag, name))
return &mockImage{id: "expectedthisid"}, nil, nil
}
b := newBuilderWithMockBackend()
@@ -146,21 +146,21 @@ func TestFromWithArg(t *testing.T) {
err := processMetaArg(metaArg, shell.NewLex('\\'), args)
sb := newDispatchRequest(b, '\\', nil, args, newStagesBuildResults())
require.NoError(t, err)
assert.NilError(t, err)
err = initializeStage(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, expected, sb.state.imageID)
assert.Equal(t, expected, sb.state.baseImage.ImageID())
assert.Len(t, sb.state.buildArgs.GetAllAllowed(), 0)
assert.Len(t, sb.state.buildArgs.GetAllMeta(), 1)
assert.Check(t, is.Equal(expected, sb.state.imageID))
assert.Check(t, is.Equal(expected, sb.state.baseImage.ImageID()))
assert.Check(t, is.Len(sb.state.buildArgs.GetAllAllowed(), 0))
assert.Check(t, is.Len(sb.state.buildArgs.GetAllMeta(), 1))
}
func TestFromWithUndefinedArg(t *testing.T) {
tag, expected := "sometag", "expectedthisid"
getImage := func(name string) (builder.Image, builder.ReleaseableLayer, error) {
assert.Equal(t, "alpine", name)
getImage := func(name string) (builder.Image, builder.ROLayer, error) {
assert.Check(t, is.Equal("alpine", name))
return &mockImage{id: "expectedthisid"}, nil, nil
}
b := newBuilderWithMockBackend()
@@ -173,8 +173,8 @@ func TestFromWithUndefinedArg(t *testing.T) {
BaseName: "alpine${THETAG}",
}
err := initializeStage(sb, cmd)
require.NoError(t, err)
assert.Equal(t, expected, sb.state.imageID)
assert.NilError(t, err)
assert.Check(t, is.Equal(expected, sb.state.imageID))
}
func TestFromMultiStageWithNamedStage(t *testing.T) {
@@ -185,13 +185,13 @@ func TestFromMultiStageWithNamedStage(t *testing.T) {
firstSB := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), previousResults)
secondSB := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), previousResults)
err := initializeStage(firstSB, firstFrom)
require.NoError(t, err)
assert.True(t, firstSB.state.hasFromImage())
assert.NilError(t, err)
assert.Check(t, firstSB.state.hasFromImage())
previousResults.indexed["base"] = firstSB.state.runConfig
previousResults.flat = append(previousResults.flat, firstSB.state.runConfig)
err = initializeStage(secondSB, secondFrom)
require.NoError(t, err)
assert.True(t, secondSB.state.hasFromImage())
assert.NilError(t, err)
assert.Check(t, secondSB.state.hasFromImage())
}
func TestOnbuild(t *testing.T) {
@@ -201,8 +201,8 @@ func TestOnbuild(t *testing.T) {
Expression: "ADD . /app/src",
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.Equal(t, "ADD . /app/src", sb.state.runConfig.OnBuild[0])
assert.NilError(t, err)
assert.Check(t, is.Equal("ADD . /app/src", sb.state.runConfig.OnBuild[0]))
}
func TestWorkdir(t *testing.T) {
@@ -217,8 +217,8 @@ func TestWorkdir(t *testing.T) {
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.Equal(t, workingDir, sb.state.runConfig.WorkingDir)
assert.NilError(t, err)
assert.Check(t, is.Equal(workingDir, sb.state.runConfig.WorkingDir))
}
func TestCmd(t *testing.T) {
@@ -233,7 +233,7 @@ func TestCmd(t *testing.T) {
},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
var expectedCommand strslice.StrSlice
if runtime.GOOS == "windows" {
@@ -242,8 +242,8 @@ func TestCmd(t *testing.T) {
expectedCommand = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", command))
}
assert.Equal(t, expectedCommand, sb.state.runConfig.Cmd)
assert.True(t, sb.state.cmdSet)
assert.Check(t, is.DeepEqual(expectedCommand, sb.state.runConfig.Cmd))
assert.Check(t, sb.state.cmdSet)
}
func TestHealthcheckNone(t *testing.T) {
@@ -255,10 +255,10 @@ func TestHealthcheckNone(t *testing.T) {
},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
require.NotNil(t, sb.state.runConfig.Healthcheck)
assert.Equal(t, []string{"NONE"}, sb.state.runConfig.Healthcheck.Test)
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)
assert.Check(t, is.DeepEqual([]string{"NONE"}, sb.state.runConfig.Healthcheck.Test))
}
func TestHealthcheckCmd(t *testing.T) {
@@ -272,10 +272,10 @@ func TestHealthcheckCmd(t *testing.T) {
},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
require.NotNil(t, sb.state.runConfig.Healthcheck)
assert.Equal(t, expectedTest, sb.state.runConfig.Healthcheck.Test)
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)
assert.Check(t, is.DeepEqual(expectedTest, sb.state.runConfig.Healthcheck.Test))
}
func TestEntrypoint(t *testing.T) {
@@ -290,8 +290,8 @@ func TestEntrypoint(t *testing.T) {
},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
require.NotNil(t, sb.state.runConfig.Entrypoint)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.Entrypoint != nil)
var expectedEntrypoint strslice.StrSlice
if runtime.GOOS == "windows" {
@@ -299,7 +299,7 @@ func TestEntrypoint(t *testing.T) {
} else {
expectedEntrypoint = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", entrypointCmd))
}
assert.Equal(t, expectedEntrypoint, sb.state.runConfig.Entrypoint)
assert.Check(t, is.DeepEqual(expectedEntrypoint, sb.state.runConfig.Entrypoint))
}
func TestExpose(t *testing.T) {
@@ -311,14 +311,14 @@ func TestExpose(t *testing.T) {
Ports: []string{exposedPort},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
require.NotNil(t, sb.state.runConfig.ExposedPorts)
require.Len(t, sb.state.runConfig.ExposedPorts, 1)
assert.Assert(t, sb.state.runConfig.ExposedPorts != nil)
assert.Assert(t, is.Len(sb.state.runConfig.ExposedPorts, 1))
portsMapping, err := nat.ParsePortSpec(exposedPort)
require.NoError(t, err)
assert.Contains(t, sb.state.runConfig.ExposedPorts, portsMapping[0].Port)
assert.NilError(t, err)
assert.Check(t, is.Contains(sb.state.runConfig.ExposedPorts, portsMapping[0].Port))
}
func TestUser(t *testing.T) {
@@ -329,8 +329,8 @@ func TestUser(t *testing.T) {
User: "test",
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.Equal(t, "test", sb.state.runConfig.User)
assert.NilError(t, err)
assert.Check(t, is.Equal("test", sb.state.runConfig.User))
}
func TestVolume(t *testing.T) {
@@ -343,10 +343,10 @@ func TestVolume(t *testing.T) {
Volumes: []string{exposedVolume},
}
err := dispatch(sb, cmd)
require.NoError(t, err)
require.NotNil(t, sb.state.runConfig.Volumes)
assert.Len(t, sb.state.runConfig.Volumes, 1)
assert.Contains(t, sb.state.runConfig.Volumes, exposedVolume)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.Volumes != nil)
assert.Check(t, is.Len(sb.state.runConfig.Volumes, 1))
assert.Check(t, is.Contains(sb.state.runConfig.Volumes, exposedVolume))
}
func TestStopSignal(t *testing.T) {
@@ -362,8 +362,8 @@ func TestStopSignal(t *testing.T) {
Signal: signal,
}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.Equal(t, signal, sb.state.runConfig.StopSignal)
assert.NilError(t, err)
assert.Check(t, is.Equal(signal, sb.state.runConfig.StopSignal))
}
func TestArg(t *testing.T) {
@@ -374,10 +374,10 @@ func TestArg(t *testing.T) {
argVal := "bar"
cmd := &instructions.ArgCommand{Key: argName, Value: &argVal}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
expected := map[string]string{argName: argVal}
assert.Equal(t, expected, sb.state.buildArgs.GetAllAllowed())
assert.Check(t, is.DeepEqual(expected, sb.state.buildArgs.GetAllAllowed()))
}
func TestShell(t *testing.T) {
@@ -388,10 +388,10 @@ func TestShell(t *testing.T) {
cmd := &instructions.ShellCommand{Shell: strslice.StrSlice{shellCmd}}
err := dispatch(sb, cmd)
require.NoError(t, err)
assert.NilError(t, err)
expectedShell := strslice.StrSlice([]string{shellCmd})
assert.Equal(t, expectedShell, sb.state.runConfig.Shell)
assert.Check(t, is.DeepEqual(expectedShell, sb.state.runConfig.Shell))
}
func TestPrependEnvOnCmd(t *testing.T) {
@@ -403,7 +403,7 @@ func TestPrependEnvOnCmd(t *testing.T) {
cmdWithEnv := prependEnvOnCmd(buildArgs, args, cmd)
expected := strslice.StrSlice([]string{
"|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar"})
assert.Equal(t, expected, cmdWithEnv)
assert.Check(t, is.DeepEqual(expected, cmdWithEnv))
}
func TestRunWithBuildArgs(t *testing.T) {
@@ -422,8 +422,8 @@ func TestRunWithBuildArgs(t *testing.T) {
imageCache := &mockImageCache{
getCacheFunc: func(parentID string, cfg *container.Config) (string, error) {
// Check the runConfig.Cmd sent to probeCache()
assert.Equal(t, cachedCmd, cfg.Cmd)
assert.Equal(t, strslice.StrSlice(nil), cfg.Entrypoint)
assert.Check(t, is.DeepEqual(cachedCmd, cfg.Cmd))
assert.Check(t, is.DeepEqual(strslice.StrSlice(nil), cfg.Entrypoint))
return "", nil
},
}
@@ -433,7 +433,7 @@ func TestRunWithBuildArgs(t *testing.T) {
return imageCache
}
b.imageProber = newImageProber(mockBackend, nil, false)
mockBackend.getImageFunc = func(_ string) (builder.Image, builder.ReleaseableLayer, error) {
mockBackend.getImageFunc = func(_ string) (builder.Image, builder.ROLayer, error) {
return &mockImage{
id: "abcdef",
config: &container.Config{Cmd: origCmd},
@@ -441,21 +441,21 @@ func TestRunWithBuildArgs(t *testing.T) {
}
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) {
// Check the runConfig.Cmd sent to create()
assert.Equal(t, cmdWithShell, config.Config.Cmd)
assert.Contains(t, config.Config.Env, "one=two")
assert.Equal(t, strslice.StrSlice{""}, config.Config.Entrypoint)
assert.Check(t, is.DeepEqual(cmdWithShell, config.Config.Cmd))
assert.Check(t, is.Contains(config.Config.Env, "one=two"))
assert.Check(t, is.DeepEqual(strslice.StrSlice{""}, config.Config.Entrypoint))
return container.ContainerCreateCreatedBody{ID: "12345"}, nil
}
mockBackend.commitFunc = func(cfg backend.CommitConfig) (image.ID, error) {
// Check the runConfig.Cmd sent to commit()
assert.Equal(t, origCmd, cfg.Config.Cmd)
assert.Equal(t, cachedCmd, cfg.ContainerConfig.Cmd)
assert.Equal(t, strslice.StrSlice(nil), cfg.Config.Entrypoint)
assert.Check(t, is.DeepEqual(origCmd, cfg.Config.Cmd))
assert.Check(t, is.DeepEqual(cachedCmd, cfg.ContainerConfig.Cmd))
assert.Check(t, is.DeepEqual(strslice.StrSlice(nil), cfg.Config.Entrypoint))
return "", nil
}
from := &instructions.Stage{BaseName: "abcdef"}
err := initializeStage(sb, from)
require.NoError(t, err)
assert.NilError(t, err)
sb.state.buildArgs.AddArg("one", strPtr("two"))
run := &instructions.RunCommand{
ShellDependantCmdLine: instructions.ShellDependantCmdLine{
@@ -463,8 +463,8 @@ func TestRunWithBuildArgs(t *testing.T) {
PrependShell: true,
},
}
require.NoError(t, dispatch(sb, run))
assert.NilError(t, dispatch(sb, run))
// Check that runConfig.Cmd has not been modified by run
assert.Equal(t, origCmd, sb.state.runConfig.Cmd)
assert.Check(t, is.DeepEqual(origCmd, sb.state.runConfig.Cmd))
}

View File

@@ -5,7 +5,6 @@ import (
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/builder"
"github.com/docker/docker/builder/remotecontext"
dockerimage "github.com/docker/docker/image"
"github.com/docker/docker/pkg/system"
"github.com/pkg/errors"
@@ -13,7 +12,7 @@ import (
"golang.org/x/net/context"
)
type getAndMountFunc func(string, bool) (builder.Image, builder.ReleaseableLayer, error)
type getAndMountFunc func(string, bool) (builder.Image, builder.ROLayer, error)
// imageSources mounts images and provides a cache for mounted images. It tracks
// all images so they can be unmounted at the end of the build.
@@ -24,7 +23,7 @@ type imageSources struct {
}
func newImageSources(ctx context.Context, options builderOptions) *imageSources {
getAndMount := func(idOrRef string, localOnly bool) (builder.Image, builder.ReleaseableLayer, error) {
getAndMount := func(idOrRef string, localOnly bool) (builder.Image, builder.ROLayer, error) {
pullOption := backend.PullOptionNoPull
if !localOnly {
if options.Options.PullParent {
@@ -92,32 +91,14 @@ func (m *imageSources) Add(im *imageMount) {
type imageMount struct {
image builder.Image
source builder.Source
layer builder.ReleaseableLayer
layer builder.ROLayer
}
func newImageMount(image builder.Image, layer builder.ReleaseableLayer) *imageMount {
func newImageMount(image builder.Image, layer builder.ROLayer) *imageMount {
im := &imageMount{image: image, layer: layer}
return im
}
func (im *imageMount) Source() (builder.Source, error) {
if im.source == nil {
if im.layer == nil {
return nil, errors.Errorf("empty context")
}
mountPath, err := im.layer.Mount()
if err != nil {
return nil, errors.Wrapf(err, "failed to mount %s", im.image.ImageID())
}
source, err := remotecontext.NewLazySource(mountPath)
if err != nil {
return nil, errors.Wrapf(err, "failed to create lazycontext for %s", mountPath)
}
im.source = source
}
return im.source, nil
}
func (im *imageMount) unmount() error {
if im.layer == nil {
return nil
@@ -133,8 +114,8 @@ func (im *imageMount) Image() builder.Image {
return im.image
}
func (im *imageMount) Layer() builder.ReleaseableLayer {
return im.layer
func (im *imageMount) NewRWLayer() (builder.RWLayer, error) {
return im.layer.NewRWLayer()
}
func (im *imageMount) ImageID() string {

View File

@@ -7,8 +7,8 @@ import (
"github.com/docker/docker/builder/dockerfile/command"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/docker/docker/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestCommandsExactlyOneArgument(t *testing.T) {
@@ -21,9 +21,9 @@ func TestCommandsExactlyOneArgument(t *testing.T) {
for _, command := range commands {
ast, err := parser.Parse(strings.NewReader(command))
require.NoError(t, err)
assert.NilError(t, err)
_, err = ParseInstruction(ast.AST.Children[0])
assert.EqualError(t, err, errExactlyOneArgument(command).Error())
assert.Check(t, is.Error(err, errExactlyOneArgument(command).Error()))
}
}
@@ -39,9 +39,9 @@ func TestCommandsAtLeastOneArgument(t *testing.T) {
for _, command := range commands {
ast, err := parser.Parse(strings.NewReader(command))
require.NoError(t, err)
assert.NilError(t, err)
_, err = ParseInstruction(ast.AST.Children[0])
assert.EqualError(t, err, errAtLeastOneArgument(command).Error())
assert.Check(t, is.Error(err, errAtLeastOneArgument(command).Error()))
}
}
@@ -53,9 +53,9 @@ func TestCommandsNoDestinationArgument(t *testing.T) {
for _, command := range commands {
ast, err := parser.Parse(strings.NewReader(command + " arg1"))
require.NoError(t, err)
assert.NilError(t, err)
_, err = ParseInstruction(ast.AST.Children[0])
assert.EqualError(t, err, errNoDestinationArgument(command).Error())
assert.Check(t, is.Error(err, errNoDestinationArgument(command).Error()))
}
}
@@ -80,7 +80,7 @@ func TestCommandsTooManyArguments(t *testing.T) {
},
}
_, err := ParseInstruction(node)
assert.EqualError(t, err, errTooManyArguments(command).Error())
assert.Check(t, is.Error(err, errTooManyArguments(command).Error()))
}
}
@@ -102,7 +102,7 @@ func TestCommandsBlankNames(t *testing.T) {
},
}
_, err := ParseInstruction(node)
assert.EqualError(t, err, errBlankCommandNames(command).Error())
assert.Check(t, is.Error(err, errBlankCommandNames(command).Error()))
}
}
@@ -120,11 +120,11 @@ func TestHealthCheckCmd(t *testing.T) {
},
}
cmd, err := ParseInstruction(node)
assert.NoError(t, err)
assert.Check(t, err)
hc, ok := cmd.(*HealthCheckCommand)
assert.True(t, ok)
assert.Check(t, ok)
expected := []string{"CMD-SHELL", "hello world"}
assert.Equal(t, expected, hc.Health.Test)
assert.Check(t, is.DeepEqual(expected, hc.Health.Test))
}
func TestParseOptInterval(t *testing.T) {
@@ -138,7 +138,7 @@ func TestParseOptInterval(t *testing.T) {
flInterval.Value = "1ms"
_, err = parseOptInterval(flInterval)
require.NoError(t, err)
assert.NilError(t, err)
}
func TestErrorCases(t *testing.T) {

View File

@@ -17,6 +17,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/builder"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/chrootarchive"
@@ -114,8 +115,8 @@ func (b *Builder) commitContainer(dispatchState *dispatchState, id string, conta
return err
}
func (b *Builder) exportImage(state *dispatchState, imageMount *imageMount, runConfig *container.Config) error {
newLayer, err := imageMount.Layer().Commit()
func (b *Builder) exportImage(state *dispatchState, layer builder.RWLayer, parent builder.Image, runConfig *container.Config) error {
newLayer, err := layer.Commit()
if err != nil {
return err
}
@@ -124,7 +125,7 @@ func (b *Builder) exportImage(state *dispatchState, imageMount *imageMount, runC
// if there is an error before we can add the full mount with image
b.imageSources.Add(newImageMount(nil, newLayer))
parentImage, ok := imageMount.Image().(*image.Image)
parentImage, ok := parent.(*image.Image)
if !ok {
return errors.Errorf("unexpected image type")
}
@@ -177,7 +178,13 @@ func (b *Builder) performCopy(state *dispatchState, inst copyInstruction) error
return errors.Wrapf(err, "failed to get destination image %q", state.imageID)
}
destInfo, err := createDestInfo(state.runConfig.WorkingDir, inst, imageMount, b.options.Platform)
rwLayer, err := imageMount.NewRWLayer()
if err != nil {
return err
}
defer rwLayer.Release()
destInfo, err := createDestInfo(state.runConfig.WorkingDir, inst, rwLayer, b.options.Platform)
if err != nil {
return err
}
@@ -203,10 +210,10 @@ func (b *Builder) performCopy(state *dispatchState, inst copyInstruction) error
return errors.Wrapf(err, "failed to copy files")
}
}
return b.exportImage(state, imageMount, runConfigWithCommentCmd)
return b.exportImage(state, rwLayer, imageMount.Image(), runConfigWithCommentCmd)
}
func createDestInfo(workingDir string, inst copyInstruction, imageMount *imageMount, platform string) (copyInfo, error) {
func createDestInfo(workingDir string, inst copyInstruction, rwLayer builder.RWLayer, platform string) (copyInfo, error) {
// Twiddle the destination when it's a relative path - meaning, make it
// relative to the WORKINGDIR
dest, err := normalizeDest(workingDir, inst.dest, platform)
@@ -214,12 +221,7 @@ func createDestInfo(workingDir string, inst copyInstruction, imageMount *imageMo
return copyInfo{}, errors.Wrapf(err, "invalid %s", inst.cmdName)
}
destMount, err := imageMount.Source()
if err != nil {
return copyInfo{}, errors.Wrapf(err, "failed to mount copy source")
}
return newCopyInfoFromSource(destMount, dest, ""), nil
return copyInfo{root: rwLayer.Root(), path: dest}, nil
}
// normalizeDest normalises the destination of a COPY/ADD command in a

View File

@@ -6,8 +6,8 @@ import (
"testing"
"github.com/docker/docker/pkg/idtools"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestChownFlagParsing(t *testing.T) {
@@ -99,8 +99,8 @@ othergrp:x:6666:
} {
t.Run(testcase.name, func(t *testing.T) {
idPair, err := parseChownFlag(testcase.chownStr, contextDir, testcase.idMapping)
require.NoError(t, err, "Failed to parse chown flag: %q", testcase.chownStr)
assert.Equal(t, testcase.expected, idPair, "chown flag mapping failure")
assert.NilError(t, err, "Failed to parse chown flag: %q", testcase.chownStr)
assert.Check(t, is.DeepEqual(testcase.expected, idPair), "chown flag mapping failure")
})
}
@@ -132,7 +132,7 @@ othergrp:x:6666:
} {
t.Run(testcase.name, func(t *testing.T) {
_, err := parseChownFlag(testcase.chownStr, contextDir, testcase.idMapping)
assert.EqualError(t, err, testcase.descr, "Expected error string doesn't match")
assert.Check(t, is.Error(err, testcase.descr), "Expected error string doesn't match")
})
}
}

View File

@@ -12,8 +12,8 @@ import (
"github.com/docker/docker/builder/remotecontext"
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestEmptyDockerfile(t *testing.T) {
@@ -60,7 +60,7 @@ func TestNonExistingDockerfile(t *testing.T) {
func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) {
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
require.NoError(t, err)
assert.NilError(t, err)
defer func() {
if err = tarStream.Close(); err != nil {
@@ -77,7 +77,7 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath,
Source: tarStream,
}
_, _, err = remotecontext.Detect(config)
assert.EqualError(t, err, expectedError)
assert.Check(t, is.Error(err, expectedError))
}
func TestCopyRunConfig(t *testing.T) {
@@ -124,9 +124,9 @@ func TestCopyRunConfig(t *testing.T) {
Env: defaultEnv,
}
runConfigCopy := copyRunConfig(runConfig, testcase.modifiers...)
assert.Equal(t, testcase.expected, runConfigCopy, testcase.doc)
assert.Check(t, is.DeepEqual(testcase.expected, runConfigCopy), testcase.doc)
// Assert the original was not modified
assert.NotEqual(t, runConfig, runConfigCopy, testcase.doc)
assert.Check(t, runConfig != runConfigCopy, testcase.doc)
}
}
@@ -156,7 +156,7 @@ func fullMutableRunConfig() *container.Config {
func TestDeepCopyRunConfig(t *testing.T) {
runConfig := fullMutableRunConfig()
copy := copyRunConfig(runConfig)
assert.Equal(t, fullMutableRunConfig(), copy)
assert.Check(t, is.DeepEqual(fullMutableRunConfig(), copy))
copy.Cmd[1] = "arg2"
copy.Env[1] = "env2=new"
@@ -166,5 +166,5 @@ func TestDeepCopyRunConfig(t *testing.T) {
copy.OnBuild[0] = "start"
copy.Labels["label3"] = "value3"
copy.Shell[0] = "sh"
assert.Equal(t, fullMutableRunConfig(), runConfig)
assert.Check(t, is.DeepEqual(fullMutableRunConfig(), runConfig))
}

View File

@@ -7,7 +7,8 @@ import (
"testing"
"github.com/docker/docker/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestNormalizeDest(t *testing.T) {
@@ -42,10 +43,10 @@ func TestNormalizeDest(t *testing.T) {
msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
actual, err := normalizeDest(testcase.current, testcase.requested, "windows")
if testcase.etext == "" {
if !assert.NoError(t, err, msg) {
if !assert.Check(t, err, msg) {
continue
}
assert.Equal(t, testcase.expected, actual, msg)
assert.Check(t, is.Equal(testcase.expected, actual), msg)
} else {
testutil.ErrorContains(t, err, testcase.etext)
}

View File

@@ -20,7 +20,7 @@ import (
type MockBackend struct {
containerCreateFunc func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
commitFunc func(backend.CommitConfig) (image.ID, error)
getImageFunc func(string) (builder.Image, builder.ReleaseableLayer, error)
getImageFunc func(string) (builder.Image, builder.ROLayer, error)
makeImageCacheFunc func(cacheFrom []string) builder.ImageCache
}
@@ -66,7 +66,7 @@ func (m *MockBackend) CopyOnBuild(containerID string, destPath string, srcRoot s
return nil
}
func (m *MockBackend) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ReleaseableLayer, error) {
func (m *MockBackend) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
if m.getImageFunc != nil {
return m.getImageFunc(refOrID)
}
@@ -124,14 +124,25 @@ func (l *mockLayer) Release() error {
return nil
}
func (l *mockLayer) Mount() (containerfs.ContainerFS, error) {
return containerfs.NewLocalContainerFS("mountPath"), nil
}
func (l *mockLayer) Commit() (builder.ReleaseableLayer, error) {
return nil, nil
func (l *mockLayer) NewRWLayer() (builder.RWLayer, error) {
return &mockRWLayer{}, nil
}
func (l *mockLayer) DiffID() layer.DiffID {
return layer.DiffID("abcdef")
}
type mockRWLayer struct {
}
func (l *mockRWLayer) Release() error {
return nil
}
func (l *mockRWLayer) Commit() (builder.ROLayer, error) {
return nil, nil
}
func (l *mockRWLayer) Root() containerfs.ContainerFS {
return nil
}

View File

@@ -3,25 +3,29 @@ package parser // import "github.com/docker/docker/builder/dockerfile/parser"
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestParseNameValOldFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo bar", "LABEL", &directive)
assert.NoError(t, err)
assert.Check(t, err)
expected := &Node{
Value: "foo",
Next: &Node{Value: "bar"},
}
assert.Equal(t, expected, node)
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
var cmpNodeOpt = cmp.AllowUnexported(Node{})
func TestParseNameValNewFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
assert.NoError(t, err)
assert.Check(t, err)
expected := &Node{
Value: "foo",
@@ -35,7 +39,7 @@ func TestParseNameValNewFormat(t *testing.T) {
},
},
}
assert.Equal(t, expected, node)
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
func TestNodeFromLabels(t *testing.T) {
@@ -61,8 +65,7 @@ func TestNodeFromLabels(t *testing.T) {
}
node := NodeFromLabels(labels)
assert.Equal(t, expected, node)
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
func TestParseNameValWithoutVal(t *testing.T) {
@@ -70,5 +73,5 @@ func TestParseNameValWithoutVal(t *testing.T) {
// In Config.Env, a variable without `=` is removed from the environment. (#31634)
// However, in Dockerfile, we don't allow "unsetting" an environment variable. (#11922)
_, err := parseNameVal("foo", "ENV", &directive)
assert.Error(t, err, "ENV must have two arguments")
assert.Check(t, is.ErrorContains(err, ""), "ENV must have two arguments")
}

View File

@@ -11,8 +11,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
const testDir = "testfiles"
@@ -21,11 +21,11 @@ const testFileLineInfo = "testfile-line/Dockerfile"
func getDirs(t *testing.T, dir string) []string {
f, err := os.Open(dir)
require.NoError(t, err)
assert.NilError(t, err)
defer f.Close()
dirs, err := f.Readdirnames(0)
require.NoError(t, err)
assert.NilError(t, err)
return dirs
}
@@ -34,11 +34,11 @@ func TestParseErrorCases(t *testing.T) {
dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile")
df, err := os.Open(dockerfile)
require.NoError(t, err, dockerfile)
assert.NilError(t, err, dockerfile)
defer df.Close()
_, err = Parse(df)
assert.Error(t, err, dockerfile)
assert.Check(t, is.ErrorContains(err, ""), dockerfile)
}
}
@@ -48,20 +48,20 @@ func TestParseCases(t *testing.T) {
resultfile := filepath.Join(testDir, dir, "result")
df, err := os.Open(dockerfile)
require.NoError(t, err, dockerfile)
assert.NilError(t, err, dockerfile)
defer df.Close()
result, err := Parse(df)
require.NoError(t, err, dockerfile)
assert.NilError(t, err, dockerfile)
content, err := ioutil.ReadFile(resultfile)
require.NoError(t, err, resultfile)
assert.NilError(t, err, resultfile)
if runtime.GOOS == "windows" {
// CRLF --> CR to match Unix behavior
content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1)
}
assert.Equal(t, result.AST.Dump()+"\n", string(content), "In "+dockerfile)
assert.Check(t, is.Equal(result.AST.Dump()+"\n", string(content)), "In "+dockerfile)
}
}
@@ -103,22 +103,22 @@ func TestParseWords(t *testing.T) {
for _, test := range tests {
words := parseWords(test["input"][0], NewDefaultDirective())
assert.Equal(t, test["expect"], words)
assert.Check(t, is.DeepEqual(test["expect"], words))
}
}
func TestParseIncludesLineNumbers(t *testing.T) {
df, err := os.Open(testFileLineInfo)
require.NoError(t, err)
assert.NilError(t, err)
defer df.Close()
result, err := Parse(df)
require.NoError(t, err)
assert.NilError(t, err)
ast := result.AST
assert.Equal(t, 5, ast.StartLine)
assert.Equal(t, 31, ast.endLine)
assert.Len(t, ast.Children, 3)
assert.Check(t, is.Equal(5, ast.StartLine))
assert.Check(t, is.Equal(31, ast.endLine))
assert.Check(t, is.Len(ast.Children, 3))
expected := [][]int{
{5, 5},
{11, 12},
@@ -126,7 +126,7 @@ func TestParseIncludesLineNumbers(t *testing.T) {
}
for i, child := range ast.Children {
msg := fmt.Sprintf("Child %d", i)
assert.Equal(t, expected[i], []int{child.StartLine, child.endLine}, msg)
assert.Check(t, is.DeepEqual(expected[i], []int{child.StartLine, child.endLine}), msg)
}
}
@@ -153,13 +153,13 @@ RUN indented \
`)
result, err := Parse(dockerfile)
require.NoError(t, err)
assert.NilError(t, err)
warnings := result.Warnings
assert.Len(t, warnings, 3)
assert.Contains(t, warnings[0], "Empty continuation line found in")
assert.Contains(t, warnings[0], "RUN something following more")
assert.Contains(t, warnings[1], "RUN another thing")
assert.Contains(t, warnings[2], "will become errors in a future release")
assert.Check(t, is.Len(warnings, 3))
assert.Check(t, is.Contains(warnings[0], "Empty continuation line found in"))
assert.Check(t, is.Contains(warnings[0], "RUN something following more"))
assert.Check(t, is.Contains(warnings[1], "RUN another thing"))
assert.Check(t, is.Contains(warnings[2], "will become errors in a future release"))
}
func TestParseReturnsScannerErrors(t *testing.T) {
@@ -170,5 +170,5 @@ func TestParseReturnsScannerErrors(t *testing.T) {
LABEL test=%s
`, label))
_, err := Parse(dockerfile)
assert.EqualError(t, err, "dockerfile line greater than max allowed size of 65535")
assert.Check(t, is.Error(err, "dockerfile line greater than max allowed size of 65535"))
}

View File

@@ -7,7 +7,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestShellParser4EnvVars(t *testing.T) {
@@ -15,7 +16,7 @@ func TestShellParser4EnvVars(t *testing.T) {
lineCount := 0
file, err := os.Open(fn)
assert.NoError(t, err)
assert.Check(t, err)
defer file.Close()
shlex := NewLex('\\')
@@ -37,7 +38,7 @@ func TestShellParser4EnvVars(t *testing.T) {
}
words := strings.Split(line, "|")
assert.Len(t, words, 3)
assert.Check(t, is.Len(words, 3))
platform := strings.TrimSpace(words[0])
source := strings.TrimSpace(words[1])
@@ -52,10 +53,10 @@ func TestShellParser4EnvVars(t *testing.T) {
((platform == "U" || platform == "A") && runtime.GOOS != "windows") {
newWord, err := shlex.ProcessWord(source, envs)
if expected == "error" {
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
} else {
assert.NoError(t, err)
assert.Equal(t, newWord, expected)
assert.Check(t, err)
assert.Check(t, is.Equal(newWord, expected))
}
}
}

View File

@@ -7,14 +7,15 @@ import (
"testing"
"time"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/moby/buildkit/session/filesync"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestFSCache(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "fscache")
assert.Nil(t, err)
assert.Check(t, err)
defer os.RemoveAll(tmpDir)
backend := NewNaiveCacheBackend(filepath.Join(tmpDir, "backend"))
@@ -26,84 +27,84 @@ func TestFSCache(t *testing.T) {
}
fscache, err := NewFSCache(opt)
assert.Nil(t, err)
assert.Check(t, err)
defer fscache.Close()
err = fscache.RegisterTransport("test", &testTransport{})
assert.Nil(t, err)
assert.Check(t, err)
src1, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo", "data", "bar"})
assert.Nil(t, err)
assert.Check(t, err)
dt, err := ioutil.ReadFile(filepath.Join(src1.Root().Path(), "foo"))
assert.Nil(t, err)
assert.Equal(t, string(dt), "data")
assert.Check(t, err)
assert.Check(t, is.Equal(string(dt), "data"))
// same id doesn't recalculate anything
src2, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo", "data2", "bar"})
assert.Nil(t, err)
assert.Equal(t, src1.Root().Path(), src2.Root().Path())
assert.Check(t, err)
assert.Check(t, is.Equal(src1.Root().Path(), src2.Root().Path()))
dt, err = ioutil.ReadFile(filepath.Join(src1.Root().Path(), "foo"))
assert.Nil(t, err)
assert.Equal(t, string(dt), "data")
assert.Nil(t, src2.Close())
assert.Check(t, err)
assert.Check(t, is.Equal(string(dt), "data"))
assert.Check(t, src2.Close())
src3, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo2", "data2", "bar"})
assert.Nil(t, err)
assert.NotEqual(t, src1.Root().Path(), src3.Root().Path())
assert.Check(t, err)
assert.Check(t, src1.Root().Path() != src3.Root().Path())
dt, err = ioutil.ReadFile(filepath.Join(src3.Root().Path(), "foo2"))
assert.Nil(t, err)
assert.Equal(t, string(dt), "data2")
assert.Check(t, err)
assert.Check(t, is.Equal(string(dt), "data2"))
s, err := fscache.DiskUsage()
assert.Nil(t, err)
assert.Equal(t, s, int64(0))
assert.Check(t, err)
assert.Check(t, is.Equal(s, int64(0)))
assert.Nil(t, src3.Close())
assert.Check(t, src3.Close())
s, err = fscache.DiskUsage()
assert.Nil(t, err)
assert.Equal(t, s, int64(5))
assert.Check(t, err)
assert.Check(t, is.Equal(s, int64(5)))
// new upload with the same shared key shoutl overwrite
src4, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo3", "data3", "bar"})
assert.Nil(t, err)
assert.NotEqual(t, src1.Root().Path(), src3.Root().Path())
assert.Check(t, err)
assert.Check(t, src1.Root().Path() != src3.Root().Path())
dt, err = ioutil.ReadFile(filepath.Join(src3.Root().Path(), "foo3"))
assert.Nil(t, err)
assert.Equal(t, string(dt), "data3")
assert.Equal(t, src4.Root().Path(), src3.Root().Path())
assert.Nil(t, src4.Close())
assert.Check(t, err)
assert.Check(t, is.Equal(string(dt), "data3"))
assert.Check(t, is.Equal(src4.Root().Path(), src3.Root().Path()))
assert.Check(t, src4.Close())
s, err = fscache.DiskUsage()
assert.Nil(t, err)
assert.Equal(t, s, int64(10))
assert.Check(t, err)
assert.Check(t, is.Equal(s, int64(10)))
// this one goes over the GC limit
src5, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo4", "datadata", "baz"})
assert.Nil(t, err)
assert.Nil(t, src5.Close())
assert.Check(t, err)
assert.Check(t, src5.Close())
// GC happens async
time.Sleep(100 * time.Millisecond)
// only last insertion after GC
s, err = fscache.DiskUsage()
assert.Nil(t, err)
assert.Equal(t, s, int64(8))
assert.Check(t, err)
assert.Check(t, is.Equal(s, int64(8)))
// prune deletes everything
released, err := fscache.Prune(context.TODO())
assert.Nil(t, err)
assert.Equal(t, released, uint64(8))
assert.Check(t, err)
assert.Check(t, is.Equal(released, uint64(8)))
s, err = fscache.DiskUsage()
assert.Nil(t, err)
assert.Equal(t, s, int64(0))
assert.Check(t, err)
assert.Check(t, is.Equal(s, int64(0)))
}
type testTransport struct {

View File

@@ -13,42 +13,39 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestParseRemoteURL(t *testing.T) {
dir, err := parseRemoteURL("git://github.com/user/repo.git")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"git://github.com/user/repo.git", "master", ""}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
dir, err = parseRemoteURL("https://github.com/user/repo.git")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"https://github.com/user/repo.git", "master", ""}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
dir, err = parseRemoteURL("git@github.com:user/repo.git")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"git@github.com:user/repo.git", "master", ""}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/")
require.NoError(t, err)
assert.NotEmpty(t, dir)
assert.Equal(t, gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
}
var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{})
func TestCloneArgsSmartHttp(t *testing.T) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
@@ -63,7 +60,7 @@ func TestCloneArgsSmartHttp(t *testing.T) {
args := fetchArgs(serverURL.String(), "master")
exp := []string{"fetch", "--depth", "1", "origin", "master"}
assert.Equal(t, exp, args)
assert.Check(t, is.DeepEqual(exp, args))
}
func TestCloneArgsDumbHttp(t *testing.T) {
@@ -79,13 +76,13 @@ func TestCloneArgsDumbHttp(t *testing.T) {
args := fetchArgs(serverURL.String(), "master")
exp := []string{"fetch", "origin", "master"}
assert.Equal(t, exp, args)
assert.Check(t, is.DeepEqual(exp, args))
}
func TestCloneArgsGit(t *testing.T) {
args := fetchArgs("git://github.com/docker/docker", "master")
exp := []string{"fetch", "--depth", "1", "origin", "master"}
assert.Equal(t, exp, args)
assert.Check(t, is.DeepEqual(exp, args))
}
func gitGetConfig(name string) string {
@@ -100,7 +97,7 @@ func gitGetConfig(name string) string {
func TestCheckoutGit(t *testing.T) {
root, err := ioutil.TempDir("", "docker-build-git-checkout")
require.NoError(t, err)
assert.NilError(t, err)
defer os.RemoveAll(root)
autocrlf := gitGetConfig("core.autocrlf")
@@ -115,22 +112,22 @@ func TestCheckoutGit(t *testing.T) {
gitDir := filepath.Join(root, "repo")
_, err = git("init", gitDir)
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "config", "user.email", "test@docker.com")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "config", "user.name", "Docker test")
require.NoError(t, err)
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
subDir := filepath.Join(gitDir, "subdir")
require.NoError(t, os.Mkdir(subDir, 0755))
assert.NilError(t, os.Mkdir(subDir, 0755))
err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 5000"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
if runtime.GOOS != "windows" {
if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
@@ -143,58 +140,58 @@ func TestCheckoutGit(t *testing.T) {
}
_, err = gitWithinDir(gitDir, "add", "-A")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "commit", "-am", "First commit")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "checkout", "-b", "test")
require.NoError(t, err)
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 3000"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM busybox\nEXPOSE 5000"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "add", "-A")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "commit", "-am", "Branch commit")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "checkout", "master")
require.NoError(t, err)
assert.NilError(t, err)
// set up submodule
subrepoDir := filepath.Join(root, "subrepo")
_, err = git("init", subrepoDir)
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(subrepoDir, "config", "user.email", "test@docker.com")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(subrepoDir, "config", "user.name", "Docker test")
require.NoError(t, err)
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(subrepoDir, "subfile"), []byte("subcontents"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(subrepoDir, "add", "-A")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(subrepoDir, "commit", "-am", "Subrepo initial")
require.NoError(t, err)
assert.NilError(t, err)
cmd := exec.Command("git", "submodule", "add", subrepoDir, "sub") // this command doesn't work with --work-tree
cmd.Dir = gitDir
require.NoError(t, cmd.Run())
assert.NilError(t, cmd.Run())
_, err = gitWithinDir(gitDir, "add", "-A")
require.NoError(t, err)
assert.NilError(t, err)
_, err = gitWithinDir(gitDir, "commit", "-am", "With submodule")
require.NoError(t, err)
assert.NilError(t, err)
type singleCase struct {
frag string
@@ -232,24 +229,24 @@ func TestCheckoutGit(t *testing.T) {
r, err := cloneGitRepo(gitRepo{remote: gitDir, ref: ref, subdir: subdir})
if c.fail {
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
continue
}
require.NoError(t, err)
assert.NilError(t, err)
defer os.RemoveAll(r)
if c.submodule {
b, err := ioutil.ReadFile(filepath.Join(r, "sub/subfile"))
require.NoError(t, err)
assert.Equal(t, "subcontents", string(b))
assert.NilError(t, err)
assert.Check(t, is.Equal("subcontents", string(b)))
} else {
_, err := os.Stat(filepath.Join(r, "sub/subfile"))
require.Error(t, err)
require.True(t, os.IsNotExist(err))
assert.Assert(t, is.ErrorContains(err, ""))
assert.Assert(t, os.IsNotExist(err))
}
b, err := ioutil.ReadFile(filepath.Join(r, "Dockerfile"))
require.NoError(t, err)
assert.Equal(t, c.exp, string(b))
assert.NilError(t, err)
assert.Check(t, is.Equal(c.exp, string(b)))
}
}

View File

@@ -3,14 +3,14 @@ package remotecontext // import "github.com/docker/docker/builder/remotecontext"
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestDetectContentType(t *testing.T) {
input := []byte("That is just a plain text")
contentType, _, err := detectContentType(input)
require.NoError(t, err)
assert.Equal(t, "text/plain", contentType)
assert.NilError(t, err)
assert.Check(t, is.Equal("text/plain", contentType))
}

View File

@@ -11,9 +11,9 @@ import (
"github.com/docker/docker/builder"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var binaryContext = []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00} //xz magic
@@ -189,12 +189,12 @@ func TestDownloadRemote(t *testing.T) {
mux.Handle("/", http.FileServer(http.Dir(contextDir.Path())))
contentType, content, err := downloadRemote(remoteURL)
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, mimeTypes.TextPlain, contentType)
assert.Check(t, is.Equal(mimeTypes.TextPlain, contentType))
raw, err := ioutil.ReadAll(content)
require.NoError(t, err)
assert.Equal(t, dockerfileContents, string(raw))
assert.NilError(t, err)
assert.Check(t, is.Equal(dockerfileContents, string(raw)))
}
func TestGetWithStatusError(t *testing.T) {
@@ -226,11 +226,11 @@ func TestGetWithStatusError(t *testing.T) {
response, err := GetWithStatusError(ts.URL)
if testcase.expectedErr == "" {
require.NoError(t, err)
assert.NilError(t, err)
body, err := readBody(response.Body)
require.NoError(t, err)
assert.Contains(t, string(body), testcase.expectedBody)
assert.NilError(t, err)
assert.Check(t, is.Contains(string(body), testcase.expectedBody))
} else {
testutil.ErrorContains(t, err, testcase.expectedErr)
}

View File

@@ -11,10 +11,10 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/env"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewEnvClient(t *testing.T) {
@@ -89,19 +89,18 @@ func TestNewEnvClient(t *testing.T) {
env.PatchAll(t, c.envs)
apiclient, err := NewEnvClient()
if c.expectedError != "" {
assert.Error(t, err, c.doc)
assert.Equal(t, c.expectedError, err.Error(), c.doc)
assert.Check(t, is.Error(err, c.expectedError), c.doc)
} else {
assert.NoError(t, err, c.doc)
assert.Check(t, err, c.doc)
version := apiclient.ClientVersion()
assert.Equal(t, c.expectedVersion, version, c.doc)
assert.Check(t, is.Equal(c.expectedVersion, version), c.doc)
}
if c.envs["DOCKER_TLS_VERIFY"] != "" {
// pedantic checking that this is handled correctly
tr := apiclient.client.Transport.(*http.Transport)
assert.NotNil(t, tr.TLSClientConfig, c.doc)
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc)
assert.Assert(t, tr.TLSClientConfig != nil, c.doc)
assert.Check(t, is.Equal(tr.TLSClientConfig.InsecureSkipVerify, false), c.doc)
}
}
}
@@ -128,7 +127,7 @@ func TestGetAPIPath(t *testing.T) {
for _, testcase := range testcases {
c := Client{version: testcase.version, basePath: "/"}
actual := c.getAPIPath(testcase.path, testcase.query)
assert.Equal(t, actual, testcase.expected)
assert.Check(t, is.Equal(actual, testcase.expected))
}
}
@@ -165,7 +164,7 @@ func TestParseHostURL(t *testing.T) {
if testcase.expectedErr != "" {
testutil.ErrorContains(t, err, testcase.expectedErr)
}
assert.Equal(t, testcase.expected, actual)
assert.Check(t, is.DeepEqual(testcase.expected, actual))
}
}
@@ -181,7 +180,7 @@ func TestNewEnvClientSetsDefaultVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, client.version, api.DefaultVersion)
assert.Check(t, is.Equal(client.version, api.DefaultVersion))
expected := "1.22"
os.Setenv("DOCKER_API_VERSION", expected)
@@ -189,7 +188,7 @@ func TestNewEnvClientSetsDefaultVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, expected, client.version)
assert.Check(t, is.Equal(expected, client.version))
}
// TestNegotiateAPIVersionEmpty asserts that client.Client can
@@ -198,7 +197,7 @@ func TestNegotiateAPIVersionEmpty(t *testing.T) {
defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": ""})
client, err := NewEnvClient()
require.NoError(t, err)
assert.NilError(t, err)
ping := types.Ping{
APIVersion: "",
@@ -215,14 +214,14 @@ func TestNegotiateAPIVersionEmpty(t *testing.T) {
// test downgrade
client.NegotiateAPIVersionPing(ping)
assert.Equal(t, expected, client.version)
assert.Check(t, is.Equal(expected, client.version))
}
// TestNegotiateAPIVersion asserts that client.Client can
// negotiate a compatible APIVersion with the server
func TestNegotiateAPIVersion(t *testing.T) {
client, err := NewEnvClient()
require.NoError(t, err)
assert.NilError(t, err)
expected := "1.21"
ping := types.Ping{
@@ -236,14 +235,14 @@ func TestNegotiateAPIVersion(t *testing.T) {
// test downgrade
client.NegotiateAPIVersionPing(ping)
assert.Equal(t, expected, client.version)
assert.Check(t, is.Equal(expected, client.version))
// set the client version to something older, and verify that we keep the
// original setting.
expected = "1.20"
client.version = expected
client.NegotiateAPIVersionPing(ping)
assert.Equal(t, expected, client.version)
assert.Check(t, is.Equal(expected, client.version))
}
@@ -254,7 +253,7 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": expected})()
client, err := NewEnvClient()
require.NoError(t, err)
assert.NilError(t, err)
ping := types.Ping{
APIVersion: "1.24",
@@ -264,7 +263,7 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
// test that we honored the env var
client.NegotiateAPIVersionPing(ping)
assert.Equal(t, expected, client.version)
assert.Check(t, is.Equal(expected, client.version))
}
type roundTripFunc func(*http.Request) (*http.Response, error)
@@ -298,7 +297,7 @@ func TestClientRedirect(t *testing.T) {
cases := []struct {
httpMethod string
expectedErr error
expectedErr *url.Error
statusCode int
}{
{http.MethodGet, nil, 301},
@@ -309,9 +308,15 @@ func TestClientRedirect(t *testing.T) {
for _, tc := range cases {
req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
assert.NoError(t, err)
assert.Check(t, err)
resp, err := client.Do(req)
assert.Equal(t, tc.expectedErr, err)
assert.Equal(t, tc.statusCode, resp.StatusCode)
assert.Check(t, is.Equal(tc.statusCode, resp.StatusCode))
if tc.expectedErr == nil {
assert.Check(t, is.Nil(err))
} else {
urlError, ok := err.(*url.Error)
assert.Assert(t, ok, "%T is not *url.Error", err)
assert.Check(t, is.Equal(*tc.expectedErr, *urlError))
}
}
}

View File

@@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -21,7 +22,7 @@ func TestConfigCreateUnsupported(t *testing.T) {
client: &http.Client{},
}
_, err := client.ConfigCreate(context.Background(), swarm.ConfigSpec{})
assert.EqualError(t, err, `"config create" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"config create" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestConfigCreateError(t *testing.T) {

View File

@@ -10,8 +10,9 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@@ -44,7 +45,7 @@ func TestConfigInspectUnsupported(t *testing.T) {
client: &http.Client{},
}
_, _, err := client.ConfigInspectWithRaw(context.Background(), "nothing")
assert.EqualError(t, err, `"config inspect" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"config inspect" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestConfigInspectError(t *testing.T) {

View File

@@ -12,7 +12,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -22,7 +23,7 @@ func TestConfigListUnsupported(t *testing.T) {
client: &http.Client{},
}
_, err := client.ConfigList(context.Background(), types.ConfigListOptions{})
assert.EqualError(t, err, `"config list" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"config list" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestConfigListError(t *testing.T) {

View File

@@ -8,7 +8,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -18,7 +19,7 @@ func TestConfigRemoveUnsupported(t *testing.T) {
client: &http.Client{},
}
err := client.ConfigRemove(context.Background(), "config_id")
assert.EqualError(t, err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestConfigRemoveError(t *testing.T) {

View File

@@ -9,7 +9,8 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -19,7 +20,7 @@ func TestConfigUpdateUnsupported(t *testing.T) {
client: &http.Client{},
}
err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{})
assert.EqualError(t, err, `"config update" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"config update" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestConfigUpdateError(t *testing.T) {

View File

@@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -24,7 +25,7 @@ func TestContainersPruneError(t *testing.T) {
filters := filters.NewArgs()
_, err := client.ContainersPrune(context.Background(), filters)
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestContainersPrune(t *testing.T) {
@@ -99,7 +100,7 @@ func TestContainersPrune(t *testing.T) {
query := req.URL.Query()
for key, expected := range listCase.expectedQueryParams {
actual := query.Get(key)
assert.Equal(t, expected, actual)
assert.Check(t, is.Equal(expected, actual))
}
content, err := json.Marshal(types.ContainersPruneReport{
ContainersDeleted: []string{"container_id1", "container_id2"},
@@ -117,8 +118,8 @@ func TestContainersPrune(t *testing.T) {
}
report, err := client.ContainersPrune(context.Background(), listCase.filters)
assert.NoError(t, err)
assert.Len(t, report.ContainersDeleted, 2)
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
assert.Check(t, err)
assert.Check(t, is.Len(report.ContainersDeleted, 2))
assert.Check(t, is.Equal(uint64(9999), report.SpaceReclaimed))
}
}

View File

@@ -9,7 +9,8 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -18,7 +19,7 @@ func TestContainerRemoveError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{})
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestContainerRemoveNotFoundError(t *testing.T) {
@@ -26,8 +27,8 @@ func TestContainerRemoveNotFoundError(t *testing.T) {
client: newMockClient(errorMock(http.StatusNotFound, "missing")),
}
err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{})
assert.EqualError(t, err, "Error: No such container: container_id")
assert.True(t, IsErrNotFound(err))
assert.Check(t, is.Error(err, "Error: No such container: container_id"))
assert.Check(t, IsErrNotFound(err))
}
func TestContainerRemove(t *testing.T) {
@@ -61,5 +62,5 @@ func TestContainerRemove(t *testing.T) {
RemoveVolumes: true,
Force: true,
})
assert.NoError(t, err)
assert.Check(t, err)
}

View File

@@ -4,8 +4,9 @@ import (
"net/http"
"testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@@ -15,7 +16,7 @@ func TestDistributionInspectUnsupported(t *testing.T) {
client: &http.Client{},
}
_, err := client.DistributionInspect(context.Background(), "foobar:1.0", "")
assert.EqualError(t, err, `"distribution inspect" requires API version 1.30, but the Docker daemon API version is 1.29`)
assert.Check(t, is.Error(err, `"distribution inspect" requires API version 1.30, but the Docker daemon API version is 1.29`))
}
func TestDistributionInspectWithEmptyID(t *testing.T) {

View File

@@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -24,7 +25,7 @@ func TestImagesPruneError(t *testing.T) {
filters := filters.NewArgs()
_, err := client.ImagesPrune(context.Background(), filters)
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestImagesPrune(t *testing.T) {
@@ -87,7 +88,7 @@ func TestImagesPrune(t *testing.T) {
query := req.URL.Query()
for key, expected := range listCase.expectedQueryParams {
actual := query.Get(key)
assert.Equal(t, expected, actual)
assert.Check(t, is.Equal(expected, actual))
}
content, err := json.Marshal(types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{
@@ -112,8 +113,8 @@ func TestImagesPrune(t *testing.T) {
}
report, err := client.ImagesPrune(context.Background(), listCase.filters)
assert.NoError(t, err)
assert.Len(t, report.ImagesDeleted, 2)
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
assert.Check(t, err)
assert.Check(t, is.Len(report.ImagesDeleted, 2))
assert.Check(t, is.Equal(uint64(9999), report.SpaceReclaimed))
}
}

View File

@@ -10,7 +10,8 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -20,7 +21,7 @@ func TestImageRemoveError(t *testing.T) {
}
_, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{})
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestImageRemoveImageNotFound(t *testing.T) {
@@ -29,8 +30,8 @@ func TestImageRemoveImageNotFound(t *testing.T) {
}
_, err := client.ImageRemove(context.Background(), "unknown", types.ImageRemoveOptions{})
assert.EqualError(t, err, "Error: No such image: unknown")
assert.True(t, IsErrNotFound(err))
assert.Check(t, is.Error(err, "Error: No such image: unknown"))
assert.Check(t, IsErrNotFound(err))
}
func TestImageRemove(t *testing.T) {

View File

@@ -11,8 +11,9 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@@ -22,7 +23,7 @@ func TestNetworkInspectError(t *testing.T) {
}
_, err := client.NetworkInspect(context.Background(), "nothing", types.NetworkInspectOptions{})
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestNetworkInspectNotFoundError(t *testing.T) {
@@ -31,8 +32,8 @@ func TestNetworkInspectNotFoundError(t *testing.T) {
}
_, err := client.NetworkInspect(context.Background(), "unknown", types.NetworkInspectOptions{})
assert.EqualError(t, err, "Error: No such network: unknown")
assert.True(t, IsErrNotFound(err))
assert.Check(t, is.Error(err, "Error: No such network: unknown"))
assert.Check(t, IsErrNotFound(err))
}
func TestNetworkInspectWithEmptyID(t *testing.T) {
@@ -113,5 +114,5 @@ func TestNetworkInspect(t *testing.T) {
}
_, err = client.NetworkInspect(context.Background(), "network_id", types.NetworkInspectOptions{Scope: "global"})
assert.EqualError(t, err, "Error: No such network: network_id")
assert.Check(t, is.Error(err, "Error: No such network: network_id"))
}

View File

@@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -89,7 +90,7 @@ func TestNetworksPrune(t *testing.T) {
query := req.URL.Query()
for key, expected := range listCase.expectedQueryParams {
actual := query.Get(key)
assert.Equal(t, expected, actual)
assert.Check(t, is.Equal(expected, actual))
}
content, err := json.Marshal(types.NetworksPruneReport{
NetworksDeleted: []string{"network_id1", "network_id2"},
@@ -106,7 +107,7 @@ func TestNetworksPrune(t *testing.T) {
}
report, err := client.NetworksPrune(context.Background(), listCase.filters)
assert.NoError(t, err)
assert.Len(t, report.NetworksDeleted, 2)
assert.Check(t, err)
assert.Check(t, is.Len(report.NetworksDeleted, 2))
}
}

View File

@@ -7,7 +7,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -31,15 +32,15 @@ func TestPingFail(t *testing.T) {
}
ping, err := client.Ping(context.Background())
assert.Error(t, err)
assert.Equal(t, false, ping.Experimental)
assert.Equal(t, "", ping.APIVersion)
assert.Check(t, is.ErrorContains(err, ""))
assert.Check(t, is.Equal(false, ping.Experimental))
assert.Check(t, is.Equal("", ping.APIVersion))
withHeader = true
ping2, err := client.Ping(context.Background())
assert.Error(t, err)
assert.Equal(t, true, ping2.Experimental)
assert.Equal(t, "awesome", ping2.APIVersion)
assert.Check(t, is.ErrorContains(err, ""))
assert.Check(t, is.Equal(true, ping2.Experimental))
assert.Check(t, is.Equal("awesome", ping2.APIVersion))
}
// TestPingWithError tests the case where there is a protocol error in the ping.
@@ -57,9 +58,9 @@ func TestPingWithError(t *testing.T) {
}
ping, err := client.Ping(context.Background())
assert.Error(t, err)
assert.Equal(t, false, ping.Experimental)
assert.Equal(t, "", ping.APIVersion)
assert.Check(t, is.ErrorContains(err, ""))
assert.Check(t, is.Equal(false, ping.Experimental))
assert.Check(t, is.Equal("", ping.APIVersion))
}
// TestPingSuccess tests that we are able to get the expected API headers/ping
@@ -76,7 +77,7 @@ func TestPingSuccess(t *testing.T) {
}),
}
ping, err := client.Ping(context.Background())
assert.Error(t, err)
assert.Equal(t, true, ping.Experimental)
assert.Equal(t, "awesome", ping.APIVersion)
assert.Check(t, is.ErrorContains(err, ""))
assert.Check(t, is.Equal(true, ping.Experimental))
assert.Check(t, is.Equal("awesome", ping.APIVersion))
}

View File

@@ -9,7 +9,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
"golang.org/x/net/context"
)
@@ -46,7 +46,7 @@ func TestSetHostHeader(t *testing.T) {
for c, test := range testCases {
hostURL, err := ParseHostURL(test.host)
require.NoError(t, err)
assert.NilError(t, err)
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
@@ -71,7 +71,7 @@ func TestSetHostHeader(t *testing.T) {
}
_, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil)
require.NoError(t, err)
assert.NilError(t, err)
}
}

View File

@@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -21,7 +22,7 @@ func TestSecretCreateUnsupported(t *testing.T) {
client: &http.Client{},
}
_, err := client.SecretCreate(context.Background(), swarm.SecretSpec{})
assert.EqualError(t, err, `"secret create" requires API version 1.25, but the Docker daemon API version is 1.24`)
assert.Check(t, is.Error(err, `"secret create" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
func TestSecretCreateError(t *testing.T) {

View File

@@ -10,8 +10,9 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@@ -21,7 +22,7 @@ func TestSecretInspectUnsupported(t *testing.T) {
client: &http.Client{},
}
_, _, err := client.SecretInspectWithRaw(context.Background(), "nothing")
assert.EqualError(t, err, `"secret inspect" requires API version 1.25, but the Docker daemon API version is 1.24`)
assert.Check(t, is.Error(err, `"secret inspect" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
func TestSecretInspectError(t *testing.T) {

View File

@@ -12,7 +12,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -22,7 +23,7 @@ func TestSecretListUnsupported(t *testing.T) {
client: &http.Client{},
}
_, err := client.SecretList(context.Background(), types.SecretListOptions{})
assert.EqualError(t, err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`)
assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
func TestSecretListError(t *testing.T) {

View File

@@ -8,7 +8,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -18,7 +19,7 @@ func TestSecretRemoveUnsupported(t *testing.T) {
client: &http.Client{},
}
err := client.SecretRemove(context.Background(), "secret_id")
assert.EqualError(t, err, `"secret remove" requires API version 1.25, but the Docker daemon API version is 1.24`)
assert.Check(t, is.Error(err, `"secret remove" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
func TestSecretRemoveError(t *testing.T) {

View File

@@ -9,7 +9,8 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -19,7 +20,7 @@ func TestSecretUpdateUnsupported(t *testing.T) {
client: &http.Client{},
}
err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{})
assert.EqualError(t, err, `"secret update" requires API version 1.25, but the Docker daemon API version is 1.24`)
assert.Check(t, is.Error(err, `"secret update" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
func TestSecretUpdateError(t *testing.T) {

View File

@@ -12,9 +12,10 @@ import (
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@@ -73,8 +74,8 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
return nil, err
}
assert.Equal(t, "foobar:1.0@sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", serviceSpec.TaskTemplate.ContainerSpec.Image)
assert.Len(t, serviceSpec.TaskTemplate.Placement.Platforms, 1)
assert.Check(t, is.Equal("foobar:1.0@sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", serviceSpec.TaskTemplate.ContainerSpec.Image))
assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1))
p := serviceSpec.TaskTemplate.Placement.Platforms[0]
b, err := json.Marshal(types.ServiceCreateResponse{
@@ -115,8 +116,8 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
spec := swarm.ServiceSpec{TaskTemplate: swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{Image: "foobar:1.0"}}}
r, err := client.ServiceCreate(context.Background(), spec, types.ServiceCreateOptions{QueryRegistry: true})
assert.NoError(t, err)
assert.Equal(t, "service_linux_amd64", r.ID)
assert.Check(t, err)
assert.Check(t, is.Equal("service_linux_amd64", r.ID))
}
func TestServiceCreateDigestPinning(t *testing.T) {

View File

@@ -8,7 +8,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -18,7 +19,7 @@ func TestServiceRemoveError(t *testing.T) {
}
err := client.ServiceRemove(context.Background(), "service_id")
assert.EqualError(t, err, "Error response from daemon: Server error")
assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
}
func TestServiceRemoveNotFoundError(t *testing.T) {
@@ -27,8 +28,8 @@ func TestServiceRemoveNotFoundError(t *testing.T) {
}
err := client.ServiceRemove(context.Background(), "service_id")
assert.EqualError(t, err, "Error: No such service: service_id")
assert.True(t, IsErrNotFound(err))
assert.Check(t, is.Error(err, "Error: No such service: service_id"))
assert.Check(t, IsErrNotFound(err))
}
func TestServiceRemove(t *testing.T) {

View File

@@ -11,8 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context"
)
@@ -55,6 +55,6 @@ func TestSwarmGetUnlockKey(t *testing.T) {
}
resp, err := client.SwarmGetUnlockKey(context.Background())
require.NoError(t, err)
assert.Equal(t, unlockKey, resp.UnlockKey)
assert.NilError(t, err)
assert.Check(t, is.Equal(unlockKey, resp.UnlockKey))
}

View File

@@ -11,9 +11,9 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
@@ -32,7 +32,7 @@ func TestVolumeInspectNotFound(t *testing.T) {
}
_, err := client.VolumeInspect(context.Background(), "unknown")
assert.True(t, IsErrNotFound(err))
assert.Check(t, IsErrNotFound(err))
}
func TestVolumeInspectWithEmptyID(t *testing.T) {
@@ -75,6 +75,6 @@ func TestVolumeInspect(t *testing.T) {
}
volume, err := client.VolumeInspect(context.Background(), "volume_id")
require.NoError(t, err)
assert.Equal(t, expected, volume)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume))
}

View File

@@ -6,8 +6,9 @@ import (
"testing"
"github.com/docker/docker/daemon/config"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
)
func TestDaemonParseShmSize(t *testing.T) {
@@ -16,7 +17,7 @@ func TestDaemonParseShmSize(t *testing.T) {
conf := &config.Config{}
installConfigFlags(conf, flags)
// By default `--default-shm-size=64M`
assert.Equal(t, int64(64*1024*1024), conf.ShmSize.Value())
assert.NoError(t, flags.Set("default-shm-size", "128M"))
assert.Equal(t, int64(128*1024*1024), conf.ShmSize.Value())
assert.Check(t, is.Equal(int64(64*1024*1024), conf.ShmSize.Value()))
assert.Check(t, flags.Set("default-shm-size", "128M"))
assert.Check(t, is.Equal(int64(128*1024*1024), conf.ShmSize.Value()))
}

View File

@@ -5,11 +5,11 @@ import (
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func defaultOptions(configFile string) *daemonOptions {
@@ -27,8 +27,8 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
opts.Debug = true
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
if !loadedConfig.Debug {
t.Fatalf("expected debug to be copied from the common flags, got false")
}
@@ -40,9 +40,9 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
opts.TLS = true
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.Equal(t, "/tmp/ca.pem", loadedConfig.CommonTLSOptions.CAFile)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, is.Equal("/tmp/ca.pem", loadedConfig.CommonTLSOptions.CAFile))
}
func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
@@ -53,9 +53,9 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
opts := defaultOptions(configFile)
flags := opts.flags
assert.NoError(t, flags.Set("config-file", configFile))
assert.NoError(t, flags.Set("label", "l1=bar"))
assert.NoError(t, flags.Set("label", "l2=baz"))
assert.Check(t, flags.Set("config-file", configFile))
assert.Check(t, flags.Set("label", "l1=bar"))
assert.Check(t, flags.Set("label", "l2=baz"))
_, err := loadDaemonCliConfig(opts)
testutil.ErrorContains(t, err, "as a flag and in the configuration file: labels")
@@ -69,9 +69,9 @@ func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) {
opts := defaultOptions(configFile)
flags := opts.flags
assert.NoError(t, flags.Set("config-file", configFile))
assert.NoError(t, flags.Set("node-generic-resource", "r1=bar"))
assert.NoError(t, flags.Set("node-generic-resource", "r2=baz"))
assert.Check(t, flags.Set("config-file", configFile))
assert.Check(t, flags.Set("node-generic-resource", "r1=bar"))
assert.Check(t, flags.Set("node-generic-resource", "r2=baz"))
_, err := loadDaemonCliConfig(opts)
testutil.ErrorContains(t, err, "as a flag and in the configuration file: node-generic-resources")
@@ -81,22 +81,22 @@ func TestLoadDaemonCliWithConflictingLabels(t *testing.T) {
opts := defaultOptions("")
flags := opts.flags
assert.NoError(t, flags.Set("label", "foo=bar"))
assert.NoError(t, flags.Set("label", "foo=baz"))
assert.Check(t, flags.Set("label", "foo=bar"))
assert.Check(t, flags.Set("label", "foo=baz"))
_, err := loadDaemonCliConfig(opts)
assert.EqualError(t, err, "conflict labels for foo=baz and foo=bar")
assert.Check(t, is.Error(err, "conflict labels for foo=baz and foo=bar"))
}
func TestLoadDaemonCliWithDuplicateLabels(t *testing.T) {
opts := defaultOptions("")
flags := opts.flags
assert.NoError(t, flags.Set("label", "foo=the-same"))
assert.NoError(t, flags.Set("label", "foo=the-same"))
assert.Check(t, flags.Set("label", "foo=the-same"))
assert.Check(t, flags.Set("label", "foo=the-same"))
_, err := loadDaemonCliConfig(opts)
assert.NoError(t, err)
assert.Check(t, err)
}
func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
@@ -107,9 +107,9 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
opts.TLSOptions.CAFile = "/tmp/ca.pem"
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.Equal(t, loadedConfig.TLS, true)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, is.Equal(loadedConfig.TLS, true))
}
func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
@@ -120,9 +120,9 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
opts.TLSOptions.CAFile = "/tmp/ca.pem"
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.True(t, loadedConfig.TLS)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, loadedConfig.TLS)
}
func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
@@ -133,9 +133,9 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
opts.TLSOptions.CAFile = "/tmp/ca.pem"
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.False(t, loadedConfig.TLS)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, !loadedConfig.TLS)
}
func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
@@ -144,10 +144,10 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.Equal(t, "warn", loadedConfig.LogLevel)
assert.Equal(t, logrus.WarnLevel, logrus.GetLevel())
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, is.Equal("warn", loadedConfig.LogLevel))
assert.Check(t, is.Equal(logrus.WarnLevel, logrus.GetLevel()))
}
func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
@@ -157,10 +157,10 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.Equal(t, "/etc/certs/ca.pem", loadedConfig.CommonTLSOptions.CAFile)
assert.Equal(t, "syslog", loadedConfig.LogConfig.Type)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, is.Equal("/etc/certs/ca.pem", loadedConfig.CommonTLSOptions.CAFile))
assert.Check(t, is.Equal("syslog", loadedConfig.LogConfig.Type))
}
func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
@@ -174,10 +174,10 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Len(t, loadedConfig.AllowNondistributableArtifacts, 1)
assert.Len(t, loadedConfig.Mirrors, 1)
assert.Len(t, loadedConfig.InsecureRegistries, 1)
assert.Check(t, is.Len(loadedConfig.AllowNondistributableArtifacts, 1))
assert.Check(t, is.Len(loadedConfig.Mirrors, 1))
assert.Check(t, is.Len(loadedConfig.InsecureRegistries, 1))
}

View File

@@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/docker/daemon/config"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
@@ -19,17 +19,17 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
opts := defaultOptions(tempFile.Path())
opts.Debug = true
opts.LogLevel = "info"
assert.NoError(t, opts.flags.Set("selinux-enabled", "true"))
assert.Check(t, opts.flags.Set("selinux-enabled", "true"))
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.True(t, loadedConfig.Debug)
assert.Equal(t, "info", loadedConfig.LogLevel)
assert.True(t, loadedConfig.EnableSelinuxSupport)
assert.Equal(t, "json-file", loadedConfig.LogConfig.Type)
assert.Equal(t, "1k", loadedConfig.LogConfig.Config["max-size"])
assert.Check(t, loadedConfig.Debug)
assert.Check(t, is.Equal("info", loadedConfig.LogLevel))
assert.Check(t, loadedConfig.EnableSelinuxSupport)
assert.Check(t, is.Equal("json-file", loadedConfig.LogConfig.Type))
assert.Check(t, is.Equal("1k", loadedConfig.LogConfig.Config["max-size"]))
}
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
@@ -39,11 +39,11 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Equal(t, "127.0.0.2", loadedConfig.IP)
assert.Equal(t, "127.0.0.1", loadedConfig.DefaultIP.String())
assert.Check(t, is.Equal("127.0.0.2", loadedConfig.IP))
assert.Check(t, is.Equal("127.0.0.1", loadedConfig.DefaultIP.String()))
}
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
@@ -56,14 +56,14 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NotNil(t, loadedConfig.ClusterOpts)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, loadedConfig.ClusterOpts != nil)
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
assert.Equal(t, expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])
assert.NotNil(t, loadedConfig.LogConfig.Config)
assert.Equal(t, "test", loadedConfig.LogConfig.Config["tag"])
assert.Check(t, is.Equal(expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"]))
assert.Check(t, loadedConfig.LogConfig.Config != nil)
assert.Check(t, is.Equal("test", loadedConfig.LogConfig.Config["tag"]))
}
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
@@ -73,17 +73,17 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.False(t, loadedConfig.EnableUserlandProxy)
assert.Check(t, !loadedConfig.EnableUserlandProxy)
// make sure reloading doesn't generate configuration
// conflicts after normalizing boolean values.
reload := func(reloadedConfig *config.Config) {
assert.False(t, reloadedConfig.EnableUserlandProxy)
assert.Check(t, !reloadedConfig.EnableUserlandProxy)
}
assert.NoError(t, config.Reload(opts.configFile, opts.flags, reload))
assert.Check(t, config.Reload(opts.configFile, opts.flags, reload))
}
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
@@ -92,8 +92,8 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
opts := defaultOptions(tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
require.NoError(t, err)
require.NotNil(t, loadedConfig)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.True(t, loadedConfig.EnableUserlandProxy)
assert.Check(t, loadedConfig.EnableUserlandProxy)
}

View File

@@ -6,8 +6,9 @@ import (
cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/daemon/config"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
)
func TestCommonOptionsInstallFlags(t *testing.T) {
@@ -20,10 +21,10 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
"--tlscert=\"/foo/cert\"",
"--tlskey=\"/foo/key\"",
})
assert.NoError(t, err)
assert.Equal(t, "/foo/cafile", opts.TLSOptions.CAFile)
assert.Equal(t, "/foo/cert", opts.TLSOptions.CertFile)
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
assert.Check(t, err)
assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))
assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile))
assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key"))
}
func defaultPath(filename string) string {
@@ -36,8 +37,8 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
opts.InstallFlags(flags)
err := flags.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, defaultPath("ca.pem"), opts.TLSOptions.CAFile)
assert.Equal(t, defaultPath("cert.pem"), opts.TLSOptions.CertFile)
assert.Equal(t, defaultPath("key.pem"), opts.TLSOptions.KeyFile)
assert.Check(t, err)
assert.Check(t, is.Equal(defaultPath("ca.pem"), opts.TLSOptions.CAFile))
assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile))
assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile))
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/system"
"github.com/pkg/errors"
)
// ResolvePath resolves the given path in the container to a resource on the
@@ -13,6 +14,9 @@ import (
// the absolute path to the resource relative to the container's rootfs, and
// an error if the path points to outside the container's rootfs.
func (container *Container) ResolvePath(path string) (resolvedPath, absPath string, err error) {
if container.BaseFS == nil {
return "", "", errors.New("ResolvePath: BaseFS of container " + container.ID + " is unexpectedly nil")
}
// Check if a drive letter supplied, it must be the system drive. No-op except on Windows
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path, container.BaseFS)
if err != nil {
@@ -45,6 +49,9 @@ func (container *Container) ResolvePath(path string) (resolvedPath, absPath stri
// resolved to a path on the host corresponding to the given absolute path
// inside the container.
func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error) {
if container.BaseFS == nil {
return nil, errors.New("StatPath: BaseFS of container " + container.ID + " is unexpectedly nil")
}
driver := container.BaseFS
lstat, err := driver.Lstat(resolvedPath)

View File

@@ -38,7 +38,7 @@ import (
"github.com/docker/docker/runconfig"
"github.com/docker/docker/volume"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
units "github.com/docker/go-units"
"github.com/docker/libnetwork"
"github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/options"
@@ -311,6 +311,9 @@ func (container *Container) SetupWorkingDirectory(rootIDs idtools.IDPair) error
// symlinking to a different path) between using this method and using the
// path. See symlink.FollowSymlinkInScope for more details.
func (container *Container) GetResourcePath(path string) (string, error) {
if container.BaseFS == nil {
return "", errors.New("GetResourcePath: BaseFS of container " + container.ID + " is unexpectedly nil")
}
// IMPORTANT - These are paths on the OS where the daemon is running, hence
// any filepath operations must be done in an OS agnostic way.
r, e := container.BaseFS.ResolveScopedPath(path, false)
@@ -391,6 +394,8 @@ func (container *Container) StartLogger() (logger.Logger, error) {
if err != nil {
return nil, err
}
container.LogPath = info.LogPath
}
l, err := initDriver(info)
@@ -974,11 +979,6 @@ func (container *Container) startLogging() error {
copier.Run()
container.LogDriver = l
// set LogPath field only for json-file logdriver
if jl, ok := l.(*jsonfilelog.JSONFileLogger); ok {
container.LogPath = jl.LogPath()
}
return nil
}

View File

@@ -1,12 +1,17 @@
package container // import "github.com/docker/docker/container"
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/docker/docker/api/types/container"
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/daemon/logger/jsonfilelog"
"github.com/docker/docker/pkg/signal"
"github.com/gotestyourself/gotestyourself/assert"
)
func TestContainerStopSignal(t *testing.T) {
@@ -66,3 +71,56 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) {
t.Fatalf("expected secret dest %q; received %q", expected, d)
}
}
func TestContainerLogPathSetForJSONFileLogger(t *testing.T) {
containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForJSONFileLogger")
assert.NilError(t, err)
defer os.RemoveAll(containerRoot)
c := &Container{
Config: &container.Config{},
HostConfig: &container.HostConfig{
LogConfig: container.LogConfig{
Type: jsonfilelog.Name,
},
},
ID: "TestContainerLogPathSetForJSONFileLogger",
Root: containerRoot,
}
logger, err := c.StartLogger()
assert.NilError(t, err)
defer logger.Close()
expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
assert.NilError(t, err)
assert.Equal(t, c.LogPath, expectedLogPath)
}
func TestContainerLogPathSetForRingLogger(t *testing.T) {
containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForRingLogger")
assert.NilError(t, err)
defer os.RemoveAll(containerRoot)
c := &Container{
Config: &container.Config{},
HostConfig: &container.HostConfig{
LogConfig: container.LogConfig{
Type: jsonfilelog.Name,
Config: map[string]string{
"mode": string(container.LogModeNonBlock),
},
},
},
ID: "TestContainerLogPathSetForRingLogger",
Root: containerRoot,
}
logger, err := c.StartLogger()
assert.NilError(t, err)
defer logger.Close()
expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
assert.NilError(t, err)
assert.Equal(t, c.LogPath, expectedLogPath)
}

View File

@@ -8,8 +8,9 @@ import (
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
)
var root string
@@ -109,56 +110,56 @@ func TestNames(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.NoError(t, db.ReserveName("name1", "containerid1"))
assert.NoError(t, db.ReserveName("name1", "containerid1")) // idempotent
assert.NoError(t, db.ReserveName("name2", "containerid2"))
assert.EqualError(t, db.ReserveName("name2", "containerid3"), ErrNameReserved.Error())
assert.Check(t, db.ReserveName("name1", "containerid1"))
assert.Check(t, db.ReserveName("name1", "containerid1")) // idempotent
assert.Check(t, db.ReserveName("name2", "containerid2"))
assert.Check(t, is.Error(db.ReserveName("name2", "containerid3"), ErrNameReserved.Error()))
// Releasing a name allows the name to point to something else later.
assert.NoError(t, db.ReleaseName("name2"))
assert.NoError(t, db.ReserveName("name2", "containerid3"))
assert.Check(t, db.ReleaseName("name2"))
assert.Check(t, db.ReserveName("name2", "containerid3"))
view := db.Snapshot()
id, err := view.GetID("name1")
assert.NoError(t, err)
assert.Equal(t, "containerid1", id)
assert.Check(t, err)
assert.Check(t, is.Equal("containerid1", id))
id, err = view.GetID("name2")
assert.NoError(t, err)
assert.Equal(t, "containerid3", id)
assert.Check(t, err)
assert.Check(t, is.Equal("containerid3", id))
_, err = view.GetID("notreserved")
assert.EqualError(t, err, ErrNameNotReserved.Error())
assert.Check(t, is.Error(err, ErrNameNotReserved.Error()))
// Releasing and re-reserving a name doesn't affect the snapshot.
assert.NoError(t, db.ReleaseName("name2"))
assert.NoError(t, db.ReserveName("name2", "containerid4"))
assert.Check(t, db.ReleaseName("name2"))
assert.Check(t, db.ReserveName("name2", "containerid4"))
id, err = view.GetID("name1")
assert.NoError(t, err)
assert.Equal(t, "containerid1", id)
assert.Check(t, err)
assert.Check(t, is.Equal("containerid1", id))
id, err = view.GetID("name2")
assert.NoError(t, err)
assert.Equal(t, "containerid3", id)
assert.Check(t, err)
assert.Check(t, is.Equal("containerid3", id))
// GetAllNames
assert.Equal(t, map[string][]string{"containerid1": {"name1"}, "containerid3": {"name2"}}, view.GetAllNames())
assert.Check(t, is.DeepEqual(map[string][]string{"containerid1": {"name1"}, "containerid3": {"name2"}}, view.GetAllNames()))
assert.NoError(t, db.ReserveName("name3", "containerid1"))
assert.NoError(t, db.ReserveName("name4", "containerid1"))
assert.Check(t, db.ReserveName("name3", "containerid1"))
assert.Check(t, db.ReserveName("name4", "containerid1"))
view = db.Snapshot()
assert.Equal(t, map[string][]string{"containerid1": {"name1", "name3", "name4"}, "containerid4": {"name2"}}, view.GetAllNames())
assert.Check(t, is.DeepEqual(map[string][]string{"containerid1": {"name1", "name3", "name4"}, "containerid4": {"name2"}}, view.GetAllNames()))
// Release containerid1's names with Delete even though no container exists
assert.NoError(t, db.Delete(&Container{ID: "containerid1"}))
assert.Check(t, db.Delete(&Container{ID: "containerid1"}))
// Reusing one of those names should work
assert.NoError(t, db.ReserveName("name1", "containerid4"))
assert.Check(t, db.ReserveName("name1", "containerid4"))
view = db.Snapshot()
assert.Equal(t, map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames())
assert.Check(t, is.DeepEqual(map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames()))
}
// Test case for GitHub issue 35920

View File

@@ -7,7 +7,7 @@ FROM aarch64/debian:jessie
RUN echo deb http://ftp.debian.org/debian jessie-backports main > /etc/apt/sources.list.d/backports.list
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev libseccomp-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM aarch64/debian:stretch
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-dev libseccomp-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM aarch64/ubuntu:trusty
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM aarch64/ubuntu:xenial
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-dev libseccomp-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -10,7 +10,7 @@ RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -10,7 +10,7 @@ RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -12,7 +12,7 @@ RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list.d
RUN apt-get update && apt-get install -y -t wheezy-backports btrfs-tools --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y apparmor bash-completion build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ubuntu:trusty
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ubuntu:xenial
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ubuntu:yakkety
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ubuntu:zesty
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -10,7 +10,7 @@ RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -10,7 +10,7 @@ RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
# GOARM is the ARM architecture version which is unrelated to the above Golang version
ENV GOARM 6
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local

View File

@@ -6,7 +6,7 @@ FROM armhf/ubuntu:trusty
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM armhf/ubuntu:xenial
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM armhf/ubuntu:yakkety
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ppc64le/ubuntu:trusty
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ppc64le/ubuntu:xenial
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libseccomp-dev libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM ppc64le/ubuntu:yakkety
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev pkg-config vim-common libseccomp-dev libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM s390x/ubuntu:xenial
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config libsystemd-dev vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -6,7 +6,7 @@ FROM s390x/ubuntu:yakkety
RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libseccomp-dev pkg-config libsystemd-dev vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -7,7 +7,7 @@ FROM amazonlinux:latest
RUN yum groupinstall -y "Development Tools"
RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ RUN yum groupinstall -y "Development Tools"
RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs
RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ RUN dnf -y upgrade
RUN dnf install -y @development-tools fedora-packager
RUN dnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ RUN dnf -y upgrade
RUN dnf install -y @development-tools fedora-packager
RUN dnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -7,7 +7,7 @@ FROM opensuse:13.2
RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build
RUN zypper --non-interactive install libbtrfs-devel device-mapper-devel glibc-static libselinux-devel pkg-config selinux-policy selinux-policy-devel systemd-devel tar git cmake vim systemd-rpm-macros
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -10,7 +10,7 @@ RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek
RUN yum groupinstall -y "Development Tools"
RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libselinux-devel pkgconfig selinux-policy selinux-policy-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -7,7 +7,7 @@ FROM oraclelinux:7
RUN yum groupinstall -y "Development Tools"
RUN yum install -y --enablerepo=ol7_optional_latest btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -7,7 +7,7 @@ FROM photon:1.0
RUN tdnf install -y wget curl ca-certificates gzip make rpm-build sed gcc linux-api-headers glibc-devel binutils libseccomp elfutils
RUN tdnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkg-config selinux-policy selinux-policy-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -9,7 +9,7 @@ RUN yum groupinstall --skip-broken -y "Development Tools"
RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs
RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ RUN yum groupinstall -y "Development Tools"
RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs
RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ RUN dnf -y upgrade
RUN dnf install -y @development-tools fedora-packager
RUN dnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -9,7 +9,7 @@ RUN zypper addrepo -n ppc64le-updates -f https://download.opensuse.org/ports/upd
RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build
RUN zypper --non-interactive install libbtrfs-devel device-mapper-devel glibc-static libselinux-devel pkg-config selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -8,7 +8,7 @@ FROM sinenomine/clefos-base-s390x
RUN touch /var/lib/rpm/* && yum groupinstall -y "Development Tools"
RUN touch /var/lib/rpm/* && yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -9,7 +9,7 @@ RUN zypper ar https://download.opensuse.org/ports/zsystems/tumbleweed/repo/oss/
RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build
RUN zypper --non-interactive install libbtrfs-devel device-mapper-devel glibc-static libselinux-devel pkg-config selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim systemd-rpm-macros
ENV GO_VERSION 1.9.4
ENV GO_VERSION 1.9.5
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local
ENV PATH $PATH:/usr/local/go/bin

View File

@@ -15,130 +15,126 @@ import (
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/registry"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)
type releaseableLayer struct {
type roLayer struct {
released bool
layerStore layer.Store
roLayer layer.Layer
rwLayer layer.RWLayer
}
func (rl *releaseableLayer) Mount() (containerfs.ContainerFS, error) {
var err error
var mountPath containerfs.ContainerFS
func (l *roLayer) DiffID() layer.DiffID {
if l.roLayer == nil {
return layer.DigestSHA256EmptyTar
}
return l.roLayer.DiffID()
}
func (l *roLayer) Release() error {
if l.released {
return nil
}
if l.roLayer != nil {
metadata, err := l.layerStore.Release(l.roLayer)
layer.LogReleaseMetadata(metadata)
if err != nil {
return errors.Wrap(err, "failed to release ROLayer")
}
}
l.roLayer = nil
l.released = true
return nil
}
func (l *roLayer) NewRWLayer() (builder.RWLayer, error) {
var chainID layer.ChainID
if rl.roLayer != nil {
chainID = rl.roLayer.ChainID()
if l.roLayer != nil {
chainID = l.roLayer.ChainID()
}
mountID := stringid.GenerateRandomID()
rl.rwLayer, err = rl.layerStore.CreateRWLayer(mountID, chainID, nil)
newLayer, err := l.layerStore.CreateRWLayer(mountID, chainID, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to create rwlayer")
}
mountPath, err = rl.rwLayer.Mount("")
rwLayer := &rwLayer{layerStore: l.layerStore, rwLayer: newLayer}
fs, err := newLayer.Mount("")
if err != nil {
// Clean up the layer if we fail to mount it here.
metadata, err := rl.layerStore.ReleaseRWLayer(rl.rwLayer)
layer.LogReleaseMetadata(metadata)
if err != nil {
logrus.Errorf("Failed to release RWLayer: %s", err)
}
rl.rwLayer = nil
rwLayer.Release()
return nil, err
}
return mountPath, nil
rwLayer.fs = fs
return rwLayer, nil
}
func (rl *releaseableLayer) Commit() (builder.ReleaseableLayer, error) {
var chainID layer.ChainID
if rl.roLayer != nil {
chainID = rl.roLayer.ChainID()
}
type rwLayer struct {
released bool
layerStore layer.Store
rwLayer layer.RWLayer
fs containerfs.ContainerFS
}
stream, err := rl.rwLayer.TarStream()
func (l *rwLayer) Root() containerfs.ContainerFS {
return l.fs
}
func (l *rwLayer) Commit() (builder.ROLayer, error) {
stream, err := l.rwLayer.TarStream()
if err != nil {
return nil, err
}
defer stream.Close()
newLayer, err := rl.layerStore.Register(stream, chainID)
var chainID layer.ChainID
if parent := l.rwLayer.Parent(); parent != nil {
chainID = parent.ChainID()
}
newLayer, err := l.layerStore.Register(stream, chainID)
if err != nil {
return nil, err
}
// TODO: An optimization would be to handle empty layers before returning
return &releaseableLayer{layerStore: rl.layerStore, roLayer: newLayer}, nil
return &roLayer{layerStore: l.layerStore, roLayer: newLayer}, nil
}
func (rl *releaseableLayer) DiffID() layer.DiffID {
if rl.roLayer == nil {
return layer.DigestSHA256EmptyTar
}
return rl.roLayer.DiffID()
}
func (rl *releaseableLayer) Release() error {
if rl.released {
func (l *rwLayer) Release() error {
if l.released {
return nil
}
if err := rl.releaseRWLayer(); err != nil {
// Best effort attempt at releasing read-only layer before returning original error.
rl.releaseROLayer()
return err
if l.fs != nil {
if err := l.rwLayer.Unmount(); err != nil {
return errors.Wrap(err, "failed to unmount RWLayer")
}
l.fs = nil
}
if err := rl.releaseROLayer(); err != nil {
return err
metadata, err := l.layerStore.ReleaseRWLayer(l.rwLayer)
layer.LogReleaseMetadata(metadata)
if err != nil {
return errors.Wrap(err, "failed to release RWLayer")
}
rl.released = true
l.released = true
return nil
}
func (rl *releaseableLayer) releaseRWLayer() error {
if rl.rwLayer == nil {
return nil
}
if err := rl.rwLayer.Unmount(); err != nil {
logrus.Errorf("Failed to unmount RWLayer: %s", err)
return err
}
metadata, err := rl.layerStore.ReleaseRWLayer(rl.rwLayer)
layer.LogReleaseMetadata(metadata)
if err != nil {
logrus.Errorf("Failed to release RWLayer: %s", err)
}
rl.rwLayer = nil
return err
}
func (rl *releaseableLayer) releaseROLayer() error {
if rl.roLayer == nil {
return nil
}
metadata, err := rl.layerStore.Release(rl.roLayer)
layer.LogReleaseMetadata(metadata)
if err != nil {
logrus.Errorf("Failed to release ROLayer: %s", err)
}
rl.roLayer = nil
return err
}
func newReleasableLayerForImage(img *image.Image, layerStore layer.Store) (builder.ReleaseableLayer, error) {
func newROLayerForImage(img *image.Image, layerStore layer.Store) (builder.ROLayer, error) {
if img == nil || img.RootFS.ChainID() == "" {
return &releaseableLayer{layerStore: layerStore}, nil
return &roLayer{layerStore: layerStore}, nil
}
// Hold a reference to the image layer so that it can't be removed before
// it is released
roLayer, err := layerStore.Get(img.RootFS.ChainID())
layer, err := layerStore.Get(img.RootFS.ChainID())
if err != nil {
return nil, errors.Wrapf(err, "failed to get layer for image %s", img.ImageID())
}
return &releaseableLayer{layerStore: layerStore, roLayer: roLayer}, nil
return &roLayer{layerStore: layerStore, roLayer: layer}, nil
}
// TODO: could this use the regular daemon PullImage ?
@@ -170,12 +166,12 @@ func (daemon *Daemon) pullForBuilder(ctx context.Context, name string, authConfi
// GetImageAndReleasableLayer returns an image and releaseable layer for a reference or ID.
// Every call to GetImageAndReleasableLayer MUST call releasableLayer.Release() to prevent
// leaking of layers.
func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ReleaseableLayer, error) {
func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
if refOrID == "" {
if !system.IsOSSupported(opts.OS) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newReleasableLayerForImage(nil, daemon.layerStores[opts.OS])
layer, err := newROLayerForImage(nil, daemon.layerStores[opts.OS])
return nil, layer, err
}
@@ -189,7 +185,7 @@ func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID st
if !system.IsOSSupported(image.OperatingSystem()) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newReleasableLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
layer, err := newROLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
return image, layer, err
}
}
@@ -201,7 +197,7 @@ func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID st
if !system.IsOSSupported(image.OperatingSystem()) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newReleasableLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
layer, err := newROLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
return image, layer, err
}

Some files were not shown because too many files have changed in this diff Show More