def test_install_maven_dependencies_remote(self, mock_request, mock_copyfile, mock_makedirs):
        counter = ThreadSafeCounter()
        mock_request.side_effect = counter.thread_safe_count
        dependency_installer = DependencyInstallerOpenSearch(
            "https://ci.opensearch.org/x/y",
            BuildManifest.from_path(self.BUILD_MANIFEST),
            BundleManifest.from_path(self.DIST_MANIFEST_REMOTE)
        )

        dependency_installer.install_maven_dependencies()
        self.assertEqual(counter.call_count, 2375)

        mock_makedirs.assert_called_with(
            os.path.realpath(
                os.path.join(
                    dependency_installer.maven_local_path, "org", "opensearch", "notification"
                )
            ),
            exist_ok=True
        )
        mock_copyfile.assert_not_called()
        mock_request.assert_has_calls([
            call(
                "https://ci.opensearch.org/x/y/builds/opensearch/maven/org/opensearch/notification/alerting-notification-1.2.0.0.jar",
                os.path.realpath(os.path.join(dependency_installer.maven_local_path, "org", "opensearch", "notification", "alerting-notification-1.2.0.0.jar"))
            )
        ])
Beispiel #2
0
    def test_install_maven_dependencies_local(self, mock_request: Mock,
                                              mock_copyfile: Mock,
                                              mock_makedirs: Mock) -> None:
        counter = ThreadSafeCounter()
        mock_copyfile.side_effect = counter.thread_safe_count

        dependency_installer = DependencyInstallerOpenSearch(
            self.DATA, BuildManifest.from_path(self.BUILD_MANIFEST),
            BundleManifest.from_path(self.DIST_MANIFEST_LOCAL))

        dependency_installer.install_maven_dependencies()

        mock_makedirs.assert_called_with(os.path.realpath(
            os.path.join(dependency_installer.maven_local_path, "org",
                         "opensearch", "notification")),
                                         exist_ok=True)
        mock_request.assert_not_called()
        self.assertEqual(counter.call_count, 2375)
        mock_copyfile.assert_has_calls([
            call(
                os.path.join(self.DATA, "builds", "opensearch", "maven", "org",
                             "opensearch", "notification",
                             "alerting-notification-1.2.0.0.jar"),
                os.path.realpath(
                    os.path.join(dependency_installer.maven_local_path, "org",
                                 "opensearch", "notification",
                                 "alerting-notification-1.2.0.0.jar")))
        ])
    def test_thread_safe_count(self, mock_lock: MagicMock) -> None:
        counter = ThreadSafeCounter()

        counter.thread_safe_count()

        self.assertEqual(counter.call_count, 1)
    def test_constructor(self, mock_lock: MagicMock) -> None:
        counter = ThreadSafeCounter()

        self.assertEqual(counter.call_count, 0)
        mock_lock.assert_called_once()