1
0
mirror of https://github.com/moby/moby.git synced 2025-09-16 18:42:34 +03:00

103 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
4b230a4909 internal/testutils: merge with internal/testutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-08 10:08:35 +02:00
Sebastiaan van Stijn
d3e45f8743 testutil: move back to internal
This package was originally internal, but was moved out when BuildKit
used it for its integration tests. That's no longer the case, so we
can make it internal again.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-08 10:08:30 +02:00
Matthieu MOREL
96f8c6395e chore: enable use-any rule from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-08-08 17:07:07 +02:00
Sebastiaan van Stijn
c17d43ae67 api/types: move ErrorResponse to common/ErrorResponse
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 14:45:10 +02:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Sebastiaan van Stijn
6adbeff449 integration-cli: remove parseEventTime utility
It was only used in a single test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 16:34:30 +02:00
Sebastiaan van Stijn
281a3f6c41 integration-cli: remove deprecaed inspectMountSourceField
The replacement is also deprecated, but at least returns a strong type,
which may help transitioning to using an api-client for these, and
removing one abstraction at a time.

Also rewriting the TestContainerAPIDeleteRemoveVolume to use the API
client (as it's part of the API suite), and touched-up the
TestRunMountShmMqueueFromHost test a bit.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 16:34:24 +02:00
Sebastiaan van Stijn
6124c00827 integration-cli: buildImageSuccessfully: don't wrap buildImage
Both are deprecated, but removing one abstraction at a time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 13:05:40 +02:00
Sebastiaan van Stijn
877529c62d integration-cli: remove deprecated inspectFieldWithError utility
The replacement is also deprecated, but removing one abstraction at a time

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 13:00:11 +02:00
Sebastiaan van Stijn
68480dc11d integration-cli: remove createTmpFile utility
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 12:48:59 +02:00
Sebastiaan van Stijn
29a7d4039e integration-cli: remove deprecated inspectFieldMap utility
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 12:32:30 +02:00
Derek McGowan
c47afd41c8 Create github.com/moby/moby/client module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:26 -07:00
Derek McGowan
afd6487b2e Create github.com/moby/moby/api module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:05 -07:00
Sebastiaan van Stijn
a30b63eafc integration-cli: remove uses of deprecated dockerCmdWithResult utility
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-06-30 13:21:30 +02:00
Matthieu MOREL
bc9ec5fc02 fix emptyStringTest from go-critic
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-07 09:57:59 +02:00
Matthieu MOREL
9b5d8cd186 fix thelper linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-05 21:42:05 +00:00
Derek McGowan
d0154d3e59 Update to use github.com/moby/go-archive
Update use of idtools to moby/user for archive and other deprecated uses

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-08 17:35:05 -07:00
Paweł Gronowski
22069f2431 integration-cli: adjust "gotest.tools/v3/assert/cmp" import alias
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-03 19:11:40 +01:00
Rob Murray
d75394bf77 Wait longer for a stable goroutine count in tests
Test 'TestDockerCLIRunSuite/TestRunAttachFailedNoLeak' does this ...

- start a container that exits immediately, its comment says:
  - "Run a dummy container to ensure all goroutines are up and running
    before we get a count"
- wait for the number of goroutines to be stable for 400ms, and remember
  that number
- start a container
- start another container, expecting it to fail with a port-mapping clash
- stop the running container
- wait for up to 30s for the number of goroutines to fall back to the
  remembered number.

In a CI run - hacking in some debug to count goroutines once a second,
before waiting for the number to stablilise for 400ms, showed that the
initial (dummy) container run had no immediate effect. But, three more
goroutines appeared within a few seconds. For example:

  === RUN   TestDockerCLIRunSuite/TestRunAttachFailedNoLeak
    docker_cli_run_test.go:3822: goroutines before container run: 47 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 47 i 0 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 1 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 2 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 3 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 4 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 5 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 6 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 7 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 8 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 9 err <nil>

That means a delay while running the rest of the test risks finding the
extra goroutines that are going to start anyway and not go away (regardless
of whether more containers are started).

So - wait for the goroutine count to be stable for 7s, rather than 400ms.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-02 18:49:02 +00:00
Rob Murray
dd7831187d Fix typo in waitForStableGourtineCount
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-02 18:48:32 +00:00
Aleksa Sarai
0553d3d994 tests: migrate away from assert.Assert(err == nil)
Unfortunately, gofmt doesn't know about types so it was necessary to
find all of the err == nil statements through trial and error. Note that
there is no is.NilError, so for assert.Check(t, err == nil) we need to
switch to just doing assert.Check(t, err). If err is an error type, this
is equivalent (and there isn't another trivial way of doing it). Here
are the full set of rules used:

Generic "err == nil":

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, err == nil) -> assert.NilError(t, err)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, err == nil) -> assert.Check(t, err)"

