CTTY commented on code in PR #3288: URL: https://github.com/apache/iceberg-rust/pull/3288#discussion_r4429798084
########## crates/storage/common/tests/file_io_suite.rs: ########## @@ -0,0 +1,494 @@ +// 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. + +//! Shared FileIO integration tests parameterized over storage backends. + +mod common; + +use bytes::Bytes; +use common::{StorageKind, load_storage}; +use futures::StreamExt; +use iceberg_test_utils::storage::roundtrip_file_io; +use rstest::rstest; + +#[rstest] +#[case::opendal_s3(StorageKind::OpenDalS3)] +#[case::opendal_gcs(StorageKind::OpenDalGcs)] +#[case::opendal_fs(StorageKind::OpenDalFs)] +#[case::opendal_memory(StorageKind::OpenDalMemory)] +#[tokio::test] +async fn test_file_io_exists(#[case] kind: StorageKind) -> iceberg::Result<()> { + let Some(harness) = load_storage(kind).await else { + return Ok(()); + }; Review Comment: what if `load_storage` failed? would it just skip the tests and report green? ########## crates/storage/common/tests/credential_suite.rs: ########## @@ -0,0 +1,125 @@ +// 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. + +//! Custom AWS credential loader and FileIO builder property tests. + +mod common; + +use std::sync::Arc; + +use common::{StorageKind, load_storage}; +use iceberg::io::{FileIOBuilder, S3_ENDPOINT, S3_PATH_STYLE_ACCESS, S3_REGION}; +use iceberg_storage_opendal::{ + AwsCredential, CustomAwsCredentialLoader, OpenDalStorageFactory, ProvideCredential, +}; +use iceberg_test_utils::get_object_store_endpoint; +use reqsign_core::Context; +use rstest::rstest; + +/// Mock credential loader for testing custom AWS credential injection. +#[derive(Debug)] +struct MockCredentialLoader { + credential: Option<AwsCredential>, +} + +impl MockCredentialLoader { + fn new(credential: Option<AwsCredential>) -> Self { + Self { credential } + } + + fn new_object_store() -> Self { + Self::new(Some(AwsCredential { + access_key_id: "admin".to_string(), + secret_access_key: "password".to_string(), + session_token: None, + expires_in: None, + })) + } +} + +impl ProvideCredential for MockCredentialLoader { + type Credential = AwsCredential; + + async fn provide_credential( + &self, + _ctx: &Context, + ) -> reqsign_core::Result<Option<AwsCredential>> { + Ok(self.credential.clone()) + } +} + +#[rstest] +#[case::opendal_s3(StorageKind::OpenDalS3)] +#[tokio::test] +async fn test_s3_with_custom_credential_loader_success( + #[case] kind: StorageKind, +) -> iceberg::Result<()> { + let Some(_harness) = load_storage(kind).await else { + return Ok(()); + }; + + let mock_loader = MockCredentialLoader::new_object_store(); + let custom_loader = CustomAwsCredentialLoader::new(mock_loader); + let object_store_endpoint = get_object_store_endpoint(); + + let file_io_with_custom_creds = FileIOBuilder::new(Arc::new(OpenDalStorageFactory::S3 { + customized_credential_load: Some(custom_loader), + })) + .with_props(vec![ + (S3_ENDPOINT, object_store_endpoint), + (S3_REGION, "us-east-1".to_string()), + (S3_PATH_STYLE_ACCESS, "true".to_string()), + ]) + .build(); + + match file_io_with_custom_creds.exists("s3://bucket1/any").await { + Ok(_) => {} + Err(e) => panic!("Failed to check existence of bucket: {e}"), + } + + Ok(()) +} + +#[rstest] +#[case::opendal_s3(StorageKind::OpenDalS3)] +#[tokio::test] +async fn test_s3_with_custom_credential_loader_failure( + #[case] kind: StorageKind, +) -> iceberg::Result<()> { + let Some(_harness) = load_storage(kind).await else { + return Ok(()); + }; + + let mock_loader = MockCredentialLoader::new(None); + let custom_loader = CustomAwsCredentialLoader::new(mock_loader); + let object_store_endpoint = get_object_store_endpoint(); + + let file_io_with_custom_creds = FileIOBuilder::new(Arc::new(OpenDalStorageFactory::S3 { + customized_credential_load: Some(custom_loader), + })) + .with_props(vec![ + (S3_ENDPOINT, object_store_endpoint), + (S3_REGION, "us-east-1".to_string()), + (S3_PATH_STYLE_ACCESS, "true".to_string()), + ]) + .build(); + + let result = file_io_with_custom_creds.exists("s3://bucket1/any").await; + assert!(result.is_err()); Review Comment: I think we should validate the error message here ########## crates/storage/common/tests/common/mod.rs: ########## @@ -0,0 +1,193 @@ +// 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. + +//! Shared test harness and helpers for storage integration suites. + +#![allow(dead_code)] + +use std::collections::HashMap; +use std::sync::Arc; + +use iceberg::io::{ + FileIOBuilder, GCS_NO_AUTH, GCS_SERVICE_HOST, S3_ACCESS_KEY_ID, S3_ENDPOINT, + S3_PATH_STYLE_ACCESS, S3_REGION, S3_SECRET_ACCESS_KEY, +}; +use iceberg_storage_opendal::{OpenDalResolvingStorageFactory, OpenDalStorageFactory}; +#[allow(unused_imports)] +pub use iceberg_test_utils::storage::{ + StorageHarness, handle_unreachable_endpoint, is_endpoint_reachable, roundtrip_file_io, + unique_path, wait_until_ready, +}; +use iceberg_test_utils::{get_gcs_endpoint, get_object_store_endpoint, set_up}; +use tempfile::TempDir; + +static FAKE_GCS_BUCKET: &str = "test-bucket"; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum StorageKind { + OpenDalS3, + OpenDalGcs, + OpenDalFs, + OpenDalMemory, + OpenDalResolving, + // TODO: Wire ObjectStoreStorage::S3 once PR #3165 is merged (https://github.com/apache/iceberg-rust/pull/3165) +} + +impl StorageKind { + pub const fn as_str(&self) -> &'static str { + match self { + Self::OpenDalS3 => "opendal_s3", + Self::OpenDalGcs => "opendal_gcs", + Self::OpenDalFs => "opendal_fs", + Self::OpenDalMemory => "opendal_memory", + Self::OpenDalResolving => "opendal_resolving", + } + } +} + +impl std::fmt::Display for StorageKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.as_str()) + } +} + +pub async fn load_storage(kind: StorageKind) -> Option<StorageHarness> { + set_up(); + match kind { + StorageKind::OpenDalS3 => load_opendal_s3().await, + StorageKind::OpenDalGcs => load_opendal_gcs().await, + StorageKind::OpenDalFs => load_opendal_fs().await, + StorageKind::OpenDalMemory => load_opendal_memory().await, + StorageKind::OpenDalResolving => load_opendal_resolving().await, + } +} + +async fn load_opendal_s3() -> Option<StorageHarness> { Review Comment: We should have a new module `backends` and move these helpers to `backends/opendal.rs` -- 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]
