flyrain commented on code in PR #2496:
URL: https://github.com/apache/polaris/pull/2496#discussion_r2320342836
##########
runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergAllowedLocationTest.java:
##########
@@ -131,6 +153,154 @@ private static TestServices getTestServices() {
return services;
}
+ @Test
+ void testViewWithAllowedLocations(@TempDir Path tmpDir) {
+ var viewId = TableIdentifier.of(namespace, "view");
+ var services = getTestServices();
+ var catalogLocation =
tmpDir.resolve(catalog).toAbsolutePath().toUri().toString();
+ createCatalog(services, Map.of(), catalogLocation,
List.of(catalogLocation));
+ var namespaceLocation = catalogLocation + "/" + namespace;
+ createNamespace(services, namespaceLocation);
+
+ // create a view with allowed locations
+ String customAllowedLocation1 = Paths.get(namespaceLocation,
"custom-location1").toString();
+ String customAllowedLocation2 = Paths.get(namespaceLocation,
"custom-location2").toString();
+
+ CreateViewRequest createViewRequest =
+ getCreateViewRequest(customAllowedLocation2, viewId.name(),
customAllowedLocation1);
+ var response =
+ services
+ .restApi()
+ .createView(
+ catalog,
+ namespace,
+ createViewRequest,
+ services.realmContext(),
+ services.securityContext());
+
+ assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
+
+ // update the view with allowed locations
+ String customAllowedLocation3 = Paths.get(namespaceLocation,
"custom-location3").toString();
+
+ Map<String, String> updatedProperties = new HashMap<>();
+ updatedProperties.put(USER_SPECIFIED_WRITE_METADATA_LOCATION_KEY,
customAllowedLocation3);
+
+ UpdateTableRequest updateRequest =
+ UpdateTableRequest.create(
+ viewId, List.of(), List.of(new
MetadataUpdate.SetProperties(updatedProperties)));
+
+ var updateResponse =
+ services
+ .catalogAdapter()
+ .newHandlerWrapper(services.securityContext(), catalog)
+ .replaceView(viewId, updateRequest);
+ assertEquals(
+
updateResponse.metadata().properties().get(USER_SPECIFIED_WRITE_METADATA_LOCATION_KEY),
+ customAllowedLocation3);
+ }
+
+ @Test
+ void testViewOutsideAllowedLocations(@TempDir Path tmpDir) {
+ var viewId = TableIdentifier.of(namespace, "view");
+ var services = getTestServices();
+
+ var catalogBaseLocation =
tmpDir.resolve(catalog).toAbsolutePath().toUri().toString();
+ var namespaceLocation = catalogBaseLocation + "/" + namespace;
+
+ createCatalog(services, Map.of(), catalogBaseLocation,
List.of(catalogBaseLocation));
+ createNamespace(services, namespaceLocation);
+
+ var locationNotAllowed = Paths.get(tmpDir.toUri().toString()).toString();
Review Comment:
Using this to make it more explicitly
```
tmpDir.resolve("location-not-allowed").toAbsolutePath().toUri().toString();
```
--
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]