blackmwk commented on code in PR #3106:
URL: https://github.com/apache/iceberg-rust/pull/3106#discussion_r4750775662
##########
crates/catalog/rest/src/catalog.rs:
##########
@@ -2017,47 +1870,46 @@ mod tests {
catalog_session,
seen_session_ids: seen_session_ids.clone(),
fail_contextual_session,
- });
+ })
+ .await;
(catalog, seen_session_ids)
}
fn test_client() -> HttpClient {
- HttpClient::new(
- &RestCatalogConfig::builder()
- .uri("http://localhost".to_string())
- .build(),
- )
- .unwrap()
+ RestCatalogTestFixture::builder()
+ .uri("http://localhost".to_string())
+ .build()
+ .http_client()
+ .unwrap()
}
/// Builds a [`RestSessionCatalog`] with the default test storage factory
and runtime.
- fn session_catalog(config: RestCatalogConfig) -> RestSessionCatalog {
+ async fn session_catalog(config: RestCatalogTestFixture) ->
RestSessionCatalog {
RestSessionCatalog::new(
config,
None,
Some(Arc::new(LocalFsStorageFactory)),
Runtime::current(),
None,
)
+ .await
+ .unwrap()
}
#[tokio::test]
async fn test_page_size_precedence() {
Review Comment:
Use rstest
##########
crates/catalog/rest/src/catalog.rs:
##########
@@ -1916,13 +1536,243 @@ mod tests {
use iceberg::transaction::{ApplyTransactionAction, Transaction};
use iceberg_test_utils::test_runtime;
use mockito::{Matcher, Mock, Server, ServerGuard};
+ use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
+ use rstest::rstest;
use serde_json::json;
+ use typed_builder::TypedBuilder;
use uuid::uuid;
use super::*;
use crate::auth::AuthSession;
+ use crate::properties::{
+ REST_CATALOG_PROP_PAGE_SIZE,
REST_CATALOG_PROP_TABLE_CACHE_EXPIRE_AFTER_WRITE_MS,
+ REST_CATALOG_PROP_TABLE_CACHE_MAX_ENTRIES, REST_CATALOG_PROP_WAREHOUSE,
+ };
use crate::request::HttpRequest;
+ #[derive(TypedBuilder)]
+ pub(crate) struct RestCatalogTestFixture {
+ uri: String,
+ #[builder(default, setter(strip_option))]
+ warehouse: Option<String>,
+ #[builder(default)]
+ props: HashMap<String, String>,
+ }
+
+ impl RestCatalogTestFixture {
+ pub(super) fn into_props(mut self) -> HashMap<String, String> {
+ self.props
+ .insert(REST_CATALOG_PROP_URI.to_string(), self.uri);
+ if let Some(warehouse) = self.warehouse {
+ self.props
+ .insert(REST_CATALOG_PROP_WAREHOUSE.to_string(),
warehouse);
+ }
+ self.props
+ }
+
+ pub(crate) fn properties(self) -> Result<RestCatalogProperties> {
+ RestCatalogProperties::from_properties(&self.into_props())
+ }
+
+ fn auth_manager(
+ self,
+ auth_manager_override: Option<Arc<dyn AuthManager>>,
+ ) -> Result<Arc<dyn AuthManager>> {
+ let props = self.into_props();
+ let config = RestCatalogProperties::for_handshake(&props)?;
+ RestCatalogClient::resolve_auth_manager(&config, &props,
auth_manager_override)
+ }
+
+ pub(crate) fn http_client(self) -> Result<HttpClient> {
+ Ok(HttpClient::new(Client::default(), &self.properties()?))
+ }
+ }
+
+ #[tokio::test]
+ async fn test_endpoints_use_resolved_properties() {
+ let mut server = Server::new_async().await;
+ let config_mock = server.mock("GET", "/v1/config")
+ .with_status(200)
+ .with_body(r#"{"defaults": {}, "overrides": {"uri":
"http://localhost:8181", "prefix": "catalog"}}"#)
+ .create_async().await;
+ let catalog = session_catalog(
+ RestCatalogTestFixture::builder()
+ .uri(server.url())
+ .props(HashMap::from([(
+ "prefix".to_string(),
+ "original".to_string(),
+ )]))
+ .build(),
+ )
+ .await;
+ let client = catalog.client();
+ let properties = client.config.clone();
+ assert_eq!(
+ (
+ client.urls.base.as_str(),
+ client.namespaces_endpoint(),
+ client.rename_table_endpoint()
+ ),
+ (
+ "http://localhost:8181/v1/catalog",
+ "http://localhost:8181/v1/catalog/namespaces",
+ "http://localhost:8181/v1/catalog/tables/rename"
+ ),
+ );
+ assert_eq!(client.config, properties);
+ config_mock.assert_async().await;
+ }
+
+ #[tokio::test]
+ async fn test_cache_property_precedence() {
Review Comment:
Use rstest
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]