Skip to content

Commit

Permalink
Add some test
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon committed Aug 28, 2024
1 parent 1252b46 commit 2a61ff3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/tests_manifests_workflow/test_input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest.mock import MagicMock, call, mock_open, patch

from manifests.input_manifest import InputManifest
from manifests.test_manifest import TestManifest
from manifests_workflow.input_manifests import InputManifests


Expand Down Expand Up @@ -119,15 +120,24 @@ def test_create_manifest_opensearch_dashboards_previous_base_version(self) -> No
input_manifest_compare = InputManifest.from_file(open(manifest_path))
self.assertEqual(input_manifest.to_dict(), input_manifest_compare.to_dict())

@patch("manifests.manifest.Manifest.to_file")
@patch("os.makedirs")
@patch("manifests_workflow.input_manifests.InputManifests.create_manifest")
def test_write_manifest(self, mock_create_manifest: MagicMock, mock_makedirs: MagicMock) -> None:
def test_write_manifest(self, mock_create_manifest: MagicMock, mock_makedirs: MagicMock, mock_to_file: MagicMock) -> None:
input_manifest = InputManifest.from_file(open(os.path.join(os.path.dirname(__file__), "data", "opensearch-2.12.1000.yml")))
test_manifest = TestManifest.from_file(open(os.path.join(os.path.dirname(__file__), "data", "opensearch-2.12.1000-test.yml")))
mock_create_manifest.return_value = (input_manifest, test_manifest)
input_manifests = InputManifests("opensearch")
input_manifests.write_manifest('0.1.2', '0.x', [])
mock_create_manifest.assert_called_with('0.1.2', '0.x', [])
mock_makedirs.assert_called_with(os.path.join(InputManifests.manifests_path(), '0.1.2'), exist_ok=True)
mock_create_manifest.return_value.to_file.assert_called_with(
os.path.join(InputManifests.manifests_path(), '0.1.2', 'opensearch-0.1.2.yml')
input_manifests.write_manifest('2.12.1000', '2.x', [])
mock_create_manifest.assert_called_with('2.12.1000', '2.x', [])
mock_makedirs.assert_called_with(os.path.join(InputManifests.manifests_path(), '2.12.1000'), exist_ok=True)
self.assertEqual(
mock_to_file.call_args_list[0][0][0],
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "manifests", "2.12.1000", "opensearch-2.12.1000.yml"))
)
self.assertEqual(
mock_to_file.call_args_list[1][0][0],
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "manifests", "2.12.1000", "opensearch-2.12.1000-test.yml"))
)

def test_jenkins_path(self) -> None:
Expand Down

0 comments on commit 2a61ff3

Please sign in to comment.