test_highstate.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import pytest
  2. import salt.output.highstate as highstate
  3. @pytest.fixture(autouse=True)
  4. def setup_loader():
  5. setup_loader_modules = {highstate: {"__opts__": {"strip_colors": True}}}
  6. with pytest.helpers.loader_mock(setup_loader_modules) as loader_mock:
  7. yield loader_mock
  8. @pytest.mark.parametrize("data", [None, {"return": None}, {"return": {"data": None}}])
  9. def test_when_data_result_is_None_output_should_be_string_None(data):
  10. expected_output = "None"
  11. actual_output = highstate.output(data=data)
  12. assert actual_output == expected_output
  13. def test_when_data_is_dict_with_return_key_and_return_value_has_data_key_and_data_dict_has_one_dict_element_with_jid_and_fun_keys_and_return_value_is_None_then_output_should_return_literal_None_string():
  14. expected_output = "None"
  15. data = {
  16. "return": {
  17. "data": {
  18. "foo bar quux fnord": {
  19. "jid": "fnordy fnordy fnordy",
  20. "fun": "fnordy fnordy fnord",
  21. "return": {"data": None},
  22. },
  23. }
  24. },
  25. }
  26. actual_output = highstate.output(data=data)
  27. assert actual_output == expected_output
  28. @pytest.mark.parametrize(
  29. "return_value", [42, "fnord"],
  30. )
  31. def test_when_data_is_dict_with_return_key_and_return_value_has_data_key_and_data_dict_has_one_dict_element_with_jid_and_fun_keys_and_return_value_is_int_or_str_that_value_should_be_returned(
  32. return_value,
  33. ):
  34. expected_output = return_value
  35. data = {
  36. "return": {
  37. "data": {
  38. "foo bar quux fnord": {
  39. "jid": "fnordy fnordy fnordy",
  40. "fun": "fnordy fnordy fnord",
  41. "return": {"data": return_value},
  42. },
  43. }
  44. },
  45. }
  46. actual_output = highstate.output(data=data)
  47. assert actual_output == expected_output
  48. def test_when_orchestrator_output_retcode_in_data_the_retcode_should_be_removed():
  49. data = {"something_master": None, "retcode": 42}
  50. actual_output = highstate.output(data)
  51. assert "retcode" not in data
  52. def test_when_more_than_one_local_master_retcode_should_not_be_removed():
  53. expected_retcode = 42
  54. data = {
  55. "something_master": None,
  56. "another_master": None,
  57. "retcode": expected_retcode,
  58. }
  59. actual_output = highstate.output(data)
  60. assert data["retcode"] == expected_retcode