kacpermuda commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3218196369


##########
providers/apache/hdfs/tests/unit/apache/hdfs/assets/test_hdfs.py:
##########
@@ -0,0 +1,92 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import urllib.parse
+
+import pytest
+
+from airflow.providers.apache.hdfs.assets.hdfs import (
+    convert_asset_to_openlineage,
+    create_asset,
+    sanitize_uri,
+)
+from airflow.providers.common.compat.assets import Asset
+
+
[email protected](
+    ("original", "normalized"),
+    [
+        pytest.param(
+            "hdfs://namenode:8020/data/file.csv",
+            "hdfs://namenode:8020/data/file.csv",
+            id="normalized",
+        ),
+        pytest.param(
+            "hdfs://namenode/data/file.csv",
+            "hdfs://namenode/data/file.csv",
+            id="no-explicit-port",
+        ),
+    ],
+)
+def test_sanitize_uri_pass(original: str, normalized: str) -> None:
+    uri_i = urllib.parse.urlsplit(original)
+    uri_o = sanitize_uri(uri_i)
+    assert urllib.parse.urlunsplit(uri_o) == normalized
+
+
[email protected](
+    "value",
+    [
+        pytest.param("hdfs://", id="blank"),
+        pytest.param("hdfs:///path/to/file", id="no-host"),
+    ],
+)
+def test_sanitize_uri_fail(value: str) -> None:
+    uri_i = urllib.parse.urlsplit(value)
+    with pytest.raises(ValueError, match="URI format hdfs:// must contain"):
+        sanitize_uri(uri_i)
+
+
[email protected](
+    ("path", "expected_uri"),
+    [
+        pytest.param("/data/file.csv", "hdfs://namenode:8020//data/file.csv", 
id="root"),
+        pytest.param("data/file.csv", "hdfs://namenode:8020/data/file.csv", 
id="no-leading-slash"),

Review Comment:
   I applied this logic to hdfs, ftp and sftp. I wanted to preserve distinction 
between absolute path and relative path, hence double slash if path passed is 
absolute, from root. My assumption was that a path from root is different than 
relative - relative should probably use user home directory as reference, so 
they are two completely different paths in this scenario.



-- 
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