-
Notifications
You must be signed in to change notification settings - Fork 282
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: dblock <dblock@dblock.org>
- Loading branch information
Showing
17 changed files
with
739 additions
and
45 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
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
File renamed without changes.
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
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
384 changes: 384 additions & 0 deletions
384
bundle-workflow/tests/tests_ci_workflow/data/job_scheduler_dependencies.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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
80 changes: 80 additions & 0 deletions
80
bundle-workflow/tests/tests_ci_workflow/test_check_gradle_dependencies.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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# 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 MagicMock | ||
|
||
from ci_workflow.check_gradle_dependencies import CheckGradleDependencies | ||
|
||
|
||
class TestCheckGradleDependencies(unittest.TestCase): | ||
class DummyDependencies(CheckGradleDependencies): | ||
def check(self): | ||
pass | ||
|
||
def __mock_dependencies(self, props="", snapshot=False, gradle_project=None): | ||
git_repo = MagicMock() | ||
git_repo.output.return_value = props | ||
|
||
return TestCheckGradleDependencies.DummyDependencies( | ||
component=MagicMock(), | ||
git_repo=git_repo, | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=snapshot, | ||
gradle_project=gradle_project, | ||
) | ||
|
||
def test_executes_gradle_dependencies(self): | ||
check = self.__mock_dependencies() | ||
check.git_repo.output.assert_called_once_with( | ||
'./gradlew :dependencies -Dopensearch.version=1.1.0 -Dbuild.snapshot=false | grep -e "---"' | ||
) | ||
|
||
def test_executes_gradle_dependencies_snapshot(self): | ||
check = self.__mock_dependencies(snapshot=True) | ||
check.git_repo.output.assert_called_once_with( | ||
'./gradlew :dependencies -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true | grep -e "---"' | ||
) | ||
|
||
def test_executes_gradle_dependencies_project(self): | ||
check = self.__mock_dependencies(snapshot=True, gradle_project="project") | ||
check.git_repo.output.assert_called_once_with( | ||
'./gradlew project:dependencies -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true | grep -e "---"' | ||
) | ||
|
||
def test_loads_tree(self): | ||
data_path = os.path.join( | ||
os.path.dirname(__file__), "data/job_scheduler_dependencies.txt" | ||
) | ||
with open(data_path) as f: | ||
check = self.__mock_dependencies(props=f.read()) | ||
self.assertEqual( | ||
check.dependencies.get_value("org.opensearch:opensearch"), | ||
"1.1.0-SNAPSHOT", | ||
) | ||
self.assertEqual( | ||
check.dependencies.get_value( | ||
"org.opensearch:opensearch/org.opensearch:opensearch-core" | ||
), | ||
"1.1.0-SNAPSHOT", | ||
) | ||
self.assertEqual( | ||
check.dependencies.get_value("com.puppycrawl.tools:checkstyle"), "8.29" | ||
) | ||
self.assertEqual( | ||
check.dependencies.get_value( | ||
"com.puppycrawl.tools:checkstyle/antlr:antlr" | ||
), | ||
"2.7.7", | ||
) | ||
self.assertEqual( | ||
check.dependencies.get_value( | ||
"com.puppycrawl.tools:checkstyle/commons-beanutils:commons-beanutils/commons-collections:commons-collections" | ||
), | ||
"3.2.2", | ||
) |
78 changes: 78 additions & 0 deletions
78
bundle-workflow/tests/tests_ci_workflow/test_check_gradle_dependencies_opensearch.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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 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 unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from ci_workflow.check_gradle_dependencies_opensearch import ( | ||
CheckGradleDependenciesOpenSearchVersion, | ||
CheckGradlePluginDependenciesOpenSearchVersion) | ||
from system.properties_file import PropertiesFile | ||
|
||
|
||
class TestCheckGradleDependenciesOpenSearchVersion(unittest.TestCase): | ||
def __mock_check(self, props=None): | ||
with patch.object( | ||
CheckGradleDependenciesOpenSearchVersion, | ||
"_CheckGradleDependencies__get_dependencies", | ||
) as mock_dependencies: | ||
mock_dependencies.return_value = PropertiesFile(props) | ||
return CheckGradleDependenciesOpenSearchVersion( | ||
component=MagicMock(), | ||
git_repo=MagicMock(), | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=True, | ||
) | ||
|
||
def test_gradle_project(self): | ||
self.assertIsNone(self.__mock_check().gradle_project) | ||
|
||
def test_has_version(self): | ||
self.__mock_check({"org.opensearch:opensearch": "1.1.0-SNAPSHOT"}).check() | ||
|
||
def test_missing_version(self): | ||
with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err: | ||
self.__mock_check({}).check() | ||
self.assertEqual( | ||
str(err.exception), | ||
"Expected to have org.opensearch:opensearch='1.1.0-SNAPSHOT', but none was found.", | ||
) | ||
|
||
def test_invalid_version(self): | ||
with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err: | ||
self.__mock_check({"org.opensearch:opensearch": "1.2.0-SNAPSHOT"}).check() | ||
self.assertEqual( | ||
str(err.exception), | ||
"Expected to have org.opensearch:opensearch='1.1.0-SNAPSHOT', but was '1.2.0-SNAPSHOT'.", | ||
) | ||
|
||
def test_executes_gradle_command(self): | ||
check = CheckGradleDependenciesOpenSearchVersion( | ||
component=MagicMock(), | ||
git_repo=MagicMock(), | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=True, | ||
) | ||
check.git_repo.output.assert_called_once_with( | ||
'./gradlew :dependencies -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true | grep -e "---"' | ||
) | ||
|
||
|
||
class TestCheckGradlePluginDependenciesOpenSearchVersion(unittest.TestCase): | ||
def test_executes_gradle_plugin_command(self): | ||
check = CheckGradlePluginDependenciesOpenSearchVersion( | ||
component=MagicMock(), | ||
git_repo=MagicMock(), | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=True, | ||
) | ||
self.assertEqual(check.gradle_project, "plugin") | ||
check.git_repo.output.assert_called_once_with( | ||
'./gradlew plugin:dependencies -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true | grep -e "---"' | ||
) |
48 changes: 48 additions & 0 deletions
48
bundle-workflow/tests/tests_ci_workflow/test_check_gradle_properties.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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 unittest | ||
from unittest.mock import MagicMock | ||
|
||
from ci_workflow.check_gradle_properties import CheckGradleProperties | ||
|
||
|
||
class TestCheckGradleProperties(unittest.TestCase): | ||
class DummyProperties(CheckGradleProperties): | ||
def check(self): | ||
pass | ||
|
||
def test_executes_gradle_properties(self): | ||
git_repo = MagicMock() | ||
git_repo.output.return_value = "" | ||
|
||
TestCheckGradleProperties.DummyProperties( | ||
component=MagicMock(), | ||
git_repo=git_repo, | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=False, | ||
) | ||
|
||
git_repo.output.assert_called_once_with( | ||
"./gradlew properties -Dopensearch.version=1.1.0 -Dbuild.snapshot=false" | ||
) | ||
|
||
def test_executes_gradle_properties_snapshot(self): | ||
git_repo = MagicMock() | ||
git_repo.output.return_value = "" | ||
|
||
TestCheckGradleProperties.DummyProperties( | ||
component=MagicMock(), | ||
git_repo=git_repo, | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=True, | ||
) | ||
|
||
git_repo.output.assert_called_once_with( | ||
"./gradlew properties -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true" | ||
) |
46 changes: 46 additions & 0 deletions
46
bundle-workflow/tests/tests_ci_workflow/test_check_gradle_properties_version.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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 unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from ci_workflow.check_gradle_properties_version import \ | ||
CheckGradlePropertiesVersion | ||
from system.properties_file import PropertiesFile | ||
|
||
|
||
class TestCheckGradlePropertiesVersion(unittest.TestCase): | ||
def __mock_check(self, props=None): | ||
with patch.object( | ||
CheckGradlePropertiesVersion, "_CheckGradleProperties__get_properties" | ||
) as mock_properties: | ||
mock_properties.return_value = PropertiesFile(props) | ||
return CheckGradlePropertiesVersion( | ||
component=MagicMock(), | ||
git_repo=MagicMock(), | ||
version="1.1.0", | ||
arch="x86", | ||
snapshot=True, | ||
) | ||
|
||
def test_has_version(self): | ||
self.__mock_check({"version": "1.1.0.0-SNAPSHOT"}).check() | ||
|
||
def test_missing_version(self): | ||
with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err: | ||
self.__mock_check().check() | ||
self.assertEqual( | ||
str(err.exception), | ||
"Expected to have version='1.1.0.0-SNAPSHOT', but none was found.", | ||
) | ||
|
||
def test_invalid_version(self): | ||
with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err: | ||
self.__mock_check({"version": "1.2.0-SNAPSHOT"}).check() | ||
self.assertEqual( | ||
str(err.exception), | ||
"Expected to have version='1.1.0.0-SNAPSHOT', but was '1.2.0-SNAPSHOT'.", | ||
) |
Oops, something went wrong.