2013-11-26 00:13:48 +00:00
|
|
|
==================
|
|
|
|
Writing Salt Tests
|
|
|
|
==================
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
THIS TUTORIAL IS A WORK IN PROGRESS
|
|
|
|
|
|
|
|
Salt comes with a powerful integration and unit test suite. The test suite
|
|
|
|
allows for the fully automated run of integration and/or unit tests from a
|
2013-11-26 13:00:47 +00:00
|
|
|
single interface. The integration tests are surprisingly easy to write and can
|
|
|
|
be written to be either destructive or non-destructive.
|
2013-11-26 00:13:48 +00:00
|
|
|
|
2014-03-26 17:06:40 +00:00
|
|
|
Getting Set Up For Tests
|
2013-11-26 00:13:48 +00:00
|
|
|
========================
|
|
|
|
|
|
|
|
To walk through adding an integration test, start by getting the latest
|
2014-04-30 20:55:30 +00:00
|
|
|
development code and the test system from GitHub:
|
2013-11-26 00:13:48 +00:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The develop branch often has failing tests and should always be considered
|
2014-05-25 04:42:00 +00:00
|
|
|
a staging area. For a checkout that tests should be running perfectly on,
|
|
|
|
please check out a specific release tag (such as v2014.1.4).
|
2013-11-26 00:13:48 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
git clone git@github.com:saltstack/salt.git
|
|
|
|
pip install git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting
|
|
|
|
|
|
|
|
Now that a fresh checkout is available run the test suite
|
|
|
|
|
|
|
|
Destructive vs Non-destructive
|
|
|
|
==============================
|
|
|
|
|
2014-05-25 04:42:00 +00:00
|
|
|
Since Salt is used to change the settings and behavior of systems, often, the
|
2013-11-26 13:00:47 +00:00
|
|
|
best approach to run tests is to make actual changes to an underlying system.
|
2013-11-26 00:13:48 +00:00
|
|
|
This is where the concept of destructive integration tests comes into play.
|
|
|
|
Tests can be written to alter the system they are running on. This capability
|
|
|
|
is what fills in the gap needed to properly test aspects of system management
|
2013-11-26 13:00:47 +00:00
|
|
|
like package installation.
|
2013-11-26 00:13:48 +00:00
|
|
|
|
|
|
|
To write a destructive test import and use the `destructiveTest` decorator for
|
|
|
|
the test method:
|
|
|
|
|
2014-07-10 22:47:51 +00:00
|
|
|
.. code-block:: python
|
2013-11-26 00:13:48 +00:00
|
|
|
|
|
|
|
import integration
|
|
|
|
from salttesting.helpers import destructiveTest
|
|
|
|
|
|
|
|
class PkgTest(integration.ModuleCase):
|
|
|
|
@destructiveTest
|
|
|
|
def test_pkg_install(self):
|
|
|
|
ret = self.run_function('pkg.install', name='finch')
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
ret = self.run_function('pkg.purge', name='finch')
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
|
|
|
|
Automated Test Runs
|
|
|
|
===================
|
|
|
|
|
|
|
|
SaltStack maintains a Jenkins server which can be viewed at
|
|
|
|
http://jenkins.saltstack.com. The tests executed from this Jenkins server
|
|
|
|
create fresh virtual machines for each test run, then execute the destructive
|
|
|
|
tests on the new clean virtual machine. This allows for the execution of tests
|
2014-12-11 15:50:14 +00:00
|
|
|
across supported platforms.
|