forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_checkout.py
77 lines (65 loc) · 2.39 KB
/
test_run_checkout.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
71
72
73
74
75
76
77
# 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 MagicMock, Mock, call, patch
import pytest
from run_checkout import main
class TestRunCheckout(unittest.TestCase):
@pytest.fixture(autouse=True)
def _capfd(self, capfd: Any) -> None:
self.capfd = capfd
@patch("argparse._sys.argv", ["run_checkout.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_checkout.py", OPENSEARCH_MANIFEST])
@patch("run_checkout.GitRepository")
@patch("run_checkout.TemporaryDirectory")
def test_main(self, mock_temp: Mock, mock_repo: Mock) -> None:
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
mock_repo.return_value.__enter__.return_value = MagicMock(working_directory="dummy")
main()
# each repository is checked out locally
mock_repo.assert_has_calls(
[
call(
"https://github.com/opensearch-project/OpenSearch.git",
"tags/1.1.0",
os.path.join(tempfile.gettempdir(), "OpenSearch"),
None,
),
call(
"https://github.com/opensearch-project/common-utils.git",
"tags/1.1.0.0",
os.path.join(tempfile.gettempdir(), "common-utils"),
None,
),
call(
"https://github.com/opensearch-project/dashboards-reports.git",
"tags/1.1.0.0",
os.path.join(tempfile.gettempdir(), "dashboards-reports"),
"reports-scheduler",
),
],
any_order=True,
)
self.assertNotEqual(mock_repo.call_count, 0)