You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/08/02 14:58:18 UTC
[arrow-rs] branch master updated: Use Config System for Object Store Integration Tests (#4628)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 8a9dd842fc Use Config System for Object Store Integration Tests (#4628)
8a9dd842fc is described below
commit 8a9dd842fccafb29fadd07fa1c2bf988a6049a52
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Wed Aug 2 15:58:12 2023 +0100
Use Config System for Object Store Integration Tests (#4628)
---
.github/workflows/object_store.yml | 21 ++---
object_store/Cargo.toml | 1 -
object_store/src/aws/mod.rs | 171 ++++---------------------------------
object_store/src/azure/mod.rs | 101 ++--------------------
object_store/src/gcp/mod.rs | 78 ++++-------------
object_store/src/http/mod.rs | 7 +-
object_store/src/lib.rs | 10 +++
7 files changed, 57 insertions(+), 332 deletions(-)
diff --git a/.github/workflows/object_store.yml b/.github/workflows/object_store.yml
index 5ae9d2d9c8..7858da1e2d 100644
--- a/.github/workflows/object_store.yml
+++ b/.github/workflows/object_store.yml
@@ -82,12 +82,19 @@ jobs:
# Run integration tests
TEST_INTEGRATION: 1
EC2_METADATA_ENDPOINT: http://localhost:1338
- AZURE_USE_EMULATOR: "1"
+ AZURE_CONTAINER_NAME: test-bucket
+ AZURE_STORAGE_USE_EMULATOR: "1"
AZURITE_BLOB_STORAGE_URL: "http://localhost:10000"
AZURITE_QUEUE_STORAGE_URL: "http://localhost:10001"
+ AWS_BUCKET: test-bucket
+ AWS_DEFAULT_REGION: "us-east-1"
+ AWS_ACCESS_KEY_ID: test
+ AWS_SECRET_ACCESS_KEY: test
+ AWS_ENDPOINT: http://localhost:4566
+ AWS_ALLOW_HTTP: true
HTTP_URL: "http://localhost:8080"
+ GOOGLE_BUCKET: test-bucket
GOOGLE_SERVICE_ACCOUNT: "/tmp/gcs.json"
- OBJECT_STORE_BUCKET: test-bucket
steps:
- uses: actions/checkout@v3
@@ -105,11 +112,6 @@ jobs:
run: docker run -d -p 8080:80 rclone/rclone serve webdav /data --addr :80
- name: Setup LocalStack (AWS emulation)
- env:
- AWS_DEFAULT_REGION: "us-east-1"
- AWS_ACCESS_KEY_ID: test
- AWS_SECRET_ACCESS_KEY: test
- AWS_ENDPOINT: http://localhost:4566
run: |
docker run -d -p 4566:4566 localstack/localstack:2.0
docker run -d -p 1338:1338 amazon/amazon-ec2-metadata-mock:v1.9.2 --imdsv2
@@ -128,11 +130,6 @@ jobs:
rustup default stable
- name: Run object_store tests
- env:
- OBJECT_STORE_AWS_DEFAULT_REGION: "us-east-1"
- OBJECT_STORE_AWS_ACCESS_KEY_ID: test
- OBJECT_STORE_AWS_SECRET_ACCESS_KEY: test
- OBJECT_STORE_AWS_ENDPOINT: http://localhost:4566
run: cargo test --features=aws,azure,gcp,http
# test the object_store crate builds against wasm32 in stable rust
diff --git a/object_store/Cargo.toml b/object_store/Cargo.toml
index 255b972e32..eca5a5ce84 100644
--- a/object_store/Cargo.toml
+++ b/object_store/Cargo.toml
@@ -71,7 +71,6 @@ aws = ["cloud"]
http = ["cloud"]
[dev-dependencies] # In alphabetical order
-dotenv = "0.15.0"
tempfile = "3.1.0"
futures-test = "0.3"
rand = "0.8"
diff --git a/object_store/src/aws/mod.rs b/object_store/src/aws/mod.rs
index 5a29bd0fc6..f6066d45a7 100644
--- a/object_store/src/aws/mod.rs
+++ b/object_store/src/aws/mod.rs
@@ -1067,153 +1067,9 @@ mod tests {
};
use bytes::Bytes;
use std::collections::HashMap;
- use std::env;
const NON_EXISTENT_NAME: &str = "nonexistentname";
- // Helper macro to skip tests if TEST_INTEGRATION and the AWS
- // environment variables are not set. Returns a configured
- // AmazonS3Builder
- macro_rules! maybe_skip_integration {
- () => {{
- dotenv::dotenv().ok();
-
- let required_vars = [
- "OBJECT_STORE_AWS_DEFAULT_REGION",
- "OBJECT_STORE_BUCKET",
- "OBJECT_STORE_AWS_ACCESS_KEY_ID",
- "OBJECT_STORE_AWS_SECRET_ACCESS_KEY",
- ];
- let unset_vars: Vec<_> = required_vars
- .iter()
- .filter_map(|&name| match env::var(name) {
- Ok(_) => None,
- Err(_) => Some(name),
- })
- .collect();
- let unset_var_names = unset_vars.join(", ");
-
- let force = env::var("TEST_INTEGRATION");
-
- if force.is_ok() && !unset_var_names.is_empty() {
- panic!(
- "TEST_INTEGRATION is set, \
- but variable(s) {} need to be set",
- unset_var_names
- );
- } else if force.is_err() {
- eprintln!(
- "skipping AWS integration test - set {}TEST_INTEGRATION to run",
- if unset_var_names.is_empty() {
- String::new()
- } else {
- format!("{} and ", unset_var_names)
- }
- );
- return;
- } else {
- let config = AmazonS3Builder::new()
- .with_access_key_id(
- env::var("OBJECT_STORE_AWS_ACCESS_KEY_ID")
- .expect("already checked OBJECT_STORE_AWS_ACCESS_KEY_ID"),
- )
- .with_secret_access_key(
- env::var("OBJECT_STORE_AWS_SECRET_ACCESS_KEY")
- .expect("already checked OBJECT_STORE_AWS_SECRET_ACCESS_KEY"),
- )
- .with_region(
- env::var("OBJECT_STORE_AWS_DEFAULT_REGION")
- .expect("already checked OBJECT_STORE_AWS_DEFAULT_REGION"),
- )
- .with_bucket_name(
- env::var("OBJECT_STORE_BUCKET")
- .expect("already checked OBJECT_STORE_BUCKET"),
- )
- .with_allow_http(true);
-
- let config = if let Ok(endpoint) = env::var("OBJECT_STORE_AWS_ENDPOINT") {
- config.with_endpoint(endpoint)
- } else {
- config
- };
-
- let config = if let Ok(token) = env::var("OBJECT_STORE_AWS_SESSION_TOKEN")
- {
- config.with_token(token)
- } else {
- config
- };
-
- let config = if let Ok(virtual_hosted_style_request) =
- env::var("OBJECT_STORE_VIRTUAL_HOSTED_STYLE_REQUEST")
- {
- config.with_virtual_hosted_style_request(
- virtual_hosted_style_request.trim().parse().unwrap(),
- )
- } else {
- config
- };
-
- config
- }
- }};
- }
-
- #[test]
- fn s3_test_config_from_env() {
- let aws_access_key_id = env::var("AWS_ACCESS_KEY_ID")
- .unwrap_or_else(|_| "object_store:fake_access_key_id".into());
- let aws_secret_access_key = env::var("AWS_SECRET_ACCESS_KEY")
- .unwrap_or_else(|_| "object_store:fake_secret_key".into());
-
- let aws_default_region = env::var("AWS_DEFAULT_REGION")
- .unwrap_or_else(|_| "object_store:fake_default_region".into());
-
- let aws_endpoint = env::var("AWS_ENDPOINT")
- .unwrap_or_else(|_| "object_store:fake_endpoint".into());
- let aws_session_token = env::var("AWS_SESSION_TOKEN")
- .unwrap_or_else(|_| "object_store:fake_session_token".into());
-
- let container_creds_relative_uri =
- env::var("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI")
- .unwrap_or_else(|_| "/object_store/fake_credentials_uri".into());
-
- // required
- env::set_var("AWS_ACCESS_KEY_ID", &aws_access_key_id);
- env::set_var("AWS_SECRET_ACCESS_KEY", &aws_secret_access_key);
- env::set_var("AWS_DEFAULT_REGION", &aws_default_region);
-
- // optional
- env::set_var("AWS_ENDPOINT", &aws_endpoint);
- env::set_var("AWS_SESSION_TOKEN", &aws_session_token);
- env::set_var(
- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
- &container_creds_relative_uri,
- );
- env::set_var("AWS_UNSIGNED_PAYLOAD", "true");
- env::set_var("AWS_CHECKSUM_ALGORITHM", "sha256");
-
- let builder = AmazonS3Builder::from_env();
- assert_eq!(builder.access_key_id.unwrap(), aws_access_key_id.as_str());
- assert_eq!(
- builder.secret_access_key.unwrap(),
- aws_secret_access_key.as_str()
- );
- assert_eq!(builder.region.unwrap(), aws_default_region);
-
- assert_eq!(builder.endpoint.unwrap(), aws_endpoint);
- assert_eq!(builder.token.unwrap(), aws_session_token);
- assert_eq!(
- builder.container_credentials_relative_uri.unwrap(),
- container_creds_relative_uri
- );
- assert_eq!(
- builder.checksum_algorithm.unwrap().get().unwrap(),
- Checksum::SHA256
- );
- assert!(builder.unsigned_payload.get().unwrap());
- }
-
#[test]
fn s3_test_config_from_map() {
let aws_access_key_id = "object_store:fake_access_key_id".to_string();
@@ -1304,7 +1160,9 @@ mod tests {
#[tokio::test]
async fn s3_test() {
- let config = maybe_skip_integration!();
+ crate::test_util::maybe_skip_integration!();
+ let config = AmazonS3Builder::from_env();
+
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
let integration = config.build().unwrap();
@@ -1317,13 +1175,14 @@ mod tests {
stream_get(&integration).await;
// run integration test with unsigned payload enabled
- let config = maybe_skip_integration!().with_unsigned_payload(true);
+ let config = AmazonS3Builder::from_env().with_unsigned_payload(true);
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
let integration = config.build().unwrap();
put_get_delete_list_opts(&integration, is_local).await;
// run integration test with checksum set to sha256
- let config = maybe_skip_integration!().with_checksum_algorithm(Checksum::SHA256);
+ let config =
+ AmazonS3Builder::from_env().with_checksum_algorithm(Checksum::SHA256);
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
let integration = config.build().unwrap();
put_get_delete_list_opts(&integration, is_local).await;
@@ -1331,8 +1190,8 @@ mod tests {
#[tokio::test]
async fn s3_test_get_nonexistent_location() {
- let config = maybe_skip_integration!();
- let integration = config.build().unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let integration = AmazonS3Builder::from_env().build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1344,7 +1203,8 @@ mod tests {
#[tokio::test]
async fn s3_test_get_nonexistent_bucket() {
- let config = maybe_skip_integration!().with_bucket_name(NON_EXISTENT_NAME);
+ crate::test_util::maybe_skip_integration!();
+ let config = AmazonS3Builder::from_env().with_bucket_name(NON_EXISTENT_NAME);
let integration = config.build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1355,8 +1215,8 @@ mod tests {
#[tokio::test]
async fn s3_test_put_nonexistent_bucket() {
- let config = maybe_skip_integration!().with_bucket_name(NON_EXISTENT_NAME);
-
+ crate::test_util::maybe_skip_integration!();
+ let config = AmazonS3Builder::from_env().with_bucket_name(NON_EXISTENT_NAME);
let integration = config.build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1368,8 +1228,8 @@ mod tests {
#[tokio::test]
async fn s3_test_delete_nonexistent_location() {
- let config = maybe_skip_integration!();
- let integration = config.build().unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let integration = AmazonS3Builder::from_env().build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1378,7 +1238,8 @@ mod tests {
#[tokio::test]
async fn s3_test_delete_nonexistent_bucket() {
- let config = maybe_skip_integration!().with_bucket_name(NON_EXISTENT_NAME);
+ crate::test_util::maybe_skip_integration!();
+ let config = AmazonS3Builder::from_env().with_bucket_name(NON_EXISTENT_NAME);
let integration = config.build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
diff --git a/object_store/src/azure/mod.rs b/object_store/src/azure/mod.rs
index 8619319a5b..019cde5813 100644
--- a/object_store/src/azure/mod.rs
+++ b/object_store/src/azure/mod.rs
@@ -1021,107 +1021,18 @@ mod tests {
use super::*;
use crate::tests::{
copy_if_not_exists, get_opts, list_uses_directories_correctly,
- list_with_delimiter, put_get_delete_list, put_get_delete_list_opts,
- rename_and_copy, stream_get,
+ list_with_delimiter, put_get_delete_list_opts, rename_and_copy, stream_get,
};
use std::collections::HashMap;
- use std::env;
-
- // Helper macro to skip tests if TEST_INTEGRATION and the Azure environment
- // variables are not set.
- macro_rules! maybe_skip_integration {
- () => {{
- dotenv::dotenv().ok();
-
- let use_emulator = std::env::var("AZURE_USE_EMULATOR").is_ok();
-
- let mut required_vars = vec!["OBJECT_STORE_BUCKET"];
- if !use_emulator {
- required_vars.push("AZURE_STORAGE_ACCOUNT");
- required_vars.push("AZURE_STORAGE_ACCESS_KEY");
- }
- let unset_vars: Vec<_> = required_vars
- .iter()
- .filter_map(|&name| match env::var(name) {
- Ok(_) => None,
- Err(_) => Some(name),
- })
- .collect();
- let unset_var_names = unset_vars.join(", ");
-
- let force = std::env::var("TEST_INTEGRATION");
-
- if force.is_ok() && !unset_var_names.is_empty() {
- panic!(
- "TEST_INTEGRATION is set, \
- but variable(s) {} need to be set",
- unset_var_names
- )
- } else if force.is_err() {
- eprintln!(
- "skipping Azure integration test - set {}TEST_INTEGRATION to run",
- if unset_var_names.is_empty() {
- String::new()
- } else {
- format!("{} and ", unset_var_names)
- }
- );
- return;
- } else {
- let builder = MicrosoftAzureBuilder::new()
- .with_container_name(
- env::var("OBJECT_STORE_BUCKET")
- .expect("already checked OBJECT_STORE_BUCKET"),
- )
- .with_use_emulator(use_emulator);
- if !use_emulator {
- builder
- .with_account(
- env::var("AZURE_STORAGE_ACCOUNT").unwrap_or_default(),
- )
- .with_access_key(
- env::var("AZURE_STORAGE_ACCESS_KEY").unwrap_or_default(),
- )
- } else {
- builder
- }
- }
- }};
- }
#[tokio::test]
async fn azure_blob_test() {
- let integration = maybe_skip_integration!().build().unwrap();
- put_get_delete_list_opts(&integration, false).await;
- get_opts(&integration).await;
- list_uses_directories_correctly(&integration).await;
- list_with_delimiter(&integration).await;
- rename_and_copy(&integration).await;
- copy_if_not_exists(&integration).await;
- stream_get(&integration).await;
- }
+ crate::test_util::maybe_skip_integration!();
+ let container_name = std::env::var("AZURE_CONTAINER_NAME").unwrap(); // (#4629)
+ let config = MicrosoftAzureBuilder::from_env();
+ let integration = config.with_container_name(container_name).build().unwrap();
- // test for running integration test against actual blob service with service principal
- // credentials. To run make sure all environment variables are set and remove the ignore
- #[tokio::test]
- #[ignore]
- async fn azure_blob_test_sp() {
- dotenv::dotenv().ok();
- let builder = MicrosoftAzureBuilder::new()
- .with_account(
- env::var("AZURE_STORAGE_ACCOUNT")
- .expect("must be set AZURE_STORAGE_ACCOUNT"),
- )
- .with_container_name(
- env::var("OBJECT_STORE_BUCKET").expect("must be set OBJECT_STORE_BUCKET"),
- )
- .with_access_key(
- env::var("AZURE_STORAGE_ACCESS_KEY")
- .expect("must be set AZURE_STORAGE_CLIENT_ID"),
- );
- let integration = builder.build().unwrap();
-
- put_get_delete_list(&integration).await;
+ put_get_delete_list_opts(&integration, false).await;
get_opts(&integration).await;
list_uses_directories_correctly(&integration).await;
list_with_delimiter(&integration).await;
diff --git a/object_store/src/gcp/mod.rs b/object_store/src/gcp/mod.rs
index d98e6b068d..58a5d19f3c 100644
--- a/object_store/src/gcp/mod.rs
+++ b/object_store/src/gcp/mod.rs
@@ -1090,7 +1090,6 @@ impl GoogleCloudStorageBuilder {
mod test {
use bytes::Bytes;
use std::collections::HashMap;
- use std::env;
use std::io::Write;
use tempfile::NamedTempFile;
@@ -1101,56 +1100,10 @@ mod test {
const FAKE_KEY: &str = r#"{"private_key": "private_key", "client_email":"client_email", "disable_oauth":true}"#;
const NON_EXISTENT_NAME: &str = "nonexistentname";
- // Helper macro to skip tests if TEST_INTEGRATION and the GCP environment variables are not set.
- macro_rules! maybe_skip_integration {
- () => {{
- dotenv::dotenv().ok();
-
- let required_vars = ["OBJECT_STORE_BUCKET", "GOOGLE_SERVICE_ACCOUNT"];
- let unset_vars: Vec<_> = required_vars
- .iter()
- .filter_map(|&name| match env::var(name) {
- Ok(_) => None,
- Err(_) => Some(name),
- })
- .collect();
- let unset_var_names = unset_vars.join(", ");
-
- let force = std::env::var("TEST_INTEGRATION");
-
- if force.is_ok() && !unset_var_names.is_empty() {
- panic!(
- "TEST_INTEGRATION is set, \
- but variable(s) {} need to be set",
- unset_var_names
- )
- } else if force.is_err() {
- eprintln!(
- "skipping Google Cloud integration test - set {}TEST_INTEGRATION to run",
- if unset_var_names.is_empty() {
- String::new()
- } else {
- format!("{} and ", unset_var_names)
- }
- );
- return;
- } else {
- GoogleCloudStorageBuilder::new()
- .with_bucket_name(
- env::var("OBJECT_STORE_BUCKET")
- .expect("already checked OBJECT_STORE_BUCKET")
- )
- .with_service_account_path(
- env::var("GOOGLE_SERVICE_ACCOUNT")
- .expect("already checked GOOGLE_SERVICE_ACCOUNT")
- )
- }
- }};
- }
-
#[tokio::test]
async fn gcs_test() {
- let integration = maybe_skip_integration!().build().unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let integration = GoogleCloudStorageBuilder::from_env().build().unwrap();
put_get_delete_list(&integration).await;
list_uses_directories_correctly(&integration).await;
@@ -1170,7 +1123,8 @@ mod test {
#[tokio::test]
async fn gcs_test_get_nonexistent_location() {
- let integration = maybe_skip_integration!().build().unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let integration = GoogleCloudStorageBuilder::from_env().build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1184,10 +1138,9 @@ mod test {
#[tokio::test]
async fn gcs_test_get_nonexistent_bucket() {
- let integration = maybe_skip_integration!()
- .with_bucket_name(NON_EXISTENT_NAME)
- .build()
- .unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let config = GoogleCloudStorageBuilder::from_env();
+ let integration = config.with_bucket_name(NON_EXISTENT_NAME).build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1203,7 +1156,8 @@ mod test {
#[tokio::test]
async fn gcs_test_delete_nonexistent_location() {
- let integration = maybe_skip_integration!().build().unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let integration = GoogleCloudStorageBuilder::from_env().build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1216,10 +1170,9 @@ mod test {
#[tokio::test]
async fn gcs_test_delete_nonexistent_bucket() {
- let integration = maybe_skip_integration!()
- .with_bucket_name(NON_EXISTENT_NAME)
- .build()
- .unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let config = GoogleCloudStorageBuilder::from_env();
+ let integration = config.with_bucket_name(NON_EXISTENT_NAME).build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
@@ -1232,10 +1185,9 @@ mod test {
#[tokio::test]
async fn gcs_test_put_nonexistent_bucket() {
- let integration = maybe_skip_integration!()
- .with_bucket_name(NON_EXISTENT_NAME)
- .build()
- .unwrap();
+ crate::test_util::maybe_skip_integration!();
+ let config = GoogleCloudStorageBuilder::from_env();
+ let integration = config.with_bucket_name(NON_EXISTENT_NAME).build().unwrap();
let location = Path::from_iter([NON_EXISTENT_NAME]);
let data = Bytes::from("arbitrary data");
diff --git a/object_store/src/http/mod.rs b/object_store/src/http/mod.rs
index bc01c174f3..6927f1b883 100644
--- a/object_store/src/http/mod.rs
+++ b/object_store/src/http/mod.rs
@@ -262,12 +262,7 @@ mod tests {
#[tokio::test]
async fn http_test() {
- dotenv::dotenv().ok();
- let force = std::env::var("TEST_INTEGRATION");
- if force.is_err() {
- eprintln!("skipping HTTP integration test - set TEST_INTEGRATION to run");
- return;
- }
+ crate::test_util::maybe_skip_integration!();
let url = std::env::var("HTTP_URL").expect("HTTP_URL must be set");
let options = ClientOptions::new().with_allow_http(true);
let integration = HttpBuilder::new()
diff --git a/object_store/src/lib.rs b/object_store/src/lib.rs
index 082dca2935..6c70326d2b 100644
--- a/object_store/src/lib.rs
+++ b/object_store/src/lib.rs
@@ -910,6 +910,16 @@ mod test_util {
use super::*;
use futures::TryStreamExt;
+ macro_rules! maybe_skip_integration {
+ () => {
+ if std::env::var("TEST_INTEGRATION").is_err() {
+ eprintln!("Skipping integration test - set TEST_INTEGRATION");
+ return;
+ }
+ };
+ }
+ pub(crate) use maybe_skip_integration;
+
pub async fn flatten_list_stream(
storage: &DynObjectStore,
prefix: Option<&Path>,