()
| 594 | |
| 595 | #[tokio::test] |
| 596 | async fn s3_object_store_builder_default() -> Result<()> { |
| 597 | if let Err(DataFusionError::Execution(e)) = check_aws_envs().await { |
| 598 | // Skip test if AWS envs are not set |
| 599 | eprintln!("{e}"); |
| 600 | return Ok(()); |
| 601 | } |
| 602 | |
| 603 | let location = "s3://bucket/path/FAKE/file.parquet"; |
| 604 | // Set it to a non-existent file to avoid reading the default configuration file |
| 605 | unsafe { |
| 606 | std::env::set_var("AWS_CONFIG_FILE", "data/aws.config"); |
| 607 | std::env::set_var("AWS_SHARED_CREDENTIALS_FILE", "data/aws.credentials"); |
| 608 | } |
| 609 | |
| 610 | // No options |
| 611 | let table_url = ListingTableUrl::parse(location)?; |
| 612 | let scheme = table_url.scheme(); |
| 613 | let sql = |
| 614 | format!("CREATE EXTERNAL TABLE test STORED AS PARQUET LOCATION '{location}'"); |
| 615 | |
| 616 | let ctx = SessionContext::new(); |
| 617 | ctx.register_table_options_extension_from_scheme(scheme); |
| 618 | let table_options = get_table_options(&ctx, &sql).await; |
| 619 | let aws_options = table_options.extensions.get::<AwsOptions>().unwrap(); |
| 620 | let builder = |
| 621 | get_s3_object_store_builder(table_url.as_ref(), aws_options, false).await?; |
| 622 | |
| 623 | // If the environment variables are set (as they are in CI) use them |
| 624 | let expected_access_key_id = std::env::var("AWS_ACCESS_KEY_ID").ok(); |
| 625 | let expected_secret_access_key = std::env::var("AWS_SECRET_ACCESS_KEY").ok(); |
| 626 | let expected_region = Some( |
| 627 | std::env::var("AWS_REGION").unwrap_or_else(|_| "eu-central-1".to_string()), |
| 628 | ); |
| 629 | let expected_endpoint = std::env::var("AWS_ENDPOINT").ok(); |
| 630 | |
| 631 | // get the actual configuration information, then assert_eq! |
| 632 | assert_eq!( |
| 633 | builder.get_config_value(&AmazonS3ConfigKey::AccessKeyId), |
| 634 | expected_access_key_id |
| 635 | ); |
| 636 | assert_eq!( |
| 637 | builder.get_config_value(&AmazonS3ConfigKey::SecretAccessKey), |
| 638 | expected_secret_access_key |
| 639 | ); |
| 640 | // Default is to skip signature when no credentials are provided |
| 641 | let expected_skip_signature = |
| 642 | if expected_access_key_id.is_none() && expected_secret_access_key.is_none() { |
| 643 | Some(String::from("true")) |
| 644 | } else { |
| 645 | Some(String::from("false")) |
| 646 | }; |
| 647 | assert_eq!( |
| 648 | builder.get_config_value(&AmazonS3ConfigKey::Region), |
| 649 | expected_region |
| 650 | ); |
| 651 | assert_eq!( |
| 652 | builder.get_config_value(&AmazonS3ConfigKey::Endpoint), |
| 653 | expected_endpoint |
nothing calls this directly
no test coverage detected
searching dependent graphs…