eugenegujing commented on code in PR #6473: URL: https://github.com/apache/texera/pull/6473#discussion_r3606019854
########## common/workflow-core/src/test/scala/org/apache/texera/amber/core/storage/model/DatasetFileDocumentSpec.scala: ########## @@ -0,0 +1,143 @@ +/* + * 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. + */ + +package org.apache.texera.amber.core.storage.model + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +import java.net.{URI, URLEncoder} +import java.nio.charset.StandardCharsets +import java.nio.file.Paths + +class DatasetFileDocumentSpec extends AnyFlatSpec with Matchers { + + // Realistic 40-char git commit hash, mirroring the URIs produced by FileResolver + // (format: dataset:///{repositoryName}/{versionHash}/{fileRelativePath}). + private val versionHash = "97fd4c2a755b69b7c66d322eab40b7e5c2ad5d10" + + "DatasetFileDocument" should "parse a valid 3-segment dataset URI into its components" in { + val uri = new URI(s"dataset:///test_dataset/$versionHash/1.txt") + val doc = new DatasetFileDocument(uri) + + doc.getRepositoryName() shouldBe "test_dataset" + doc.getVersionHash() shouldBe versionHash + doc.getFileRelativePath() shouldBe "1.txt" + } + + it should "join multi-segment relative paths correctly" in { + val uri = new URI(s"dataset:///my_repo/$versionHash/some/nested/dir/data.csv") + val doc = new DatasetFileDocument(uri) + + doc.getRepositoryName() shouldBe "my_repo" + doc.getVersionHash() shouldBe versionHash + doc.getFileRelativePath() shouldBe Paths.get("some", "nested", "dir", "data.csv").toString + } + + it should "URL-decode the version hash" in { + // FileResolver URL-encodes segments and then builds the URI with the multi-arg + // constructor, so uri.getPath still contains URLEncoder-encoded segments. + val uri = new URI("dataset", "", "/repo/hash%20with%2Bspecials/file.txt", null) + val doc = new DatasetFileDocument(uri) + + doc.getVersionHash() shouldBe "hash with+specials" + doc.getFileRelativePath() shouldBe "file.txt" + } Review Comment: This test intentionally uses the multi-arg URI constructor, while the suggestion proposes are already covered by the "URL-decode each relative path segment" test. -- 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]
