forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_assemble.py
55 lines (41 loc) · 1.9 KB
/
test_run_assemble.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
# 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 unittest
from unittest.mock import ANY, MagicMock, Mock, call, patch
import pytest
from pytest import CaptureFixture
from run_assemble import main
class TestRunAssemble(unittest.TestCase):
@pytest.fixture(autouse=True)
def getCapfd(self, capfd: CaptureFixture) -> None:
self.capfd = capfd
@patch("argparse._sys.argv", ["run_assemble.py", "--help"])
def test_usage(self) -> None:
with self.assertRaises(SystemExit):
main()
out, _ = self.capfd.readouterr()
self.assertTrue(out.startswith("usage:"))
BUILD_MANIFEST = os.path.join(os.path.dirname(__file__), "data", "opensearch-build-1.1.0.yml")
@patch("os.makedirs")
@patch("os.getcwd", return_value="curdir")
@patch("argparse._sys.argv", ["run_assemble.py", BUILD_MANIFEST])
@patch("run_assemble.Bundles.create")
@patch("run_assemble.BundleRecorder", return_value=MagicMock())
def test_main(self, mock_recorder: Mock, mock_bundles: Mock, getcwd: Mock, makeDirs: Mock) -> None:
mock_bundle = MagicMock(min_dist=MagicMock(archive_path="path"))
mock_bundles.return_value.__enter__.return_value = mock_bundle
main()
mock_bundle.install_min.assert_called()
mock_bundle.install_components.assert_called()
mock_bundle.package.assert_called_with(os.path.join("curdir", "tar", "dist", "opensearch"))
mock_recorder.return_value.write_manifest.assert_has_calls([
call("path"),
call(os.path.join("curdir", "tar", "dist", "opensearch"))
]) # manifest included in package
self.assertTrue(getcwd.called)
makeDirs.assert_called_once_with(ANY, exist_ok=True)