-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vacha <[email protected]>
- Loading branch information
Showing
3 changed files
with
72 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
|
||
|
||
class TestUtils: | ||
def get_test_dependencies(): | ||
test_dir = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), "../../../src/test_workflow" | ||
) | ||
return [ | ||
file_name | ||
for file_name in os.listdir(test_dir) | ||
if os.path.isfile(os.path.join(test_dir, file_name)) | ||
] |
82 changes: 35 additions & 47 deletions
82
bundle-workflow/tests/test_workflow/test_dependency_installer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,47 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from src.test_workflow.dependency_installer import DependencyInstaller | ||
from helper.test_utils import TestUtils | ||
|
||
from test_workflow.dependency_installer import DependencyInstaller | ||
|
||
|
||
class DependencyInstallerTests(unittest.TestCase): | ||
dependency_installer = DependencyInstaller("7", "job-scheduler", "1.1.0.0", "arm64") | ||
def setUp(self): | ||
self.dependency_installer = DependencyInstaller( | ||
"7", "job-scheduler", "1.1.0.0", "arm64" | ||
) | ||
|
||
def test_get_dependency_path(self): | ||
def test_dependency_path(self): | ||
self.assertEqual( | ||
"org/opensearch/job-scheduler/1.1.0.0/", | ||
self.dependency_installer.get_dependency_path(), | ||
) | ||
|
||
def test_copy_to_maven_local(self): | ||
dependency_from_s3 = self.get_test_dependencies() | ||
maven_local_path = self.dependency_installer.get_maven_local_path() | ||
if not os.path.exists(maven_local_path): | ||
os.makedirs(maven_local_path) | ||
else: | ||
self.clean_maven_local_path(maven_local_path) | ||
self.dependency_installer.copy_to_maven_local( | ||
dependency_from_s3, maven_local_path | ||
self.dependency_installer.dependency_path, | ||
) | ||
self.assertCountEqual(dependency_from_s3, os.listdir(maven_local_path)) | ||
self.assertListEqual(dependency_from_s3, os.listdir(maven_local_path)) | ||
|
||
def test_install(self): | ||
maven_local_path = self.dependency_installer.get_maven_local_path() | ||
self.clean_maven_local_path(maven_local_path) | ||
self.dependency_installer.install() | ||
self.assertCountEqual( | ||
self.get_test_dependencies(), os.listdir(maven_local_path) | ||
) | ||
self.assertListEqual(self.get_test_dependencies(), os.listdir(maven_local_path)) | ||
|
||
def get_test_dependencies(self): | ||
test_dir = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), "../../src/test_workflow" | ||
) | ||
return [ | ||
file_name | ||
for file_name in os.listdir(test_dir) | ||
if os.path.isfile(os.path.join(test_dir, file_name)) | ||
] | ||
|
||
def clean_maven_local_path(self, maven_local_path): | ||
for file_name in os.listdir(maven_local_path): | ||
local_file_path = os.path.join(maven_local_path, file_name) | ||
try: | ||
if os.path.isfile(local_file_path) or os.path.islink(local_file_path): | ||
os.unlink(local_file_path) | ||
elif os.path.isdir(local_file_path): | ||
shutil.rmtree(local_file_path) | ||
except OSError as e: | ||
print(f"Failed to clean {local_file_path}. Reason: {e}") | ||
raise | ||
maven_local_path = self.dependency_installer.maven_local_path | ||
with patch( | ||
"test_workflow.dependency_installer.DependencyInstaller.MavenLocalFileHandler.copy" | ||
) as mock_maven_copy: | ||
self.dependency_installer.maven_local_file_handler = [ | ||
DependencyInstaller.MavenLocalFileHandler(), | ||
DependencyInstaller.MavenLocalFileHandler(), | ||
] | ||
self.dependency_installer.install() | ||
mock_maven_copy.assert_called_with( | ||
TestUtils.get_test_dependencies(), maven_local_path | ||
) | ||
|
||
|
||
class MavenLocalFileHandlerTests(unittest.TestCase): | ||
def setUp(self): | ||
self.maven_local_file_handler = DependencyInstaller.MavenLocalFileHandler() | ||
|
||
def test_copy(self): | ||
maven_local_path = tempfile.mkdtemp() | ||
test_files = TestUtils.get_test_dependencies() | ||
self.maven_local_file_handler.copy(test_files, maven_local_path) | ||
self.assertCountEqual(test_files, os.listdir(maven_local_path)) | ||
self.assertListEqual(test_files, os.listdir(maven_local_path)) |