|
1 | 1 | # Testing Deis |
2 | 2 |
|
3 | | -Deis is a distributed system with many moving parts, which makes it of paramount importance to test every change thoroughly. |
| 3 | +Each Deis component is one among an ecosystem of such components - many of which integrate with one another - which makes testing each component thoroughly a matter of paramount importance. |
4 | 4 |
|
5 | | -Deis is also a set of components that correspond to directories in the source code repository. Most components are Docker containers, two are command-line clients, and one contains the documentation. Components have source-code level [unit tests][] and black-box type [functional tests][]. [integration tests][] verify the behavior of the components together as a system. |
| 5 | +Each Deis component includes its own suite of style checks, [unit tests][], and black-box type [functional tests][]. |
6 | 6 |
|
7 | | -GitHub pull requests for Deis are tested automatically by a Jenkins [continuous integration][] (CI) system at <https://ci.deis.io>. Contributors should run the same tests locally before proposing any changes to the Deis codebase. |
| 7 | +[Integration tests][] verify the behavior of the Deis components together as a system and are provided separatley by the [deis/workflow-e2e][workflow-e2e] project. |
8 | 8 |
|
9 | | -## Set Up the Environment |
10 | | - |
11 | | -To run all tests, you will need: |
12 | | - |
13 | | -- Vagrant 1.6.5 or later |
14 | | -- VirtualBox 4.3 or later |
15 | | -- Docker 1.8.3 |
16 | | -- PostgreSQL server |
17 | | - |
18 | | -The tests assume that you have Deis' [source code][] in your `$GOPATH`: |
19 | | - |
20 | | - $ go get -u -v github.com/deis/deis |
21 | | - $ cd $GOPATH/src/github.com/deis/deis |
22 | | - |
23 | | -## Start a Docker Registry |
24 | | - |
25 | | -Deis' functional tests build Docker images and test them locally. The images are then pushed to a [Docker registry][] so that integration tests can test them as binary artifacts--just as a real-world provisioning of Deis pulls images from the Docker Hub. |
| 9 | +GitHub pull requests for all Deis components are tested automatically by the [Travis CI][travis] [continuous integration][] system. Contributors should run the same tests locally before proposing any changes to the Deis codebase. |
26 | 10 |
|
27 | | -If you don't have a Docker registry already accessible for your testing or for continuous deployment, start one locally. |
28 | | - |
29 | | - $ make dev-registry |
30 | | - |
31 | | - To configure the registry for local Deis development: |
32 | | - export DEIS_REGISTRY=192.168.59.103:5000 |
| 11 | +## Set Up the Environment |
33 | 12 |
|
34 | | -!!! important |
35 | | - The functional tests also use several mock or example containers: **deis/test-etcd**, **deis/test-postgresql**, and **deis/mock-store**. These are built locally during a test run. |
| 13 | +Successfully executing the unit and functional tests for any Deis component requires that the [Development Environment][dev-environment] is set up first. |
36 | 14 |
|
37 | 15 | ## Run the Tests |
38 | 16 |
|
39 | | -The unit and functional tests for each component are in their respective directories. The integration tests, scripts, and supporting go packages are in the `tests/` directory in the project root. |
40 | | - |
41 | | -Scripts in the `tests/bin/` directory are the best place to start. These test individual pieces of Deis, then bring up a Vagrant cluster and test all of them as a system. They call `tests/bin/test-setup.sh` to test for important environment variables and will exit with a helpful message if any are missing. |
| 17 | +The style checks, unit tests, and functional tests for each component can all be executed via make targets: |
42 | 18 |
|
43 | | -The `test-setup.sh` script also prepares the testing environment, as well as tears it down after testing is complete. If there is a test failure, the script collects verbose component logs, compresses them, and places them in `$HOME`. If [s3cmd][] is installed and configured on the test machine, the script will instead upload the logs to Amazon S3. This is how the Jenkins CI infrastructure is configured, so that contributors have access to the logs to see how their PR failed. |
44 | | - |
45 | | -### test-integration.sh |
46 | | - |
47 | | -- runs documentation tests |
48 | | -- builds Docker images tagged with `$BUILD_TAG` |
49 | | -- runs unit and functional tests |
50 | | -- creates a 3-node Vagrant cluster |
51 | | -- pushes the Docker images to a registry |
52 | | -- provisions the cluster for Deis with the registry images |
53 | | -- runs all integration tests |
54 | | -- takes roughly an hour |
| 19 | +To execute style checks: |
55 | 20 |
|
56 | 21 | ``` |
57 | | -$ ./tests/bin/test-integration.sh |
58 | | -
|
59 | | ->>> Preparing test environment <<< |
60 | | -
|
61 | | -DEIS_ROOT=/Users/matt/Projects/src/github.com/deis/deis |
62 | | -DEIS_TEST_APP=example-dockerfile-http |
63 | | -... |
64 | | ->>> Running integration suite <<< |
65 | | -
|
66 | | -make -C tests/ test-full |
67 | | -... |
68 | | ->>> Test run complete <<< |
| 22 | +$ make test-style |
69 | 23 | ``` |
70 | 24 |
|
71 | | -### test-smoke.sh |
72 | | - |
73 | | -- runs documentation tests |
74 | | -- builds Docker images tagged with `$BUILD_TAG` |
75 | | -- runs unit and functional tests |
76 | | -- creates a 3-node Vagrant cluster |
77 | | -- pushes the Docker images to a registry |
78 | | -- provisions the cluster for Deis with the registry images |
79 | | -- runs a "smoke test" that pushes and scales an app |
80 | | -- takes roughly 45 minutes |
81 | | - |
82 | | -### test-latest.sh |
83 | | - |
84 | | -- installs the latest `deis` and `deisctl` client releases |
85 | | -- creates a 3-node Vagrant cluster |
86 | | -- provisions the cluster for Deis with latest release images |
87 | | -- runs a "smoke test" that pushes and scales an app |
88 | | -- takes roughly 30 minutes |
89 | | - |
90 | | -## Run Specific Tests |
91 | | - |
92 | | -Run the tests for a single component this way: |
| 25 | +To execute unit tests: |
93 | 26 |
|
94 | | - $ make -C database test # unit + functional |
95 | | - $ make -C controller test-unit |
96 | | - $ make -C router test-functional |
| 27 | +``` |
| 28 | +$ make test-unit |
| 29 | +``` |
97 | 30 |
|
| 31 | +To execute functional tests: |
98 | 32 |
|
99 | | -## Customize Test Runs |
| 33 | +``` |
| 34 | +$ make test-functional |
| 35 | +``` |
100 | 36 |
|
101 | | -The file `tests/bin/test-setup.sh` is the best reference to environment variables that can affect the tests' behavior. Here are some important ones: |
| 37 | +To execute style checks, unit tests, and functional tests all in one shot: |
102 | 38 |
|
103 | | -- `$HOST_IPADDR` - address on which Docker containers can communicate for the |
104 | | - functional tests, probably the host's IP or the one assigned to [Docker Machine][]. |
105 | | -- `$DEIS_TEST_APP` - name of the [Deis example app][] to use, which is cloned |
106 | | - from GitHub (default: `example-go`) |
107 | | -- `$DEIS_TEST_AUTH_KEY` - SSH key used to register with the Deis controller |
108 | | - (default: `~/.ssh/deis`) |
109 | | -- `$DEIS_TEST_SSH_KEY` - SSH key used to login to the controller machine |
110 | | - (default: `~/.vagrant.d/insecure_private_key`) |
111 | | -- `$DEIS_TEST_DOMAIN` - the domain to use for testing |
112 | | - (default: `local3.deisapp.com`) |
| 39 | +``` |
| 40 | +$ make test |
| 41 | +``` |
113 | 42 |
|
| 43 | +To execute integration tests, refer to [deis/workflow-e2e][workflow-e2e] documentation. |
114 | 44 |
|
115 | 45 | [unit tests]: http://en.wikipedia.org/wiki/Unit_testing |
116 | 46 | [functional tests]: http://en.wikipedia.org/wiki/Functional_testing |
117 | 47 | [integration tests]: http://en.wikipedia.org/wiki/Integration_testing |
| 48 | +[workflow-e2e]: https://github.com/deis/workflow-e2e |
| 49 | +[travis]: https://travis-ci.org/deis |
118 | 50 | [continuous integration]: http://en.wikipedia.org/wiki/Continuous_integration |
119 | | -[Docker Machine]: http://docs.docker.com/machine/install-machine/ |
120 | | -[source code]: https://github.com/deis/deis |
121 | | -[Docker registry]: https://github.com/docker/distribution |
122 | | -[Deis example app]: https://github.com/deis?query=example- |
123 | | -[s3cmd]: http://s3tools.org/s3cmd |
| 51 | +[dev-environment]: development-environment.md |
0 commit comments