forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_ci.py
70 lines (57 loc) · 2.44 KB
/
test_run_ci.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
67
68
69
70
# 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 os
import tempfile
import unittest
from typing import Any
from unittest.mock import Mock, call, patch
import pytest
from run_ci import main
class TestRunCi(unittest.TestCase):
@pytest.fixture(autouse=True)
def _capfd(self, capfd: Any) -> None:
self.capfd = capfd
@patch("argparse._sys.argv", ["run_ci.py", "--help"])
def test_usage(self) -> None:
with self.assertRaises(SystemExit):
main()
out, _ = self.capfd.readouterr()
self.assertTrue(out.startswith("usage:"))
OPENSEARCH_MANIFEST = os.path.realpath(
os.path.join(
os.path.dirname(__file__),
"..",
"manifests",
"templates",
"opensearch",
"1.x",
"os-template-1.1.0.yml"
)
)
@patch("argparse._sys.argv", ["run_ci.py", OPENSEARCH_MANIFEST])
@patch("ci_workflow.ci_input_manifest.TemporaryDirectory")
@patch("ci_workflow.ci_input_manifest.CiCheckLists.from_component")
def test_main(self, mock_lists: Mock, mock_temp: Mock, *mocks: Any) -> None:
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
main()
self.assertNotEqual(mock_lists.call_count, 0)
self.assertEqual(mock_lists.return_value.checkout.call_count, mock_lists.call_count)
self.assertEqual(mock_lists.return_value.check.call_count, mock_lists.call_count)
OPENSEARCH_TEST_MANIFEST = os.path.realpath(os.path.join(os.path.dirname(__file__), "../manifests/3.0.0/opensearch-3.0.0-test.yml"))
@patch("argparse._sys.argv", ["run_ci.py", OPENSEARCH_TEST_MANIFEST])
@patch("logging.info")
def test_main_test_manifest(self, mock_logging: Mock, *mocks: Any) -> None:
main()
mock_logging.assert_has_calls([
call("TestManifest schema validation succeeded"),
call("Done.")
])
OPENSEARCH_TEST_MANIFEST_NOT_EXIST = os.path.realpath(os.path.join(os.path.dirname(__file__), "../manifests/1.4.0/opensearch-1.3.0-test.yml"))
@patch("argparse._sys.argv", ["run_ci.py", OPENSEARCH_TEST_MANIFEST_NOT_EXIST])
def test_main_test_manifest_empty(self, *mocks: Any) -> None:
with self.assertRaises(SystemExit):
main()