test_status.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.pytests.unit.beacons.test_status
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Status beacon test cases
  6. """
  7. from __future__ import absolute_import
  8. import pytest
  9. import salt.modules.status as status_module
  10. from salt.beacons import status
  11. @pytest.fixture(autouse=True)
  12. def setup_loader(request):
  13. setup_loader_modules = {
  14. status: {
  15. "__salt__": pytest.helpers.salt_loader_module_functions(status_module)
  16. },
  17. status_module: {"__grains__": {"kernel": "Linux"}, "__salt__": {}},
  18. }
  19. with pytest.helpers.loader_mock(request, setup_loader_modules) as loader_mock:
  20. yield loader_mock
  21. def test_empty_config():
  22. config = []
  23. ret = status.validate(config)
  24. assert ret == (True, "Valid beacon configuration")
  25. ret = status.beacon(config)
  26. expected = sorted(["loadavg", "meminfo", "cpustats", "vmstats", "time"])
  27. assert sorted(list(ret[0]["data"])) == expected
  28. def test_deprecated_dict_config():
  29. config = {"time": ["all"]}
  30. ret = status.validate(config)
  31. assert ret == (False, "Configuration for status beacon must be a list.")
  32. def test_list_config():
  33. config = [{"time": ["all"]}]
  34. ret = status.validate(config)
  35. assert ret == (True, "Valid beacon configuration")
  36. ret = status.beacon(config)
  37. expected = ["time"]
  38. assert list(ret[0]["data"]) == expected