Skip to content

Commit

Permalink
refine tests for changed and return_code
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Feb 12, 2025
1 parent 2b6c0af commit 2426d10
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 14 deletions.
Binary file modified tests/unit/plugins/modules/fixtures/plan.tfplan
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/unit/plugins/modules/test_goss_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_goss_render_debug(capfd):
assert not stderr

info = json.loads(stdout)
assert info['changed']
assert 'render' in info['command']
assert '--debug' in info['command']
assert 'size: 4096' in info['stdout']
Expand All @@ -52,6 +53,7 @@ def test_goss_render_vars_inline(capfd):
assert not stderr

info = json.loads(stdout)
assert info['changed']
assert 'render' in info['command']
assert '--vars-inline' in info['command']
assert '{"my_service": "httpd", "my_package": "apache"}' in info['command']
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/plugins/modules/test_goss_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_goss_serve_gossfile(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert 'serve' in info['cmd']
assert '-g' in info['cmd']
assert 'galaxy.yml' in info['cmd']
Expand All @@ -36,7 +35,6 @@ def test_goss_serve_format_vars(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert 'serve' in info['cmd']
assert '-g' not in info['cmd']
assert '-f' in info['cmd']
Expand All @@ -58,7 +56,6 @@ def test_goss_serve_endpoint_port(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert 'serve' in info['cmd']
assert '-c' in info['cmd']
assert '1m' in info['cmd']
Expand All @@ -79,7 +76,6 @@ def test_goss_serve_package_vars_inline(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert 'serve' in info['cmd']
assert '--package' in info['cmd']
assert 'rpm' in info['cmd']
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/plugins/modules/test_packer_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_packer_build_except_onerror_force(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert '/tmp' == info['cmd'][-1]
assert '-force' in info['cmd']
assert '-on-error=abort' in info['cmd']
Expand All @@ -60,7 +59,6 @@ def test_packer_build_except_parallel_timestamp(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert '/tmp' == info['cmd'][-1]
assert '-except=null.this,null.that' in info['cmd']
assert '-parallel-builds=1' in info['cmd']
Expand All @@ -81,7 +79,6 @@ def test_packer_build_var_varfile(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert '-var' in info['cmd']
assert 'var_name=var_value' in info['cmd']
assert 'var_name_other=var_value_other' in info['cmd']
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/plugins/modules/test_packer_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_packer_init_defaults(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert 'init' in info['cmd']
assert 'ui,error,Error: Could not find any config file in' in info['stdout']

Expand All @@ -33,6 +32,7 @@ def test_packer_init_config(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert str(utils.fixtures_dir()) == info['command'][-1]
assert not info['stdout']

Expand All @@ -47,6 +47,7 @@ def test_packer_init_upgrade(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-upgrade' in info['command']
assert str(utils.fixtures_dir()) == info['command'][-1]
assert not info['stdout']
3 changes: 1 addition & 2 deletions tests/unit/plugins/modules/test_packer_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_packer_validate_eval_datasource_warn_undeclared(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert '-evaluate-datasources' in info['cmd']
assert '-no-warn-undeclared-var' in info['cmd']
assert str(utils.fixtures_dir()) == info['cmd'][-1]
Expand All @@ -57,6 +56,7 @@ def test_packer_validate_syntax_except(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert str(utils.fixtures_dir()) == info['command'][-1]
assert '-syntax-only' in info['command']
assert '-except=null.this,null.that' in info['command']
Expand All @@ -77,7 +77,6 @@ def test_packer_validate_var_varfile(capfd):
assert not stderr

info = json.loads(stdout)
assert info['return_code'] == 1
assert '-var' in info['cmd']
assert 'var_name=var_value' in info['cmd']
assert 'var_name_other=var_value_other' in info['cmd']
Expand Down
1 change: 0 additions & 1 deletion tests/unit/plugins/modules/test_puppet_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test_puppet_agent_nodaemonize_onetime(capfd):

info = json.loads(stdout)
assert len(info['msg']) == 0
assert info['return_code'] == 1
assert 'agent' in info['cmd']
assert '--no-daemonize' in info['cmd']
assert '--onetime' in info['cmd']
7 changes: 4 additions & 3 deletions tests/unit/plugins/modules/test_puppet_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

def test_puppet_apply_test(capfd):
"""test puppet apply with test"""
utils.set_module_args({'test': True, 'manifest': str(utils.fixtures_dir() / 'manifest.pp')})
utils.set_module_args({'test': True, 'manifest': f"{str(utils.fixtures_dir())}/manifest.pp"})
with pytest.raises(SystemExit, match='0'):
puppet_apply.main()

stdout, stderr = capfd.readouterr()
assert not stderr

info = json.loads(stdout)
print(info)
assert info['changed']
assert info['return_code'] == 2
assert 'hello world' in info['stdout']
assert not info['stderr']
assert 'apply' in info['command']
Expand All @@ -29,7 +29,7 @@ def test_puppet_apply_test(capfd):

def test_puppet_apply_debug_noop_verbose(capfd):
"""test puppet apply with debug noop verbose"""
utils.set_module_args({'debug': True, 'manifest': str(utils.fixtures_dir() / 'manifest.pp'), 'no_op': True, 'verbose': True})
utils.set_module_args({'debug': True, 'manifest': f"{str(utils.fixtures_dir())}/manifest.pp", 'no_op': True, 'verbose': True})
with pytest.raises(SystemExit, match='0'):
puppet_apply.main()

Expand All @@ -38,6 +38,7 @@ def test_puppet_apply_debug_noop_verbose(capfd):

info = json.loads(stdout)
assert not info['changed']
assert info['return_code'] == 0
assert 'hello world' in info['stdout']
assert not info['stderr']
assert 'apply' in info['command']
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/plugins/modules/test_terraform_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_terraform_apply_config_destroy(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert '-destroy' in info['command']
assert 'No changes.' in info['stdout']
Expand Down Expand Up @@ -69,6 +70,7 @@ def test_terraform_apply_multiple_args(capfd):

print(stdout)
info = json.loads(stdout)
assert not info['changed']
assert '-target=aws_instance.this' in info['command']
assert '-target=local_file.that' in info['command']
assert '-var' in info['command']
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/plugins/modules/test_terraform_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_terraform_fmt_defaults(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert 'fmt' in info['command']
assert '-no-color' in info['command']
assert '-list=false' in info['command']
Expand All @@ -34,6 +35,7 @@ def test_terraform_fmt_config_diff_write(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert '-diff' in info['command']
assert '-write=false' in info['command']
Expand All @@ -50,6 +52,7 @@ def test_terraform_fmt_check_recursive(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-check' in info['command']
assert '-recursive' in info['command']
assert '' == info['stdout']
4 changes: 4 additions & 0 deletions tests/unit/plugins/modules/test_terraform_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_terraform_init_defaults(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert 'init' in info['command']
assert '-no-color' in info['command']
assert '-input=false' in info['command']
Expand All @@ -34,6 +35,7 @@ def test_terraform_init_config(capfd):
assert not stderr

info = json.loads(stdout)
assert info['changed']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert 'Terraform has been successfully initialized!' in info['stdout']

Expand All @@ -52,6 +54,7 @@ def test_terraform_init_upgrade_backend(capfd):
assert not stderr

info = json.loads(stdout)
assert info['changed']
assert '-upgrade' in info['command']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert 'Terraform has been successfully initialized!' in info['stdout']
Expand All @@ -70,6 +73,7 @@ def test_terraform_init_multiple_args(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-migrate-state' in info['command']
assert f"-backend-config={str(utils.fixtures_dir())}/config.tf" in info['command']
print(info['command'])
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/plugins/modules/test_terraform_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_terraform_plan_config_destroy(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert '-destroy' in info['command']
assert 'No changes.' in info['stdout']
Expand All @@ -53,6 +54,7 @@ def test_terraform_plan_replace_out(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-replace=aws_instance.this' in info['command']
assert '-replace=local_file.that' in info['command']
assert '-out=plan.tfplan' in info['command']
Expand All @@ -74,6 +76,7 @@ def test_terraform_plan_multiple_args(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-refresh-only' in info['command']
assert '-var' in info['command']
assert 'var_name=var_value' in info['command']
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/plugins/modules/test_terraform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_terraform_test_defaults(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert 'test' in info['command']
assert 'Success! 0 passed, 0 failed.' in info['stdout']

Expand All @@ -32,6 +33,7 @@ def test_terraform_test_config(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-test-directory=my_tests' in info['command']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert 'Success! 0 passed, 0 failed.' in info['stdout']
Expand All @@ -51,6 +53,7 @@ def test_terraform_test_upgrade_backend(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-json' in info['command']
assert '-var' in info['command']
assert 'var_name=var_value' in info['command']
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/plugins/modules/test_terraform_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_terraform_validate_defaults(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert 'validate' in info['command']
assert '-no-color' in info['command']
assert 'Success! The configuration is valid.' in info['stdout']
Expand All @@ -33,6 +34,7 @@ def test_terraform_validate_config(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert f"-chdir={str(utils.fixtures_dir())}" in info['command']
assert 'Success! The configuration is valid.' in info['stdout']

Expand All @@ -47,6 +49,7 @@ def test_terraform_validate_json_dir(capfd):
assert not stderr

info = json.loads(stdout)
assert not info['changed']
assert '-json' in info['command']
assert '-test-directory=my_tests' in info['command']
assert 'Test directory does not exist' in info['stdout']

0 comments on commit 2426d10

Please sign in to comment.