Skip to content

Commit c0b7a32

Browse files
committed
docs(testing): add better instructions for contributors
1 parent 1e0c1a5 commit c0b7a32

5 files changed

Lines changed: 215 additions & 114 deletions

File tree

docs/contributing/hacking.rst

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ target to spin up a quick, disposable registry inside a Docker container.
8888
To configure the registry for local Deis development:
8989
export DEV_REGISTRY=192.168.59.103:5000
9090
91-
If you are developing elsewhere, you must setup the registry yourself.
91+
If you are developing elsewhere, you must set up a registry yourself.
9292
Make sure it meets the following requirements:
9393

9494
#. You can push Docker images from your workstation
@@ -124,7 +124,7 @@ Test Your Changes
124124
-----------------
125125

126126
Deis ships with a comprehensive suite of automated tests, most written in Go.
127-
You can find instructions for `running the tests`_ under the ``tests/`` directory.
127+
See :ref:`testing` for instructions on running the tests.
128128

129129
Useful Commands
130130
---------------
@@ -164,45 +164,11 @@ Django Shell
164164
165165
Have commands other Deis developers might find useful? Send us a PR!
166166

167-
Standards & Test Coverage
168-
-------------------------
169-
170-
When changing Python code in the Deis project, keep in mind our :ref:`standards`.
171-
Specifically, when you change local code, you must run ``make flake8 && make coverage``,
172-
then check the HTML report to see that test coverage has improved as a result of your
173-
changes and new unit tests.
174-
175-
.. code-block:: console
176-
177-
$ make flake8
178-
flake8
179-
./api/models.py:17:1: F401 'Group' imported but unused
180-
./api/models.py:81:1: F841 local variable 'result' is assigned to but never used
181-
make: *** [flake8] Error 1
182-
$
183-
$ make coverage
184-
coverage run manage.py test --noinput api web
185-
WARNING Cannot synchronize with etcd cluster
186-
Creating test database for alias 'default'...
187-
...............................................
188-
----------------------------------------------------------------------
189-
Ran 47 tests in 47.768s
190-
191-
OK
192-
Destroying test database for alias 'default'...
193-
coverage html
194-
$ head -n 25 htmlcov/index.html | grep pc_cov
195-
<span class='pc_cov'>81%</span>
196-
197167
Pull Requests
198168
-------------
199169

200-
Please create a GitHub `pull request`_ for any code changes that will benefit Deis users
201-
in general. This workflow helps changesets map well to discrete features.
202-
203-
Creating a pull request on the Deis repository also runs an integration test on
204-
http://ci.deis.io to ensure the pull request doesn't break any tests or reduce code
205-
coverage.
170+
Please read :ref:`standards`. It contains a checklist of things you should do
171+
when proposing a change to Deis.
206172

207173
.. _`easy-fix`: https://github.com/deis/deis/issues?labels=easy-fix&state=open
208174
.. _`deisctl`: https://github.com/deis/deis/deisctl

docs/contributing/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Contributing
99

1010
.. toctree::
1111

12-
1312
overview
1413
hacking
14+
testing
1515
standards
1616
community
1717
conduct

docs/contributing/standards.rst

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,17 @@ will then be closed when your PR is merged.
4141
Include Tests
4242
-------------
4343

44-
While working on local code changes, run Deis' tests:
44+
If you change or add functionality to any Deis code, your changes should include
45+
the necessary tests to prove that it works. Unit tests may be written with the
46+
component's implementation language (usually Go or Python), and functional and
47+
integration tests are written in Go. Test code can be found in the ``tests/``
48+
directory of the Deis project.
4549

46-
.. code-block:: console
50+
While working on local code changes, always run the tests. Be sure your
51+
proposed changes pass all of ``./tests/bin/test-integration`` on your
52+
workstation before submitting a PR.
4753

