test_ini_manage.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Integration tests for the ini_manage state
  3. """
  4. import pytest
  5. def test_options_present(salt_call_cli):
  6. """
  7. test ini.options_present when the file
  8. does not exist and then run it again
  9. when it does exist and run it again when
  10. we want to add more sections to the ini
  11. """
  12. with pytest.helpers.temp_file("ini_file.ini") as tpath:
  13. content = """
  14. test_ini:
  15. ini.options_present:
  16. - name: {}
  17. - sections:
  18. general:
  19. server_hostname: foo.com
  20. server_port: 1234
  21. """.format(
  22. tpath
  23. )
  24. with pytest.helpers.temp_state_file("manage_ini.sls", content) as sfpath:
  25. ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
  26. assert ret.json[next(iter(ret.json))]["changes"] == {
  27. "general": {
  28. "before": None,
  29. "after": {"server_hostname": "foo.com", "server_port": "1234"},
  30. }
  31. }
  32. content = """
  33. test_ini:
  34. ini.options_present:
  35. - name: {}
  36. - sections:
  37. general:
  38. server_hostname: foo.com
  39. server_port: 1234
  40. server_user: saltfoo
  41. """.format(
  42. tpath
  43. )
  44. with pytest.helpers.temp_state_file("manage_ini.sls", content) as sfpath:
  45. # check to see adding a new section works
  46. ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
  47. assert ret.json[next(iter(ret.json))]["changes"] == {
  48. "general": {"server_user": {"before": None, "after": "saltfoo"}}
  49. }
  50. # check when no changes are expected
  51. ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
  52. assert ret.json[next(iter(ret.json))]["changes"] == {}