test_restart.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. from render import Render
  3. @pytest.fixture
  4. def mock_values():
  5. return {
  6. "images": {
  7. "test_image": {
  8. "repository": "nginx",
  9. "tag": "latest",
  10. }
  11. },
  12. }
  13. def test_invalid_restart_policy(mock_values):
  14. render = Render(mock_values)
  15. c1 = render.add_container("test_container", "test_image")
  16. c1.healthcheck.disable()
  17. with pytest.raises(Exception):
  18. c1.restart.set_policy("invalid_policy")
  19. def test_valid_restart_policy(mock_values):
  20. render = Render(mock_values)
  21. c1 = render.add_container("test_container", "test_image")
  22. c1.healthcheck.disable()
  23. c1.restart.set_policy("on-failure")
  24. output = render.render()
  25. assert output["services"]["test_container"]["restart"] == "on-failure"
  26. def test_valid_restart_policy_with_maximum_retry_count(mock_values):
  27. render = Render(mock_values)
  28. c1 = render.add_container("test_container", "test_image")
  29. c1.healthcheck.disable()
  30. c1.restart.set_policy("on-failure", 10)
  31. output = render.render()
  32. assert output["services"]["test_container"]["restart"] == "on-failure:10"
  33. def test_invalid_restart_policy_with_maximum_retry_count(mock_values):
  34. render = Render(mock_values)
  35. c1 = render.add_container("test_container", "test_image")
  36. c1.healthcheck.disable()
  37. with pytest.raises(Exception):
  38. c1.restart.set_policy("on-failure", maximum_retry_count=-1)
  39. def test_invalid_restart_policy_with_maximum_retry_count_and_policy(mock_values):
  40. render = Render(mock_values)
  41. c1 = render.add_container("test_container", "test_image")
  42. c1.healthcheck.disable()
  43. with pytest.raises(Exception):
  44. c1.restart.set_policy("always", maximum_retry_count=10)