def test_missing_component(self, mock_manifest: Mock, find_build_root: Mock) -> None: find_build_root.return_value = "url/linux/x64/builds/opensearch" check = CiCheckManifestComponent( InputComponentFromDist({ "name": "does-not-exist", "dist": "url" }), CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=True)) mock_manifest.from_url.return_value = BuildManifest.from_path( self.BUILD_MANIFEST) with self.assertRaises( CiCheckManifestComponent.MissingComponentError) as ctx: check.check() self.assertEqual( str(ctx.exception), "Missing does-not-exist in url/linux/x64/builds/opensearch/manifest.yml." ) find_build_root.assert_called()
def test_retrieves_manifests(self, mock_manifest: Mock, find_build_root: Mock) -> None: find_build_root.return_value = "url/linux/ARCH/builds/opensearch" check = CiCheckManifestComponent( InputComponentFromDist({ "name": "common-utils", "dist": "url" }), CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=True)) mock_manifest.from_url.return_value = BuildManifest.from_path( self.BUILD_MANIFEST) check.check() mock_manifest.from_url.assert_has_calls([ call("url/linux/ARCH/builds/opensearch/manifest.yml"), call("url/linux/ARCH/builds/opensearch/manifest.yml"), ]) find_build_root.assert_has_calls([ call("url", "linux", "x64", "opensearch"), call("url", "linux", "arm64", "opensearch"), ])
def __mock_check(self, props: Any = None, component: Component = None, snapshot: bool = True) -> CiCheckGradlePropertiesVersion: with patch.object(CiCheckGradlePropertiesVersion, "_CiCheckGradleProperties__get_properties") as mock_properties: mock_properties.return_value = PropertiesFile(props) return CiCheckGradlePropertiesVersion( component=component or MagicMock(), git_repo=MagicMock(), target=CiTarget(version="2.0.0", name="opensearch", qualifier="alpha1", snapshot=snapshot), )
def test_executes_gradle_command_snapshot(self): check = CiCheckGradlePublishToMavenLocal( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="opensearch", snapshot=True), ) check.check() check.git_repo.execute.assert_called_once_with( "./gradlew publishToMavenLocal -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true" )
def test_executes_gradle_command_with_arg(self): check = CiCheckGradleDependenciesOpenSearchVersion( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="opensearch", snapshot=True), args="plugin", ) check.git_repo.output.assert_called_once_with( './gradlew plugin:dependencies -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true --configuration compileOnly | grep -e "---"' )
def __mock_dependencies(self, props="", snapshot=False, gradle_project=None): git_repo = MagicMock() git_repo.output.return_value = props return TestCiCheckGradleDependencies.DummyDependencies( component=MagicMock(), git_repo=git_repo, target=CiTarget(version="1.1.0", name="opensearch", snapshot=snapshot), args=gradle_project, )
def test_executes_gradle_properties_snapshot(self): git_repo = MagicMock() git_repo.output.return_value = "" TestCiCheckGradleProperties.DummyProperties( component=MagicMock(), git_repo=git_repo, target=CiTarget(version="1.1.0", name="opensearch", snapshot=True), ) git_repo.output.assert_called_once_with("./gradlew properties -Dopensearch.version=1.1.0-SNAPSHOT -Dbuild.snapshot=true")
def __mock_check(self, props=None, component=None, snapshot=True): with patch.object( CiCheckGradlePropertiesVersion, "_CiCheckGradleProperties__get_properties") as mock_properties: mock_properties.return_value = PropertiesFile(props) return CiCheckGradlePropertiesVersion( component=component or MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="opensearch", snapshot=snapshot), )
def __mock_check(self, props=None): with patch.object( CiCheckGradleDependenciesOpenSearchVersion, "_CiCheckGradleDependencies__get_dependencies", ) as mock_dependencies: mock_dependencies.return_value = PropertiesFile(props) return CiCheckGradleDependenciesOpenSearchVersion( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="opensearch", snapshot=True), args=None, )
def test_executes_gradle_command_qualifier_snapshot(self) -> None: check = CiCheckGradlePublishToMavenLocal( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="2.0.0", name="opensearch", qualifier="alpha1", snapshot=True), ) check.check() exec_command = unittest.mock.create_autospec(check.git_repo.execute) exec_command.assert_called_once_with( "./gradlew publishToMavenLocal -Dopensearch.version=2.0.0-alpha1-SNAPSHOT -Dbuild.snapshot=true -Dbuild.version_qualifier=alpha1" )
def test_executes_gradle_command(self) -> None: check = CiCheckGradlePublishToMavenLocal( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=False), ) check.check() exec_command = unittest.mock.create_autospec(check.git_repo.execute) exec_command.assert_called_once_with( "./gradlew publishToMavenLocal -Dopensearch.version=1.1.0 -Dbuild.snapshot=false" )
def test_executes_gradle_command_qualifier(self) -> None: check = CiCheckGradleDependenciesOpenSearchVersion( component=MagicMock(), git_repo=MagicMock(), target=CiTarget(version="2.0.0", name="opensearch", qualifier="alpha1", snapshot=True), args=None, ) output = unittest.mock.create_autospec(check.git_repo.output) output.assert_called_once_with( './gradlew :dependencies -Dopensearch.version=2.0.0-alpha1-SNAPSHOT -Dbuild.snapshot=true -Dbuild.version_qualifier=alpha1 --configuration compileOnly | grep -e "---"' )
def test_invalid_check(self, *mocks): component = InputComponentFromDist({ "name": "common-utils", "dist": "url", "checks": ["invalid:check"] }) list = CiCheckListDist( component, CiTarget(version="1.1.0", name="opensearch", snapshot=True)) list.checkout("path") with self.assertRaises(CiCheckListDist.InvalidCheckError) as ctx: list.check() self.assertTrue( str(ctx.exception).startswith("Invalid check: invalid:check"))
def test_check(self, mock_manifest_from_url: Mock, find_build_root: Mock): mock_manifest_from_url.return_value = BuildManifest.from_path( self.BUILD_MANIFEST) component = InputComponentFromDist({ "name": "common-utils", "dist": "url", "checks": ["manifest:component"] }) list = CiCheckListDist( component, CiTarget(version="1.1.0", name="opensearch", snapshot=True)) list.check() mock_manifest_from_url.assert_called() find_build_root.assert_called()
def test_loads_package_json(self) -> None: props = TestCiCheckPackage.DummyProperties( component=MagicMock(), git_repo=MagicMock(working_directory=self.DATA), target=CiTarget(version="1.3.0", name="opensearch-dashboards", qualifier=None, snapshot=False), ) self.assertEqual(props.properties["name"].data, "opensearch-security-dashboards") self.assertEqual(props.properties["version"].data, "1.3.0.0") self.assertEqual(props.properties["opensearchDashboards.version"].data, "1.3.0")
def test_executes_gradle_properties_qualifier_snapshot(self) -> None: git_repo = MagicMock() git_repo.output.return_value = "" TestCiCheckGradleProperties.DummyProperties( component=MagicMock(), git_repo=git_repo, target=CiTarget(version="2.0.0", name="opensearch", qualifier="alpha1", snapshot=True), ) git_repo.output.assert_called_once_with( "./gradlew properties -Dopensearch.version=2.0.0-alpha1-SNAPSHOT -Dbuild.snapshot=true -Dbuild.version_qualifier=alpha1" )
def test_executes_gradle_properties(self) -> None: git_repo = MagicMock() git_repo.output.return_value = "" TestCiCheckGradleProperties.DummyProperties( component=MagicMock(), git_repo=git_repo, target=CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=False), ) git_repo.output.assert_called_once_with( "./gradlew properties -Dopensearch.version=1.1.0 -Dbuild.snapshot=false" )
def __mock_check(self, props: Any = None, component: Component = None, snapshot: bool = True) -> CiCheckNpmPackageVersion: with patch.object( CiCheckNpmPackageVersion, "_CiCheckPackage__get_properties") as mock_properties: mock_properties.return_value = PropertiesFile(props) return CiCheckNpmPackageVersion( component=component or MagicMock(), git_repo=MagicMock(), target=CiTarget(version="1.1.0", name="dashboards-plugin", qualifier=None, snapshot=snapshot), )
def __check__(self): target = CiTarget(version=self.manifest.build.version, name=self.manifest.build.filename, snapshot=self.args.snapshot) with TemporaryDirectory(keep=self.args.keep, chdir=True) as work_dir: logging.info(f"Sanity-testing in {work_dir.name}") logging.info(f"Sanity testing {self.manifest.build.name}") for component in self.manifest.components.select( focus=self.args.component): logging.info(f"Sanity testing {component.name}") ci_check_list = CiCheckLists.from_component(component, target) ci_check_list.checkout(work_dir.name) ci_check_list.check() logging.info("Done.")
def test_opensearch_version(self): self.assertEqual( CiTarget(version="1.1.0", name="opensearch", snapshot=False).opensearch_version, "1.1.0")
def test_component_version_qualifier_snapshot(self) -> None: self.assertEqual( CiTarget(version="1.3.0", name="opensearch", qualifier="alpha1", snapshot=True).component_version, "1.3.0.0-alpha1-SNAPSHOT", )
def test_component_version(self) -> None: self.assertEqual(CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=False).component_version, "1.1.0.0")
def test_opensearch_version_snapshot(self) -> None: self.assertEqual( CiTarget(version="1.1.0", name="opensearch", qualifier=None, snapshot=True).opensearch_version, "1.1.0-SNAPSHOT", )
def test_component_version_snapshot(self): self.assertEqual( CiTarget(version="1.1.0", name="opensearch", snapshot=True).component_version, "1.1.0.0-SNAPSHOT", )