A module for testing the logic of states and highstates

codeauthor:William Cannon <>

Saltcheck provides unittest like functionality requiring only the knowledge of salt module execution and yaml.

In order to run state and highstate saltcheck tests a sub-folder of a state must be created and named saltcheck-tests.

Tests for a state should be created in files ending in *.tst and placed in the saltcheck-tests folder.

Multiple tests can be created in a file. Multiple *.tst files can be created in the saltcheck-tests folder. Salt rendering is supported in test files (e.g. yaml + jinja). The id of a test works in the same manner as in salt state files. They should be unique and descriptive.

Example file system layout:


  module_and_function: test.echo
    - "hello"
  assertion: assertEqual
  expected-return:  'hello'
class salt.modules.saltcheck.SaltCheck

This class implements the saltcheck

call_salt_command(fun, args, kwargs)

Generic call of salt Caller command

static cast_expected_to_returned_type(expected, returned)

Determine the type of variable returned Cast the expected to the type of variable returned

static get_state_search_path_list()

For the state file system, return a list of paths to search for states


Run a single saltcheck test

class salt.modules.saltcheck.StateTestLoader(search_paths)

Class loads in test files for a state e.g. state_dir/saltcheck-tests/[1.tst, 2.tst, 3.tst]


Adding test files

static convert_sls_to_path(sls)

Converting sls to paths

static convert_sls_to_paths(sls_list)

Converting sls to paths


Gather files for a test suite


loads in one test file


loads in one test file


Load tests either from one file, or a set of files


Execute all tests for a salt highstate and return results

CLI Example:

salt '*' saltcheck.run_highstate_tests

Execute all tests for a salt state and return results Nested states will also be tested

Parameters:state (str) -- the name of a user defined state

CLI Example:

salt '*' saltcheck.run_state_tests postfix

Execute one saltcheck test and return result

Parameters:arg test (keyword) --

CLI Example:

salt '*' saltcheck.run_test
    test='{"module_and_function": "test.echo",
           "assertion": "assertEqual",
           "expected-return": "This works!",
           "args":["This works!"] }'

Updates the master cache onto the minion - transfers all salt-check-tests Should be done one time before running tests, and if tests are updated Can be automated by setting "auto_update_master_cache: True" in minion config

CLI Example:

salt '*' saltcheck.update_master_cache