forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_manifests.py
66 lines (52 loc) · 2.16 KB
/
test_run_manifests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import unittest
from typing import Any
from unittest.mock import MagicMock, Mock, call, patch
import pytest
from run_manifests import main
class TestRunManifests(unittest.TestCase):
@pytest.fixture(autouse=True)
def _capfd(self, capfd: Any) -> None:
self.capfd = capfd
@patch("argparse._sys.argv", ["run_manifests.py", "--help"])
def test_usage(self) -> None:
with self.assertRaises(SystemExit):
main()
out, _ = self.capfd.readouterr()
self.assertTrue(out.startswith("usage:"))
@patch("argparse._sys.argv", ["run_manifests.py", "list"])
@patch("run_manifests.logging", return_value=MagicMock())
def test_main_list(self, mock_logging: Mock, *mocks: Any) -> None:
main()
mock_logging.info.assert_has_calls([
call("OpenSearch 1.3.0"),
call("OpenSearch 1.3.1"),
call("OpenSearch 1.3.2"),
call("OpenSearch 1.3.3"),
call("OpenSearch 1.3.4")
])
mock_logging.info.assert_has_calls([
call("OpenSearch 2.0.0"),
call("OpenSearch 2.0.1")
])
mock_logging.info.assert_has_calls([
call("OpenSearch 3.0.0")
])
mock_logging.info.assert_has_calls([
call("OpenSearch Dashboards 1.3.0")
])
mock_logging.info.assert_has_calls([
call("Done.")
])
@patch("argparse._sys.argv", ["run_manifests.py", "update"])
@patch("manifests_workflow.manifests_args.InputManifestsOpenSearch", return_value=MagicMock())
@patch("manifests_workflow.manifests_args.InputManifestsOpenSearchDashboards", return_value=MagicMock())
def test_main_update(self, mock_manifests_opensearch_dashboards: Mock, mock_manifests_opensearch: Mock, *mocks: Any) -> None:
main()
mock_manifests_opensearch_dashboards.return_value.update.assert_called()
mock_manifests_opensearch.return_value.update.assert_called()