- Update links to use the correct (v3) version.
- Slightly touch-up examples.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -8,11 +8,11 @@ questions you may have as an aspiring Moby contributor. |
| 8 | 8 |
Moby has two test suites (and one legacy test suite): |
| 9 | 9 |
|
| 10 | 10 |
* Unit tests - use standard `go test` and |
| 11 |
- [gotest.tools/assert](https://godoc.org/gotest.tools/assert) assertions. They are located in |
|
| 11 |
+ [gotest.tools/v3/assert](https://pkg.go.dev/gotest.tools/v3/assert) assertions. They are located in |
|
| 12 | 12 |
the package they test. Unit tests should be fast and test only their own |
| 13 | 13 |
package. |
| 14 | 14 |
* API integration tests - use standard `go test` and |
| 15 |
- [gotest.tools/assert](https://godoc.org/gotest.tools/assert) assertions. They are located in |
|
| 15 |
+ [gotest.tools/v3/assert](https://pkg.go.dev/gotest.tools/v3/assert) assertions. They are located in |
|
| 16 | 16 |
`./integration/<component>` directories, where `component` is: container, |
| 17 | 17 |
image, volume, etc. These tests perform HTTP requests to an API endpoint and |
| 18 | 18 |
check the HTTP response and daemon state after the call. |
| ... | ... |
@@ -57,17 +57,28 @@ Instead, implement new tests under `integration/`. |
| 57 | 57 |
### Integration tests environment considerations |
| 58 | 58 |
|
| 59 | 59 |
When adding new tests or modifying existing tests under `integration/`, testing |
| 60 |
-environment should be properly considered. `skip.If` from |
|
| 61 |
-[gotest.tools/skip](https://godoc.org/gotest.tools/skip) can be used to make the |
|
| 60 |
+environment should be properly considered. [`skip.If`](https://pkg.go.dev/gotest.tools/v3/skip#If) from |
|
| 61 |
+[gotest.tools/v3/skip](https://pkg.go.dev/gotest.tools/v3/skip) can be used to make the |
|
| 62 | 62 |
test run conditionally. Full testing environment conditions can be found at |
| 63 |
-[environment.go](https://github.com/moby/moby/blob/6b6eeed03b963a27085ea670f40cd5ff8a61f32e/testutil/environment/environment.go) |
|
| 63 |
+[environment.go](https://github.com/moby/moby/blob/311b2c87e125c6d4198014369e313135cf928a8a/testutil/environment/environment.go) |
|
| 64 | 64 |
|
| 65 | 65 |
Here is a quick example. If the test needs to interact with a docker daemon on |
| 66 | 66 |
the same host, the following condition should be checked within the test code |
| 67 | 67 |
|
| 68 | 68 |
```go |
| 69 |
-skip.If(t, testEnv.IsRemoteDaemon()) |
|
| 70 |
-// your integration test code |
|
| 69 |
+package example |
|
| 70 |
+ |
|
| 71 |
+import ( |
|
| 72 |
+ "testing" |
|
| 73 |
+ |
|
| 74 |
+ "gotest.tools/v3/skip" |
|
| 75 |
+) |
|
| 76 |
+ |
|
| 77 |
+func TestSomething(t *testing.T) {
|
|
| 78 |
+ skip.If(t, testEnv.IsRemoteDaemon(), "test requires a local daemon") |
|
| 79 |
+ |
|
| 80 |
+ // your integration test code |
|
| 81 |
+} |
|
| 71 | 82 |
``` |
| 72 | 83 |
|
| 73 | 84 |
If a remote daemon is detected, the test will be skipped. |
| ... | ... |
@@ -78,11 +89,11 @@ If a remote daemon is detected, the test will be skipped. |
| 78 | 78 |
|
| 79 | 79 |
To run the unit test suite: |
| 80 | 80 |
|
| 81 |
-``` |
|
| 81 |
+```bash |
|
| 82 | 82 |
make test-unit |
| 83 | 83 |
``` |
| 84 | 84 |
|
| 85 |
-or `hack/test/unit` from inside a `BINDDIR=. make shell` container or properly |
|
| 85 |
+or `hack/test/unit` from inside a `make shell` container or properly |
|
| 86 | 86 |
configured environment. |
| 87 | 87 |
|
| 88 | 88 |
The following environment variables may be used to run a subset of tests: |
| ... | ... |
@@ -95,7 +106,7 @@ The following environment variables may be used to run a subset of tests: |
| 95 | 95 |
|
| 96 | 96 |
To run the integration test suite: |
| 97 | 97 |
|
| 98 |
-``` |
|
| 98 |
+```bash |
|
| 99 | 99 |
make test-integration |
| 100 | 100 |
``` |
| 101 | 101 |
|
| ... | ... |
@@ -121,6 +132,6 @@ automatically set the other above mentioned environment variables accordingly. |
| 121 | 121 |
You can change a version of golang used for building stuff that is being tested |
| 122 | 122 |
by setting `GO_VERSION` variable, for example: |
| 123 | 123 |
|
| 124 |
-``` |
|
| 125 |
-make GO_VERSION=1.12.8 test |
|
| 124 |
+```bash |
|
| 125 |
+make GO_VERSION=1.24.5 test |
|
| 126 | 126 |
``` |