def check(self, path: str) -> None: if os.path.splitext(path)[1] != ".zip": raise BuildArtifactCheck.BuildArtifactInvalidError( path, "Not a zip file.") match = re.search(r"^(\w+)-[\d\.]*.*.zip$", os.path.basename(path)) if not match: raise BuildArtifactCheck.BuildArtifactInvalidError( path, "Expected filename to be in the format of pluginName-1.1.0.zip." ) plugin_name = match.group(1) valid_filenames = self.__valid_paths(plugin_name) if not os.path.basename(path) in valid_filenames: raise BuildArtifactCheck.BuildArtifactInvalidError( path, f"Expected filename to to be one of {valid_filenames}.") with ZipFile(path, "r") as zip: data = zip.read( f"opensearch-dashboards/{plugin_name}/opensearch_dashboards.json" ).decode("UTF-8") config = ConfigFile(data) try: config.check_value_in( "version", self.target.compatible_component_versions) config.check_value_in("opensearchDashboardsVersion", self.target.compatible_versions) except ConfigFile.CheckError as e: raise BuildArtifactCheck.BuildArtifactInvalidError( path, e.__str__()) logging.info( f'Checked {path} ({config.get_value("version", "N/A")})')
def test_check_value_in_none_found(self): f = ConfigFile() with self.assertRaises(ConfigFile.UnexpectedKeyValuesError) as err: f.check_value_in("invalid", ["one", "two"]) self.assertEqual( str(err.exception), "Expected to have invalid=any of ['one', 'two'], but none was found.", )
def test_check_value_in_invalid(self): f = ConfigFile({"key": "value"}) with self.assertRaises(ConfigFile.UnexpectedKeyValuesError) as err: f.check_value_in("key", ["one", "two"]) self.assertEqual( str(err.exception), "Expected to have key=any of ['one', 'two'], but was 'value'.", )
def test_check_value_in(self): f = ConfigFile({"key": "value"}) f.check_value_in("key", ["value"])