Generic, but with a different variable name:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, sr.err == nil) -> assert.NilError(t, sr.err)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, sr.err == nil) -> assert.Check(t, sr.err)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, err2 == nil) -> assert.NilError(t, err2)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, err2 == nil) -> assert.Check(t, err2)"

JSON-related error assertions:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.Unmarshal(a, b) == nil) -> assert.NilError(t, json.Unmarshal(a, b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.Unmarshal(a, b) == nil) -> assert.Check(t, json.Unmarshal(a, b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.NewDecoder(a).Decode(b) == nil) -> assert.NilError(t, json.NewDecoder(a).Decode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.NewDecoder(a).Decode(b) == nil) -> assert.Check(t, json.NewDecoder(a).Decode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.NewEncoder(a).Encode(b) == nil) -> assert.NilError(t, json.NewEncoder(a).Encode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.NewEncoder(a).Encode(b) == nil) -> assert.Check(t, json.NewEncoder(a).Encode(b))"

Process-related error assertions:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Start() == nil) -> assert.NilError(t, a.Start())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Start() == nil) -> assert.Check(t, a.Start())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Kill() == nil) -> assert.NilError(t, a.Kill())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Kill() == nil) -> assert.Check(t, a.Kill())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Signal(b) == nil) -> assert.NilError(t, a.Signal(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Signal(b) == nil) -> assert.Check(t, a.Signal(b))"

waitInspect:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, waitInspect(a, b, c, d) == nil) -> assert.NilError(t, waitInspect(a, b, c, d))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, waitInspect(a, b, c, d) == nil) -> assert.Check(t, waitInspect(a, b, c, d))"

File closing error assertions:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Close() == nil) -> assert.NilError(t, a.Close())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Close() == nil) -> assert.Check(t, a.Close())"

mount.MakeRShared:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, mount.MakeRShared(a) == nil) -> assert.NilError(t, mount.MakeRShared(a))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, mount.MakeRShared(a) == nil) -> assert.Check(t, mount.MakeRShared(a))"

daemon.SwarmLeave:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, d.SwarmLeave(a, b, c) == nil) -> assert.NilError(t, d.SwarmLeave(a, b, c))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, d.SwarmLeave(a, b, c) == nil) -> assert.Check(t, d.SwarmLeave(a, b, c))"

os.MkdirAll:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, os.MkdirAll(a, b) == nil) -> assert.NilError(t, os.MkdirAll(a, b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, os.MkdirAll(a, b) == nil) -> assert.Check(t, os.MkdirAll(a, b))"

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:20 +11:00
Sebastiaan van Stijn
8e76998aee integration-cli: loadSpecialImage: fix shadowed variables (govet)
integration-cli/docker_utils_test.go:492:3: shadow: declaration of "line" shadows declaration at line 491 (govet)
            line := strings.TrimSpace(line)
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:54:53 +01:00
Sebastiaan van Stijn
0d1c645919 integration-cli: writeFile: fix file permissions (gosec)
integration-cli/docker_utils_test.go:187:12: G302: Expect file permissions to be 0600 or less (gosec)
        f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o700)
                  ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:50:20 +01:00