48-
$ export DEV_REGISTRY=192.168.59.103:5000 HOST_IPADDR=192.168.59.103
49-
$ ./tests/bin/test-integration.sh
50-
51-
>>> Preparing test environment <<<
52-
53-
DEIS_ROOT=/Users/matt/Projects/src/github.com/deis/deis
54-
DEIS_TEST_APP=example-go
55-
...
56-
57-
You can run subsets of the tests:
58-
59-
.. code-block:: console
60-
61-
$ make -C docs/ test
62-
$ make -C controller/ test-unit
63-
64-
Be sure your proposed changes pass all of ``./tests/bin/test-integration``
65-
on your workstation before submitting a PR.
66-
67-
See ``tests/README.md`` in the code for more information.
54+
See :ref:`testing` for more information.
6855

6956

7057
Include Docs

docs/contributing/testing.rst

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
:title: Testing Deis
2+
:description: How to test Deis
3+
4+
.. _testing:
5+
6+
Testing Deis
7+
============
8+
9+
Deis is a distributed system with many moving parts, which makes it of paramount
10+
importance to test every change thoroughly.
11+
12+
Deis is also a set of components that correspond to directories in the source
13+
code repository. Most components are Docker containers, two are command-line
14+
clients, and one contains the documentation. Components have source-code level
15+
`unit tests`_ and black-box type `functional tests`_. `integration tests`_
16+
verify the behavior of the components together as a system.
17+
18+
GitHub pull requests for Deis are tested automatically by a Jenkins
19+
`continuous integration`_ (CI) system at http://ci.deis.io. Contributors should
20+
run the same tests locally before proposing any changes to the Deis codebase.
21+
22+
23+
Set Up the Environment
24+
----------------------
25+
26+
To run all tests, you will need:
27+
28+
- Vagrant 1.6.5 or later
29+
- VirtualBox 4.3 or later
30+
- Docker 1.3.0
31+
- PostgreSQL server
32+
33+
The tests assume that you have Deis' `source code`_ in your ``$GOPATH``:
34+
35+
.. code-block:: console
36+
37+
$ go get -u -v github.com/deis/deis
38+
$ cd $GOPATH/src/github.com/deis/deis
39+
40+
Disable Docker TLS
41+
^^^^^^^^^^^^^^^^^^
42+
43+
If you aren't using Linux, your Docker client probably talks to a Docker server
44+
over a TCP connection, as in boot2docker_. Since Docker 1.3.0, that connection
45+
is secured with TLS. Deis' tests use Docker client code directly, but don't yet
46+
incorporate TLS changes.
47+
48+
For now, you must disable Docker TLS to run Deis' functional tests. Here is how
49+
to revert to plain TCP for boot2docker_ 1.3.0. You will add the line
50+
``DOCKER_TLS=""`` to line 24 of */etc/init.d/docker* in your boot2docker VM, so
51+
that section will look like this:
52+
53+
.. code-block:: bash
54+
55+
start() {
56+
DOCKER_TLS="" # <- Add this line and save!
57+
# Not enabling Docker daemon TLS by default.
58+
if [ "$DOCKER_TLS" != "" ]; then
59+
60+
Open a shell to the boot2docker VM, make the change, and restart docker:
61+
62+
.. code-block:: console
63+
64+
$ boot2docker up && boot2docker ssh
65+
$ sudo vi /etc/init.d/docker # edit as above, and save
66+
$ sudo /etc/init.d/docker restart
67+
$ exit
68+
69+
Back on your host machine, ensure your ``DOCKER_HOST`` environment variable
70+
uses port `2375`:
71+
72+
.. code-block:: console
73+
74+
$ export DOCKER_HOST=tcp://192.168.59.103:2375
75+
$ unset DOCKER_TLS_VERIFY
76+
$ docker info
77+
Containers: 34
78+
...
79+
80+
Start a Docker Registry
81+
^^^^^^^^^^^^^^^^^^^^^^^
82+
83+
Deis' functional tests build Docker images and test them locally. The images are
84+
then pushed to a `Docker registry`_ so that integration tests can test them as
85+
binary artifacts--just as a real-world provisioning of Deis pulls images from
86+
the Docker Hub.
87+
88+
If you don't have a Docker registry already accessible for your testing or for
89+
continuous deployment, start one locally:
90+
91+
.. code-block:: console
92+
93+
$ make dev-registry
94+
registry
95+
96+
To use local boot2docker registry for Deis development:
97+
export DEV_REGISTRY=192.168.59.103:5000
98+
99+
100+
Run the Tests
101+
-------------
102+
103+
The unit and functional tests for each component are in their respective
104+
directories. The integration tests, scripts, and supporting go packages are in
105+
the ``tests/`` directory in the project root.
106+
107+
Scripts in the ``tests/bin`` directory are the best place to start. These test
108+
individual pieces of Deis, then bring up a Vagrant cluster and test all of them
109+
as a system. They call ``tests/bin/test-setup.sh`` to test for important
110+
environment variables and will exit with a helpful message if any are missing.
111+
112+
test-integration.sh
113+
^^^^^^^^^^^^^^^^^^^
114+
115+
- runs documentation tests
116+
- builds Docker images tagged with ``$BUILD_TAG``
117+
- runs unit and functional tests
118+
- creates a 3-node Vagrant CoreOS cluster
119+
- pushes the Docker images to a registry
120+
- provisions the cluster for Deis with the registry images
121+
- runs all integration tests
122+
- takes roughly an hour
123+
124+
.. code-block:: console
125+
126+
$ ./tests/bin/test-integration.sh
127+
128+
>>> Preparing test environment <<<
129+
130+
DEIS_ROOT=/Users/matt/Projects/src/github.com/deis/deis
131+
DEIS_TEST_APP=example-go
132+
...
133+
>>> Running integration suite <<<
134+
135+
make -C tests/ test-full
136+
...
137+
>>> Test run complete <<<
138+
139+
test-smoke.sh
140+
^^^^^^^^^^^^^
141+
142+
- runs documentation tests
143+
- builds Docker images tagged with ``$BUILD_TAG``
144+
- runs unit and functional tests
145+
- creates a 3-node Vagrant CoreOS cluster
146+
- pushes the Docker images to a registry
147+
- provisions the cluster for Deis with the registry images
148+
- runs a "smoke test" that pushes and scales an app
149+
- takes roughly 45 minutes
150+
151+
test-latest.sh
152+
^^^^^^^^^^^^^^
153+
154+
- installs the latest ``deis`` and ``deisctl`` client releases
155+
- creates a 3-node Vagrant CoreOS cluster
156+
- provisions the cluster for Deis with latest release images
157+
- runs a "smoke test" that pushes and scales an app
158+
- takes roughly 30 minutes
159+
160+
Run Specific Tests
161+
^^^^^^^^^^^^^^^^^^
162+
163+
Run the tests for a single component this way:
164+
165+
.. code-block:: console
166+
167+
$ make -C logger test # unit + functional
168+
$ make -C controller test-unit
169+
$ make -C router test-functional
170+
171+
172+
Customize Test Runs
173+
-------------------
174+
175+
The file ``tests/bin/test-setup.sh`` is the best reference to environment
176+
variables that can affect the tests' behavior. Here are some important ones:
177+
178+
- ``HOST_IPADDR`` - address on which Docker containers can communicate for the
179+
functional tests, probably the host's IP or the one assigned to boot2docker_.
180+
- ``DEIS_TEST_APP`` - name of the `Deis example app`_ to use, which is cloned
181+
from GitHub (default: ``example-go``)
182+
- ``DEIS_TEST_AUTH_KEY`` - SSH key used to register with the Deis controller
183+
(default: ``~/.ssh/deis``)
184+
- ``DEIS_TEST_SSH_KEY`` - SSH key used to login to the controller machine
185+
(default: ``~/.vagrant.d/insecure_private_key``)
186+
- ``DEIS_TEST_DOMAIN`` - the domain to use for testing
187+
(default: ``local3.deisapp.com``)
188+
189+
190+
.. _`unit tests`: http://en.wikipedia.org/wiki/Unit_testing
191+
.. _`functional tests`: http://en.wikipedia.org/wiki/Functional_testing
192+
.. _`integration tests`: http://en.wikipedia.org/wiki/Integration_testing
193+
.. _`continuous integration`: http://en.wikipedia.org/wiki/Continuous_integration
194+
.. _boot2docker: http://boot2docker.io/
195+
.. _`source code`: https://github.com/deis/deis
196+
.. _`Docker registry`: https://github.com/docker/docker-registry
197+
.. _`Deis example app`: https://github.com/deis?query=example-

tests/README.md

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,13 @@
33
This directory contains a [Go](http://golang.org/) package with integration
44
tests for the [Deis](http://deis.io/) open source PaaS.
55

6-
[![GoDoc](https://godoc.org/github.com/deis/deis/tests?status.svg)](https://godoc.org/github.com/deis/deis/tests)
6+
Please refer to [Testing Deis](http://docs.deis.io/en/latest/contributing/testing/)
7+
for help with running these tests.
8+
9+
[![Testing Deis](https://readthedocs.org/projects/deis/badge/)](http://docs.deis.io/en/latest/contributing/testing/)
710

811
**NOTE**: These integration tests are targeted for use in Deis'
912
[continuous integration system](http://ci.deis.io/). The tests currently assume
1013
they are targeting a freshly provisioned Deis cluster. **Don't** run the
1114
integration tests on a Deis installation with existing users; the tests will
1215
fail and could overwrite data.
13-
14-
## Test Setup
15-
16-
Check out [Deis' source code](https://github.com/deis/deis) into the `$GOPATH`:
17-
18-
```console
19-
$ go get -u -v github.com/deis/deis
20-
$ cd $GOPATH/src/github.com/deis/deis/tests
21-
```
22-
23-
Provision a Deis cluster as usual, and ensure that a matching `deis`
24-
command-line client is available in your `$PATH`.
25-
26-
Create two SSH keys:
27-
28-
```console
29-
$ ssh-keygen -q -t rsa -f ~/.ssh/deis -N '' -C deis
30-
$ ssh-keygen -q -t rsa -f ~/.ssh/deiskey -N '' -C deiskey
31-
```
32-
33-
The first key `deis` is used for authentication against Deis by the `test` user
34-
who runs the integration tests. The second `deiskey` is used only for testing
35-
`deis keys:add`, `deis keys:list`, and related commands.
36-
37-
## Test Execution
38-
39-
Run all the integration tests:
40-
41-
```console
42-
$ make test-full
43-
```
44-
45-
Or run just the [smoke test](http://www.catb.org/jargon/html/S/smoke-test.html):
46-
47-
```console
48-
$ make test-smoke
49-
```
50-
51-
## Customizing Test Runs
52-
53-
These environment variables can be set to customize the test run:
54-
* `DEIS_TEST_AUTH_KEY` - SSH key used to register with the Deis controller
55-
(default: `~/.ssh/deis`)
56-
* `DEIS_TEST_SSH_KEY` - SSH key used to login to the controller machine
57-
(default: `~/.vagrant.d/insecure_private_key`)
58-
* `DEIS_TEST_DOMAIN` - the domain to use for testing
59-
(default: `local.deisapp.com`)
60-
* `DEIS_TEST_HOSTS` - comma-separated list of IPs for nodes in the cluster,
61-
should be internal IPs for cloud providers (default: `172.17.8.100`)
62-
* `DEIS_TEST_APP` - name of the
63-
[Deis example app](https://github.com/deis?query=example-) to use, which is
64-
cloned from GitHub (default: random)

0 commit comments

Comments
 (0)