Beispiel #1
0
 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'.",
     )
Beispiel #2
0
 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_to_dict(self, mock_config):
     mock_config.return_value = ConfigFile('{"version":"2.1"}')
     repo = MagicMock(ref="ref", url="repo")
     component = ComponentOpenSearchDashboardsMin(repo)
     self.assertEqual(
         component.to_dict(),
         {"name": "OpenSearch-Dashboards", "ref": "ref", "repository": "repo"},
     )
    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 properties(self) -> ConfigFile:
     path = os.path.join(self.git_repo.working_directory, "package.json")
     return ConfigFile.from_file(path)
 def test_properties(self, mock_config):
     mock_config.return_value = ConfigFile('{"version":"2.1"}')
     component = ComponentOpenSearchDashboardsMin(MagicMock(working_directory="path"))
     self.assertEqual(component.properties.get_value("version"), "2.1")
Beispiel #7
0
 def test_check_value_in(self):
     f = ConfigFile({"key": "value"})
     f.check_value_in("key", ["value"])
Beispiel #8
0
 def test_check_value_none_found(self):
     f = ConfigFile()
     with self.assertRaises(ConfigFile.UnexpectedKeyValueError) as err:
         f.check_value("invalid", "value")
     self.assertEqual(str(err.exception), "Expected to have invalid='value', but none was found.")
Beispiel #9
0
 def test_check_value_invalid(self):
     f = ConfigFile({"key": "value"})
     with self.assertRaises(ConfigFile.UnexpectedKeyValueError) as err:
         f.check_value("key", "invalid")
     self.assertEqual(str(err.exception), "Expected to have key='invalid', but was 'value'.")
Beispiel #10
0
 def test_check_value_from_json(self):
     f = ConfigFile('{"key":"value"}')
     f.check_value("key", "value")
Beispiel #11
0
 def test_check_value(self):
     f = ConfigFile({"key": "value"})
     f.check_value("key", "value")
Beispiel #12
0
 def test_get_value(self):
     f = ConfigFile({"key": "value"})
     self.assertEqual(f.get_value("key"), "value")
     self.assertEqual(f.get_value("invalid"), None)
     self.assertEqual(f.get_value("invalid", "default"), "default")
Beispiel #13
0
 def test_blank(self):
     f = ConfigFile()
     self.assertEqual(f.data, {})
Beispiel #14
0
 def test_version(self, mock_config: MagicMock) -> None:
     mock_config.return_value = ConfigFile('{"version":"2.1"}')
     component = ComponentOpenSearchDashboardsMin(
         MagicMock(working_directory="path"))
     self.assertEqual(component.version, "2.1")