Sebastiaan van Stijn
6ca0d3b1b1 integration-cli: inspectMountPoint: fix implicit memory aliasing (gosec)
integration-cli/docker_utils_test.go:149:8: G601: Implicit memory aliasing in for loop. (gosec)
                m = &c
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:50:20 +01:00
Nathan Baulch
59eba0ae13 Fix typos
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
2024-09-06 21:53:09 +10:00
Sebastiaan van Stijn
b79a4696ee integration-cli: fix non-constant format string in call (govet)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:39 +02:00
Sebastiaan van Stijn
5517322cf9 api/types: move MountPoint to api/types/container
This moves the `MountPoint` type to the container package, and
deprecates the old location.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 12:46:47 +02:00
Paweł Gronowski
a6e7e67d3a specialimage: Return optional ocispec.Index
To ease accessing image descriptors in tests.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-03-07 16:25:30 +01:00
Paweł Gronowski
bc94dfc7d2 hack: Load special images on demand
Rewrite `.build-empty-images` shell script that produced special images
(emptyfs with no layers, and empty danglign image) to a Go functions
that construct the same archives in a temporary directory.

Use them to load these images on demand only in the tests that need
them.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-12-06 17:16:37 +01:00
Sebastiaan van Stijn
5a72ed3406 integration-cli: remove deprecated dockerCmd and waitRun utilities
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-19 18:02:30 +02:00
Sebastiaan van Stijn
eafb618594 integration-cli: findContainerIP: replace dockerCmd
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-19 17:38:45 +02:00
Brian Goff
e8dc902781 Wire up tests to support otel tracing
Integration tests will now configure clients to propagate traces as well
as create spans for all tests.

