abderrahim commented on code in PR #1890:
URL: https://github.com/apache/buildstream/pull/1890#discussion_r1527187182


##########
tests/frontend/mirror.py:
##########
@@ -807,3 +807,93 @@ def test_mirror_expand_project_and_toplevel_root(cli, 
tmpdir):
         # Success if the expanded %{project-root} is found
         assert foo_str in contents
         assert bar_str in contents
+
+
+# Test a simple SourceMirror implementation which reads
+# plugin configuration and behaves in the same way as default
+# mirrors but using data in the plugin configuration instead.
+#
[email protected](DATA_DIR)
[email protected]("datafiles")
+def test_source_mirror_plugin(cli, tmpdir):
+    output_file = os.path.join(str(tmpdir), "output.txt")
+    project_dir = str(tmpdir)
+    element_dir = os.path.join(project_dir, "elements")
+    os.makedirs(element_dir, exist_ok=True)
+    element_name = "test.bst"
+    element_path = os.path.join(element_dir, element_name)
+    element = generate_element(output_file)
+    _yaml.roundtrip_dump(element, element_path)
+
+    project_file = os.path.join(project_dir, "project.conf")
+    project = {
+        "name": "test",
+        "min-version": "2.0",
+        "element-path": "elements",
+        "aliases": {
+            "foo": "FOO/",
+            "bar": "BAR/",
+        },
+        "mirrors": [
+            {
+                "name": "middle-earth",
+                "kind": "mirror",
+                "aliases": {
+                    "foo": ["<invalid>"],

Review Comment:
   Tbf, I think that we can have all the needed flexibility (at least in the 
case where there is an alias) by making `SourceMirror._get_alias_uris()` public 
for plugins to implement. This allows the plugins to express whatever they can 
support.
   
   As I said before, I think we could have this method just return the number 
of URLs it will provide, and have `SourceMirror.translate_url()` take an index 
rather than a "URL" which isn't exactly going to be a URL depending on what the 
source mirror is doing internally.
   
   In the absence of an alias, I think we can just pass `None` as an alias. 
`Project.get_alias_uris()` currently allows the alias to be `None`, so it is 
more a question of forwarding this to mirrors, and making sure sources and 
source fetchers don't explode when given a substitution URL for a `None` alias. 
We may not do this now, but explicitly state that alias can be `None` in 
`SourceMirror._get_alias_uris()` (or whatever it will be called once it's made 
public).
   
   The only question that remains is about a mirror plugin applying to more 
than one project: In the current state, a mirror is a property of a project, 
and `SourceMirror._get_alias_uris()` doesn't know about which project it is 
answering for. But I think this is a separate question.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to