2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Run tests and test documentation"
|
|
|
|
description = "Describes Docker's testing infrastructure"
|
|
|
|
keywords = ["make test, make docs, Go tests, gofmt, contributing, running tests"]
|
|
|
|
[menu.main]
|
2015-06-16 09:04:13 -04:00
|
|
|
parent = "smn_develop"
|
|
|
|
weight=6
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
# Run tests and test documentation
|
|
|
|
|
|
|
|
Contributing includes testing your changes. If you change the Docker code, you
|
|
|
|
may need to add a new test or modify an existing one. Your contribution could
|
|
|
|
even be adding tests to Docker. For this reason, you need to know a little
|
|
|
|
about Docker's test infrastructure.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
Many contributors contribute documentation only. Or, a contributor makes a code
|
|
|
|
contribution that changes how Docker behaves and that change needs
|
|
|
|
documentation. For these reasons, you also need to know how to build, view, and
|
|
|
|
test the Docker documentation.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
In this section, you run tests in the `dry-run-test` branch of your Docker
|
|
|
|
fork. If you have followed along in this guide, you already have this branch.
|
|
|
|
If you don't have this branch, you can create it or simply use another of your
|
|
|
|
branches.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
## Understand testing at Docker
|
|
|
|
|
|
|
|
Docker tests use the Go language's test framework. In this framework, files
|
|
|
|
whose names end in `_test.go` contain test code; you'll find test files like
|
|
|
|
this throughout the Docker repo. Use these files for inspiration when writing
|
|
|
|
your own tests. For information on Go's test framework, see <a
|
|
|
|
href="http://golang.org/pkg/testing/" target="_blank">Go's testing package
|
|
|
|
documentation</a> and the <a href="http://golang.org/cmd/go/#hdr-Test_packages"
|
|
|
|
target="_blank">go test help</a>.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
You are responsible for _unit testing_ your contribution when you add new or
|
|
|
|
change existing Docker code. A unit test is a piece of code that invokes a
|
|
|
|
single, small piece of code ( _unit of work_ ) to verify the unit works as
|
|
|
|
expected.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
Depending on your contribution, you may need to add _integration tests_. These
|
|
|
|
are tests that combine two or more work units into one component. These work
|
|
|
|
units each have unit tests and then, together, integration tests that test the
|
|
|
|
interface between the components. The `integration` and `integration-cli`
|
|
|
|
directories in the Docker repository contain integration test code.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-04-25 14:57:01 -04:00
|
|
|
Testing is its own specialty. If you aren't familiar with testing techniques,
|
2015-03-07 08:06:40 -05:00
|
|
|
there is a lot of information available to you on the Web. For now, you should
|
|
|
|
understand that, the Docker maintainers may ask you to write a new test or
|
|
|
|
change an existing one.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
### Run tests on your local host
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
Before submitting any code change, you should run the entire Docker test suite.
|
|
|
|
The `Makefile` contains a target for the entire test suite. The target's name
|
2015-09-17 11:37:50 -04:00
|
|
|
is simply `test`. The `Makefile` contains several targets for testing:
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
<style type="text/css">
|
2015-03-08 10:41:08 -04:00
|
|
|
.monospaced {font-family: Monaco, Consolas, "Lucida Console", monospace !important;}
|
2015-03-06 13:01:31 -05:00
|
|
|
</style>
|
2015-03-08 10:41:08 -04:00
|
|
|
<table>
|
2015-03-06 13:01:31 -05:00
|
|
|
<tr>
|
2015-03-07 08:06:40 -05:00
|
|
|
<th>Target</th>
|
|
|
|
<th>What this target does</th>
|
2015-03-06 13:01:31 -05:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-03-08 10:41:08 -04:00
|
|
|
<td class="monospaced">test</td>
|
2015-03-07 08:06:40 -05:00
|
|
|
<td>Run all the tests.</td>
|
2015-03-06 13:01:31 -05:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-03-08 10:41:08 -04:00
|
|
|
<td class="monospaced">test-unit</td>
|
2015-03-07 08:06:40 -05:00
|
|
|
<td>Run just the unit tests.</td>
|
2015-03-06 13:01:31 -05:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-03-08 10:41:08 -04:00
|
|
|
<td class="monospaced">test-integration-cli</td>
|
2015-03-07 08:06:40 -05:00
|
|
|
<td>Run the test for the integration command line interface.</td>
|
2015-03-06 13:01:31 -05:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-03-08 10:41:08 -04:00
|
|
|
<td class="monospaced">test-docker-py</td>
|
2015-03-07 08:06:40 -05:00
|
|
|
<td>Run the tests for Docker API client.</td>
|
2015-03-06 13:01:31 -05:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
Run the entire test suite on your current repository:
|
|
|
|
|
|
|
|
1. Open a terminal on your local host.
|
|
|
|
|
|
|
|
2. Change to the root your Docker repository.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ cd docker-fork
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
3. Make sure you are in your development branch.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ git checkout dry-run-test
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
4. Run the `make test` command.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ make test
|
|
|
|
|
|
|
|
This command does several things, it creates a container temporarily for
|
|
|
|
testing. Inside that container, the `make`:
|
|
|
|
|
|
|
|
* creates a new binary
|
|
|
|
* cross-compiles all the binaries for the various operating systems
|
2015-06-07 03:07:04 -04:00
|
|
|
* runs all the tests in the system
|
2015-03-07 08:06:40 -05:00
|
|
|
|
2015-09-18 22:24:16 -04:00
|
|
|
It can take approximate one hour to run all the tests. The time depends
|
|
|
|
on your host performance. The default timeout is 60 minutes, which is
|
|
|
|
defined in hack/make.sh(${TIMEOUT:=60m}). You can modify the timeout
|
|
|
|
value on the basis of your host performance. When they complete
|
2015-03-07 08:06:40 -05:00
|
|
|
successfully, you see the output concludes with something like this:
|
|
|
|
|
|
|
|
|
|
|
|
[PASSED]: top - sleep process should be listed in privileged mode
|
|
|
|
[PASSED]: version - verify that it works and that the output is properly formatted
|
|
|
|
PASS
|
|
|
|
coverage: 70.8% of statements
|
|
|
|
---> Making bundle: test-docker-py (in bundles/1.5.0-dev/test-docker-py)
|
2015-07-22 15:37:17 -04:00
|
|
|
+++ exec docker daemon --debug --host unix:///go/src/github.com/docker/docker/bundles/1.5.0-dev/test-docker-py/docker.sock --storage-driver vfs --exec-driver native --pidfile /go/src/github.com/docker/docker/bundles/1.5.0-dev/test-docker-py/docker.pid
|
2015-03-07 08:06:40 -05:00
|
|
|
.................................................................
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Ran 65 tests in 89.266s
|
|
|
|
|
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
### Run test targets inside the development container
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
If you are working inside a Docker development container, you use the
|
2015-03-12 22:16:56 -04:00
|
|
|
`hack/make.sh` script to run tests. The `hack/make.sh` script doesn't
|
2015-03-07 08:06:40 -05:00
|
|
|
have a single target that runs all the tests. Instead, you provide a single
|
2015-03-26 15:18:27 -04:00
|
|
|
command line with multiple targets that does the same thing.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
Try this now.
|
|
|
|
|
|
|
|
1. Open a terminal and change to the `docker-fork` root.
|
|
|
|
|
|
|
|
2. Start a Docker development image.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
If you are following along with this guide, you should have a
|
|
|
|
`dry-run-test` image.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ docker run --privileged --rm -ti -v `pwd`:/go/src/github.com/docker/docker dry-run-test /bin/bash
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-12 22:16:56 -04:00
|
|
|
3. Run the tests using the `hack/make.sh` script.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-05-12 18:39:57 -04:00
|
|
|
root@5f8630b873fe:/go/src/github.com/docker/docker# hack/make.sh dynbinary binary cross test-unit test-integration-cli test-docker-py
|
2015-03-07 08:06:40 -05:00
|
|
|
|
|
|
|
The tests run just as they did within your local host.
|
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
Of course, you can also run a subset of these targets too. For example, to run
|
|
|
|
just the unit tests:
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-12 22:16:56 -04:00
|
|
|
root@5f8630b873fe:/go/src/github.com/docker/docker# hack/make.sh dynbinary binary cross test-unit
|
2015-03-07 08:06:40 -05:00
|
|
|
|
|
|
|
Most test targets require that you build these precursor targets first:
|
|
|
|
`dynbinary binary cross`
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Running individual or multiple named tests
|
|
|
|
|
2015-04-22 16:19:14 -04:00
|
|
|
We use [gocheck](https://labix.org/gocheck) for our integration-cli tests.
|
2015-03-07 08:06:40 -05:00
|
|
|
You can use the `TESTFLAGS` environment variable to run a single test. The
|
|
|
|
flag's value is passed as arguments to the `go test` command. For example, from
|
|
|
|
your local host you can run the `TestBuild` test with this command:
|
|
|
|
|
2015-04-30 03:40:48 -04:00
|
|
|
$ TESTFLAGS='-check.f DockerSuite.TestBuild*' make test-integration-cli
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
To run the same test inside your Docker development container, you do this:
|
|
|
|
|
2015-04-30 03:40:48 -04:00
|
|
|
root@5f8630b873fe:/go/src/github.com/docker/docker# TESTFLAGS='-check.f TestBuild*' hack/make.sh binary test-integration-cli
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
## Testing the Windows binary against a Linux daemon
|
2015-03-10 14:21:09 -04:00
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
This explains how to test the Windows binary on a Windows machine set up as a
|
|
|
|
development environment. The tests will be run against a docker daemon
|
|
|
|
running on a remote Linux machine. You'll use **Git Bash** that came with the
|
|
|
|
Git for Windows installation. **Git Bash**, just as it sounds, allows you to
|
|
|
|
run a Bash terminal on Windows.
|
2015-03-10 14:21:09 -04:00
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
1. If you don't have one open already, start a Git Bash terminal.
|
2015-03-10 14:21:09 -04:00
|
|
|
|
|
|
|
![Git Bash](/project/images/git_bash.png)
|
|
|
|
|
|
|
|
2. Change to the `docker` source directory.
|
|
|
|
|
|
|
|
$ cd /c/gopath/src/github.com/docker/docker
|
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
3. Set `DOCKER_REMOTE_DAEMON` as follows:
|
|
|
|
|
|
|
|
$ export DOCKER_REMOTE_DAEMON=1
|
2015-03-10 14:21:09 -04:00
|
|
|
|
|
|
|
4. Set `DOCKER_TEST_HOST` to the `tcp://IP_ADDRESS:2376` value; substitute your
|
2015-08-05 12:21:45 -04:00
|
|
|
Linux machines actual IP address. For example:
|
2015-03-10 14:21:09 -04:00
|
|
|
|
2015-08-05 16:22:39 -04:00
|
|
|
$ export DOCKER_TEST_HOST=tcp://213.124.23.200:2376
|
2015-03-10 14:21:09 -04:00
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
5. Make the binary and run the tests:
|
2015-03-10 14:21:09 -04:00
|
|
|
|
|
|
|
$ hack/make.sh binary test-integration-cli
|
|
|
|
|
2015-08-05 12:21:45 -04:00
|
|
|
Some tests are skipped on Windows for various reasons. You can see which
|
|
|
|
tests were skipped by re-running the make and passing in the
|
|
|
|
`TESTFLAGS='-test.v'` value. For example
|
|
|
|
|
|
|
|
$ TESTFLAGS='-test.v' hack/make.sh binary test-integration-cli
|
|
|
|
|
|
|
|
Should you wish to run a single test such as one with the name
|
|
|
|
'TestExample', you can pass in `TESTFLAGS='-check.f TestExample'`. For
|
|
|
|
example
|
|
|
|
|
|
|
|
$TESTFLAGS='-check.f TestExample' hack/make.sh binary test-integration-cli
|
2015-03-10 14:21:09 -04:00
|
|
|
|
|
|
|
You can now choose to make changes to the Docker source or the tests. If you
|
|
|
|
make any changes just run these commands again.
|
|
|
|
|
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
## Build and test the documentation
|
|
|
|
|
2015-06-16 06:14:37 -04:00
|
|
|
The Docker documentation source files are under `docs`. The content is
|
2015-03-06 13:01:31 -05:00
|
|
|
written using extended Markdown. We use the static generator <a
|
|
|
|
href="http://www.mkdocs.org/" target="_blank">MkDocs</a> to build Docker's
|
|
|
|
documentation. Of course, you don't need to install this generator
|
|
|
|
to build the documentation, it is included with container.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
You should always check your documentation for grammar and spelling. The best
|
|
|
|
way to do this is with <a href="http://www.hemingwayapp.com/"
|
|
|
|
target="_blank">an online grammar checker</a>.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
When you change a documentation source file, you should test your change
|
|
|
|
locally to make sure your content is there and any links work correctly. You
|
|
|
|
can build the documentation from the local host. The build starts a container
|
|
|
|
and loads the documentation into a server. As long as this container runs, you
|
|
|
|
can browse the docs.
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
1. In a terminal, change to the root of your `docker-fork` repository.
|
|
|
|
|
2015-03-26 00:52:32 -04:00
|
|
|
$ cd ~/repos/docker-fork
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
2. Make sure you are in your feature branch.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ git status
|
|
|
|
On branch dry-run-test
|
|
|
|
Your branch is up-to-date with 'origin/dry-run-test'.
|
|
|
|
nothing to commit, working directory clean
|
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
3. Build the documentation.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
$ make docs
|
|
|
|
|
|
|
|
When the build completes, you'll see a final output message similar to the
|
|
|
|
following:
|
|
|
|
|
|
|
|
Successfully built ee7fe7553123
|
|
|
|
docker run --rm -it -e AWS_S3_BUCKET -e NOCACHE -p 8000:8000 "docker-docs:dry-run-test" mkdocs serve
|
|
|
|
Running at: http://0.0.0.0:8000/
|
|
|
|
Live reload enabled.
|
|
|
|
Hold ctrl+c to quit.
|
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
4. Enter the URL in your browser.
|
|
|
|
|
2015-08-05 12:07:11 -04:00
|
|
|
If you are using Docker Machine, replace the default localhost address
|
2015-03-07 08:06:40 -05:00
|
|
|
(0.0.0.0) with your DOCKERHOST value. You can get this value at any time by
|
2015-08-05 12:07:11 -04:00
|
|
|
entering `docker-machine ip <machine-name>` at the command line.
|
2015-03-07 08:06:40 -05:00
|
|
|
|
2015-03-06 13:01:31 -05:00
|
|
|
5. Once in the documentation, look for the red notice to verify you are seeing the correct build.
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
![Beta documentation](/project/images/red_notice.png)
|
2015-03-06 13:01:31 -05:00
|
|
|
|
|
|
|
6. Navigate to your new or changed document.
|
|
|
|
|
|
|
|
7. Review both the content and the links.
|
|
|
|
|
|
|
|
8. Return to your terminal and exit out of the running documentation container.
|
|
|
|
|
|
|
|
|
|
|
|
## Where to go next
|
|
|
|
|
2015-03-07 08:06:40 -05:00
|
|
|
Congratulations, you have successfully completed the basics you need to
|
|
|
|
understand the Docker test framework. In the next steps, you use what you have
|
|
|
|
learned so far to [contribute to Docker by working on an
|
|
|
|
issue](/project/make-a-contribution/).
|