Some extra changes were needed (or desired for trace propagation) in the
test helpers to pass through tracing spans via context.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-09-07 18:38:22 +00:00
Sebastiaan van Stijn
225e2562c9 integration-cli: format code with gofumpt
Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-29 00:08:27 +02:00
Sebastiaan van Stijn
3beda17773 integration-cli: rename vars that collided with imports
- use apiClient for api-clients to reduce shadowing (also more "accurate")
- use "ctr" instead of "container"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-03 20:01:05 +02:00
Sebastiaan van Stijn
018347f802 integration-cli: remove waitInspectWithArgs()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-29 18:26:12 +01:00
Sebastiaan van Stijn
61c434c030 integration-cli: remove inspectMountPointJSON()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-29 18:26:00 +01:00
Sebastiaan van Stijn
940730093b integration-cli: remove cli.Build(), cli.Inspect()
They were just small wrappers arround cli.Args(), and the abstraction
made one wonder if they were doing some "magic" things, but they weren't,
so just inlining the `cli.Args()` makes it more transparent what's executed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-28 09:25:27 +01:00
Sebastiaan van Stijn
abaf4b25d7 integration-cli: remove some redundant fmt.Sprintf()'s
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-15 12:50:21 +01:00
Sebastiaan van Stijn
89f63f476b integration-cli: SA5011: possible nil pointer dereference (staticcheck)
I think the original intent here was to make passing t optional (62a856e912),
but it looks like that's not done anywhere, so let's remove it.

    integration-cli/docker_utils_test.go:81:2: SA5011: possible nil pointer dereference (staticcheck)
        c.Helper()
        ^
    integration-cli/docker_utils_test.go:84:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
        if c != nil {
           ^
    integration-cli/docker_utils_test.go:106:2: SA5011: possible nil pointer dereference (staticcheck)
        c.Helper()
        ^
    integration-cli/docker_utils_test.go:108:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
        if c != nil {
           ^
    integration-cli/docker_utils_test.go:116:2: SA5011: possible nil pointer dereference (staticcheck)
        c.Helper()
        ^
    integration-cli/docker_utils_test.go:118:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
        if c != nil {
           ^
    integration-cli/docker_utils_test.go:126:2: SA5011: possible nil pointer dereference (staticcheck)
        c.Helper()
        ^
    integration-cli/docker_utils_test.go:128:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
        if c != nil {
           ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-08 09:43:28 +01:00
Eng Zer Jun
c55a4ac779 refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-08-27 14:56:57 +08:00
Brian Goff
601707a655 TestPushMultipleTags: Add support for 20.10 CLI
In 20.10 we no longer implicitly push all tags and require a
"--all-tags" flag, so add this to the test when the CLI is >= 20.10

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-03-18 19:26:17 +00:00
Sebastiaan van Stijn
9f0b3f5609 bump gotest.tools v3.0.1 for compatibility with Go 1.14
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 00:06:42 +01:00
Sebastiaan van Stijn
67e4d36e46 integration-cli: remove unused functions and enable disabled tests
```
14:26:43 integration-cli/docker_cli_pull_local_test.go:64:6: U1000: func `testConcurrentPullWholeRepo` is unused (unused)
14:26:43 func testConcurrentPullWholeRepo(c *check.C) {
14:26:43      ^
14:26:43 integration-cli/docker_cli_pull_local_test.go:111:31: U1000: func `(*DockerRegistrySuite).testConcurrentPullWholeRepo` is unused (unused)
14:26:43 func (s *DockerRegistrySuite) testConcurrentPullWholeRepo(c *check.C) {
14:26:43                               ^
14:26:43 integration-cli/docker_cli_pull_local_test.go:115:38: U1000: func `(*DockerSchema1RegistrySuite).testConcurrentPullWholeRepo` is unused (unused)
14:26:43 func (s *DockerSchema1RegistrySuite) testConcurrentPullWholeRepo(c *check.C) {
14:26:43                                      ^
14:26:43 integration-cli/docker_cli_pull_local_test.go:120:6: U1000: func `testConcurrentFailingPull` is unused (unused)
14:26:43 func testConcurrentFailingPull(c *check.C) {
14:26:43      ^
14:26:43 integration-cli/docker_cli_pull_local_test.go:142:31: U1000: func `(*DockerRegistrySuite).testConcurrentFailingPull` is unused (unused)
14:26:43 func (s *DockerRegistrySuite) testConcurrentFailingPull(c *check.C) {
14:26:43                               ^
14:26:43 integration-cli/docker_cli_pull_local_test.go:146:38: U1000: func `(*DockerSchema1RegistrySuite).testConcurrentFailingPull` is unused (unused)
14:26:43 func (s *DockerSchema1RegistrySuite) testConcurrentFailingPull(c *check.C) {

14:26:43 integration-cli/docker_utils_test.go:170:6: U1000: func `inspectImage` is unused (unused)
14:26:43 func inspectImage(c *check.C, name, filter string) string {
14:26:43      ^
14:26:43 integration-cli/events_utils_test.go:196:6: U1000: func `parseEventsWithID` is unused (unused)
14:26:43 func parseEventsWithID(c *check.C, out, match, id string) {
14:26:43      ^
14:26:43 integration-cli/fixtures_linux_daemon_test.go:17:6: U1000: type `testingT` is unused (unused)
14:26:43 type testingT interface {
14:26:43      ^
14:26:43 integration-cli/fixtures_linux_daemon_test.go:19:2: U1000: func `testingT.Fatalf` is unused (unused)
14:26:43 	Fatalf(string, ...interface{})
14:26:43 	^
14:26:43 integration-cli/fixtures_linux_daemon_test.go:22:6: U1000: type `logT` is unused (unused)
14:26:43 type logT interface {
14:26:43      ^
14:26:43 integration-cli/fixtures_linux_daemon_test.go:23:2: U1000: func `logT.Logf` is unused (unused)
14:26:43 	Logf(string, ...interface{})
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-18 12:56:59 +02:00
Sebastiaan van Stijn
0fabf3e41e integration-cli: remove unneeded fmt.Sprintf() in asserts
Replaced using a bit of grep-ing;

```
find . -name "*_test.go" -exec sed -E -i 's#assert.Assert\((.*), fmt.Sprintf\((.*)\)\)$#assert.Assert\(\1, \2\)#g' '{}' \;
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 16:18:04 +02:00
Tibor Vass
231ed42cab integration-cli: remove TestingT
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-10 00:25:01 +00:00
Tibor Vass
8eb9f3f90e integration-cli: fix pollCheck
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:47:44 +00:00
Tibor Vass
bad6f3bf73 integration-cli: have helper functions use testing.Helper()
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:57 +00:00
Tibor Vass
649201dc44 remove waitAndAssert and type casts
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:57 +00:00
Tibor Vass
42599f1cad prepare for eg on waitAndAssert
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:57 +00:00
Tibor Vass
318b1612e1 fix remaining compile issues
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:57 +00:00