|
18 | 18 | */ |
19 | 19 | package org.apache.polaris.service.storage; |
20 | 20 |
|
| 21 | +import java.net.URISyntaxException; |
21 | 22 | import org.apache.polaris.core.storage.StorageLocation; |
| 23 | +import org.apache.polaris.core.storage.azure.AzureLocation; |
22 | 24 | import org.assertj.core.api.Assertions; |
23 | 25 | import org.junit.jupiter.api.Test; |
24 | 26 |
|
25 | 27 | public class StorageLocationTest { |
26 | 28 |
|
27 | 29 | @Test |
28 | 30 | public void testOfDifferentPrefixes() { |
29 | | - StorageLocation StandardLocation = StorageLocation.of("file:///path/to/file"); |
| 31 | + StorageLocation standardLocation = StorageLocation.of("file:///path/to/file"); |
30 | 32 | StorageLocation slashLeadingLocation = StorageLocation.of("/path/to/file"); |
| 33 | + StorageLocation manySlashLeadingLocation = StorageLocation.of("////////path/to/file"); |
31 | 34 | StorageLocation fileSingleSlashLocation = StorageLocation.of("file:/path/to/file"); |
32 | | - Assertions.assertThat(slashLeadingLocation.equals(StandardLocation)).isTrue(); |
33 | | - Assertions.assertThat(fileSingleSlashLocation.equals(StandardLocation)).isTrue(); |
| 35 | + StorageLocation fileTooManySlashesLocation = StorageLocation.of("file://///////path/to/file"); |
| 36 | + Assertions.assertThat(slashLeadingLocation.equals(standardLocation)).isTrue(); |
| 37 | + Assertions.assertThat(manySlashLeadingLocation.equals(standardLocation)).isTrue(); |
| 38 | + Assertions.assertThat(fileSingleSlashLocation.equals(standardLocation)).isTrue(); |
| 39 | + Assertions.assertThat(fileTooManySlashesLocation.equals(standardLocation)).isTrue(); |
| 40 | + Assertions.assertThat(standardLocation).isExactlyInstanceOf(StorageLocation.class); |
| 41 | + Assertions.assertThat(slashLeadingLocation).isExactlyInstanceOf(StorageLocation.class); |
| 42 | + Assertions.assertThat(manySlashLeadingLocation).isExactlyInstanceOf(StorageLocation.class); |
| 43 | + Assertions.assertThat(fileSingleSlashLocation).isExactlyInstanceOf(StorageLocation.class); |
| 44 | + Assertions.assertThat(fileTooManySlashesLocation).isExactlyInstanceOf(StorageLocation.class); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testBlobStorageLocations() { |
| 49 | + StorageLocation azureLocation = |
| 50 | + StorageLocation.of("wasb://container@storageaccount.blob.core.windows.net/myfile"); |
| 51 | + Assertions.assertThat(azureLocation instanceof AzureLocation).isTrue(); |
| 52 | + azureLocation = |
| 53 | + StorageLocation.of("abfss://container@storageaccount.blob.core.windows.net/myfile"); |
| 54 | + Assertions.assertThat(azureLocation instanceof AzureLocation).isTrue(); |
| 55 | + |
| 56 | + String s3LocationStr = "s3://test-bucket/mydirectory"; |
| 57 | + StorageLocation s3Location = StorageLocation.of(s3LocationStr); |
| 58 | + Assertions.assertThat(s3Location instanceof AzureLocation).isFalse(); |
| 59 | + |
| 60 | + Assertions.assertThat(s3Location.toString()).isEqualTo(s3LocationStr); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testSpecialCharacters() { |
| 65 | + // Blob Storage does not have validations |
| 66 | + String specialCharsBlobStorage = "s3://test-bucket/quote'/equals=/period/../myfile.parquet"; |
| 67 | + StorageLocation s3LocationSpecialCharacters = StorageLocation.of(specialCharsBlobStorage); |
| 68 | + |
| 69 | + Assertions.assertThat(s3LocationSpecialCharacters.toString()) |
| 70 | + .isEqualTo(specialCharsBlobStorage); |
| 71 | + |
| 72 | + // But local filesystems do |
| 73 | + String specialCharsLocalStorage = "file:///var/tmp\"/myfile.parquet"; |
| 74 | + Assertions.assertThatThrownBy( |
| 75 | + () -> { |
| 76 | + StorageLocation.of(specialCharsLocalStorage); |
| 77 | + }) |
| 78 | + .hasCauseInstanceOf(URISyntaxException.class); |
34 | 79 | } |
35 | 80 | } |
0 commit comments