github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/docs/contributing/testing.rst (about) 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 https://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 Start a Docker Registry 41 ^^^^^^^^^^^^^^^^^^^^^^^ 42 43 Deis' functional tests build Docker images and test them locally. The images are 44 then pushed to a `Docker registry`_ so that integration tests can test them as 45 binary artifacts--just as a real-world provisioning of Deis pulls images from 46 the Docker Hub. 47 48 If you don't have a Docker registry already accessible for your testing or for 49 continuous deployment, start one locally. 50 51 .. code-block:: console 52 53 $ make dev-registry 54 registry 55 56 To use local registry for Deis development: 57 export DEV_REGISTRY=192.168.59.103:5000 58 59 .. important:: 60 61 The functional tests also use several mock or example containers: 62 **deis/test-etcd**, **deis/test-postgresql**, and **deis/mock-store**. 63 These are built locally during a test run. 64 65 Run the Tests 66 ------------- 67 68 The unit and functional tests for each component are in their respective 69 directories. The integration tests, scripts, and supporting go packages are in 70 the ``tests/`` directory in the project root. 71 72 Scripts in the ``tests/bin`` directory are the best place to start. These test 73 individual pieces of Deis, then bring up a Vagrant cluster and test all of them 74 as a system. They call ``tests/bin/test-setup.sh`` to test for important 75 environment variables and will exit with a helpful message if any are missing. 76 77 The ``test-setup.sh`` script also prepares the testing environment, as well as 78 tears it down after testing is complete. If there is a test failure, the script 79 collects verbose component logs, compresses them, and places them in ``$HOME``. 80 If `s3cmd`_ is installed and configured on the test machine, the script will 81 instead upload the logs to Amazon S3. This is how the Jenkins CI infrastructure 82 is configured, so that contributors have access to the logs to see how their 83 PR failed. 84 85 test-integration.sh 86 ^^^^^^^^^^^^^^^^^^^ 87 88 - runs documentation tests 89 - builds Docker images tagged with ``$BUILD_TAG`` 90 - runs unit and functional tests 91 - creates a 3-node Vagrant CoreOS cluster 92 - pushes the Docker images to a registry 93 - provisions the cluster for Deis with the registry images 94 - runs all integration tests 95 - takes roughly an hour 96 97 .. code-block:: console 98 99 $ ./tests/bin/test-integration.sh 100 101 >>> Preparing test environment <<< 102 103 DEIS_ROOT=/Users/matt/Projects/src/github.com/deis/deis 104 DEIS_TEST_APP=example-dockerfile-http 105 ... 106 >>> Running integration suite <<< 107 108 make -C tests/ test-full 109 ... 110 >>> Test run complete <<< 111 112 test-smoke.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 a "smoke test" that pushes and scales an app 122 - takes roughly 45 minutes 123 124 test-latest.sh 125 ^^^^^^^^^^^^^^ 126 127 - installs the latest ``deis`` and ``deisctl`` client releases 128 - creates a 3-node Vagrant CoreOS cluster 129 - provisions the cluster for Deis with latest release images 130 - runs a "smoke test" that pushes and scales an app 131 - takes roughly 30 minutes 132 133 Run Specific Tests 134 ^^^^^^^^^^^^^^^^^^ 135 136 Run the tests for a single component this way: 137 138 .. code-block:: console 139 140 $ make -C logger test # unit + functional 141 $ make -C controller test-unit 142 $ make -C router test-functional 143 144 145 Customize Test Runs 146 ------------------- 147 148 The file ``tests/bin/test-setup.sh`` is the best reference to environment 149 variables that can affect the tests' behavior. Here are some important ones: 150 151 - ``HOST_IPADDR`` - address on which Docker containers can communicate for the 152 functional tests, probably the host's IP or the one assigned to `Docker Machine`_. 153 - ``DEIS_TEST_APP`` - name of the `Deis example app`_ to use, which is cloned 154 from GitHub (default: ``example-go``) 155 - ``DEIS_TEST_AUTH_KEY`` - SSH key used to register with the Deis controller 156 (default: ``~/.ssh/deis``) 157 - ``DEIS_TEST_SSH_KEY`` - SSH key used to login to the controller machine 158 (default: ``~/.vagrant.d/insecure_private_key``) 159 - ``DEIS_TEST_DOMAIN`` - the domain to use for testing 160 (default: ``local3.deisapp.com``) 161 162 163 .. _`unit tests`: http://en.wikipedia.org/wiki/Unit_testing 164 .. _`functional tests`: http://en.wikipedia.org/wiki/Functional_testing 165 .. _`integration tests`: http://en.wikipedia.org/wiki/Integration_testing 166 .. _`continuous integration`: http://en.wikipedia.org/wiki/Continuous_integration 167 .. _`Docker Machine`: http://docs.docker.com/machine/install-machine/ 168 .. _`source code`: https://github.com/deis/deis 169 .. _`Docker registry`: https://github.com/docker/docker-registry 170 .. _`Deis example app`: https://github.com/deis?query=example- 171 .. _`s3cmd`: http://s3tools.org/s3cmd