Skip to content

Commit 4db2ea0

Browse files
committed
Add testing.md
Signed-off-by: Daniel Nephin <[email protected]>
1 parent cb91286 commit 4db2ea0

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

CONTRIBUTING.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ Fork the repository and make changes on your fork in a feature branch:
155155
your intentions, and name it XXXX-something where XXXX is the number of the
156156
issue.
157157

158-
Submit unit tests for your changes. Go has a great test framework built in; use
159-
it! Take a look at existing tests for inspiration. [Run the full test
160-
suite](https://docs.docker.com/opensource/project/test-and-docs/) on your branch before
161-
submitting a pull request.
158+
Submit tests for your changes. See [TESTING.md](./TESTING.md) for details.
162159

163160
Update the documentation when creating or modifying features. Test your
164161
documentation changes for clarity, concision, and correctness, as well as a
@@ -251,10 +248,9 @@ calling it in another file constitute a single logical unit of work. The very
251248
high majority of submissions should have a single commit, so if in doubt: squash
252249
down to one.
253250

254-
After every commit, [make sure the test suite passes]
255-
(https://docs.docker.com/opensource/project/test-and-docs/). Include documentation
256-
changes in the same pull request so that a revert would remove all traces of
257-
the feature or fix.
251+
After every commit, [make sure the test suite passes](./TESTING.md). Include
252+
documentation changes in the same pull request so that a revert would remove
253+
all traces of the feature or fix.
258254

259255
Include an issue reference like `Closes #XXXX` or `Fixes #XXXX` in commits that
260256
close an issue. Including references automatically closes the issue on a merge.

TESTING.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Testing
2+
3+
This document contains the Moby code testing guidelines. It should answer any
4+
questions you may have as an aspiring Moby contributor.
5+
6+
## Test suites
7+
8+
Moby has two test suites (and one legacy test suite):
9+
10+
* Unit tests - use standard `go test` and
11+
[testify](https://github.com/stretchr/testify) assertions. They are located in
12+
the package they test. Unit tests should be fast and test only their own
13+
package.
14+
* API integration tests - use standard `go test` and
15+
[testify](https://github.com/stretchr/testify) assertions. They are located in
16+
`./integration/<component>` directories, where `component` is: container,
17+
image, volume, etc. These tests perform HTTP requests to an API endpoint and
18+
check the HTTP response and daemon state after the call.
19+
20+
The legacy test suite `integration-cli/` is deprecated. No new tests will be
21+
added to this suite. Any tests in this suite which require updates should be
22+
ported to either the unit test suite or the new API integration test suite.
23+
24+
## Writing new tests
25+
26+
Most code changes will fall into one of the following categories.
27+
28+
### Writing tests for new features
29+
30+
New code should be covered by unit tests. If the code is difficult to test with
31+
a unit tests then that is a good sign that it should be refactored to make it
32+
easier to reuse and maintain. Consider accepting unexported interfaces instead
33+
of structs so that fakes can be provided for dependencies.
34+
35+
If the new feature includes a completely new API endpoint then a new API
36+
integration test should be added to cover the success case of that endpoint.
37+
38+
If the new feature does not include a completely new API endpoint consider
39+
adding the new API fields to the existing test for that endpoint. A new
40+
integration test should **not** be added for every new API field or API error
41+
case. Error cases should be handled by unit tests.
42+
43+
### Writing tests for bug fixes
44+
45+
Bugs fixes should include a unit test case which exercises the bug.
46+
47+
A bug fix may also include new assertions in an existing integration tests for the
48+
API endpoint.
49+
50+
## Running tests
51+
52+
To run the unit test suite:
53+
54+
```
55+
make test-unit
56+
```
57+
58+
or `hack/test/unit` from inside a `BINDDIR=. make shell` container or properly
59+
configured environment.
60+
61+
The following environment variables may be used to run a subset of tests:
62+
63+
* `TESTDIRS` - paths to directories to be tested, defaults to `./...`
64+
* `TESTFLAGS` - flags passed to `go test`, to run tests which match a pattern
65+
use `TESTFLAGS="-test.run TestNameOrPrefix"`
66+
67+
To run the integration test suite:
68+
69+
```
70+
make test-integration
71+
```

0 commit comments

Comments
 (0)