From cc15766671d11204af0e50b80df2ff7728d4e37f Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sun, 21 May 2023 13:32:04 +0200 Subject: [PATCH] Implement Salt test tests Test the tests. Signed-off-by: Georg Pfuetzenreuter --- tests/01_test_cli.py | 4 ++- tests/03_test_salt.py | 29 ++++++++++++++++++++++ tests/configs/complete.ini | 2 +- tests/salt/hello_world/tests/test_hello.py | 2 ++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/salt/hello_world/tests/test_hello.py diff --git a/tests/01_test_cli.py b/tests/01_test_cli.py index 7412e65..155fdb5 100644 --- a/tests/01_test_cli.py +++ b/tests/01_test_cli.py @@ -150,7 +150,9 @@ def test_test_incomplete(script_runner, script, config): 'one_minion_one_master', 'two_minions_one_master', 'one_minion_bootstrap', - 'one_minion_one_master_bootstrap' + 'one_minion_one_master_bootstrap', + 'one_minion_salt', + 'two_minions_one_master_salt' ]) def test_stop(script_runner, script, config, suite): cmd = (script, '--config', config, '--suite', suite, '--stop', '--force') diff --git a/tests/03_test_salt.py b/tests/03_test_salt.py index d9ef598..ac06703 100644 --- a/tests/03_test_salt.py +++ b/tests/03_test_salt.py @@ -28,3 +28,32 @@ def test_salt(script_runner, script, config, suite): assert 'DEBUG - main_interactive: state.apply requested' in result.stderr assert script_runner.run(*cmd, '--stop') +@pytest.mark.parametrize('config', ['complete'], indirect=True) +@pytest.mark.parametrize('suite,count', [ + ('one_minion_salt', 0), + ('two_minions_one_master_salt', 1) + ]) +def test_salt_test(script_runner, script, config, suite, count): + cmd = (script, '--config', config, '--suite', suite) + result = script_runner.run(*cmd, '--debug', '--env', '--test') + assert result.success + for message in [ + 'Comment: File /srv/hello_world.txt updated', + 'Succeeded: 1 (changed=1)', + 'DEBUG - main_interactive: state.apply requested', + 'INFO - main_interactive: Initiating tests ...', + 'DEBUG - runtests: Test result is 0', + 'DEBUG - runtests: Test succeeded' + ]: + assert message in result.stderr + assert not any(term in result.stderr for term in [ + 'FAILED', 'WARNING - runtests: Tests failed', + 'DEBUG - runtests: Test result is 1', 'AssertionError' + ]) + if count > 0: + minions = [0, 1] + else: + minions = [0] + for m in minions: + assert 'test_hello_world_content[paramiko://scullery-minion%i] PASSED' % m in result.stdout + assert script_runner.run(*cmd, '--stop') diff --git a/tests/configs/complete.ini b/tests/configs/complete.ini index fdee52b..0f29c07 100644 --- a/tests/configs/complete.ini +++ b/tests/configs/complete.ini @@ -56,7 +56,7 @@ test=bogus [test.hello] apply=hello_world -test=salt/hello_world/tests/test_hello.py +test=tests/salt/hello_world/tests/test_hello.py [test.bogus] apply=cashew diff --git a/tests/salt/hello_world/tests/test_hello.py b/tests/salt/hello_world/tests/test_hello.py new file mode 100644 index 0000000..4cab978 --- /dev/null +++ b/tests/salt/hello_world/tests/test_hello.py @@ -0,0 +1,2 @@ +def test_hello_world_content(host): + assert host.file('/srv/hello_world.txt').content.decode('UTF-8') == 'Hello salted world!\n'