test_configs.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_add_duplicate_config_with_different_data(mock_values):
  14. render = Render(mock_values)
  15. c1 = render.add_container("test_container", "test_image")
  16. c1.healthcheck.disable()
  17. c1.configs.add("test_config", "test_data", "/some/path")
  18. with pytest.raises(Exception):
  19. c1.configs.add("test_config", "test_data2", "/some/path")
  20. def test_add_config_with_empty_target(mock_values):
  21. render = Render(mock_values)
  22. c1 = render.add_container("test_container", "test_image")
  23. c1.healthcheck.disable()
  24. with pytest.raises(Exception):
  25. c1.configs.add("test_config", "test_data", "")
  26. def test_add_duplicate_target(mock_values):
  27. render = Render(mock_values)
  28. c1 = render.add_container("test_container", "test_image")
  29. c1.healthcheck.disable()
  30. c1.configs.add("test_config", "test_data", "/some/path")
  31. with pytest.raises(Exception):
  32. c1.configs.add("test_config2", "test_data2", "/some/path")
  33. def test_add_config(mock_values):
  34. render = Render(mock_values)
  35. c1 = render.add_container("test_container", "test_image")
  36. c1.healthcheck.disable()
  37. c1.configs.add("test_config", "$test_data", "/some/path")
  38. output = render.render()
  39. assert output["configs"]["test_config"]["content"] == "$$test_data"
  40. assert output["services"]["test_container"]["configs"] == [{"source": "test_config", "target": "/some/path"}]
  41. def test_add_config_with_mode(mock_values):
  42. render = Render(mock_values)
  43. c1 = render.add_container("test_container", "test_image")
  44. c1.healthcheck.disable()
  45. c1.configs.add("test_config", "test_data", "/some/path", "0777")
  46. output = render.render()
  47. assert output["configs"]["test_config"]["content"] == "test_data"
  48. assert output["services"]["test_container"]["configs"] == [
  49. {"source": "test_config", "target": "/some/path", "mode": 511}
  50. ]