Skip to content

Commit

Permalink
Fix test to use get_credentials method
Browse files Browse the repository at this point in the history
  • Loading branch information
lizardoluis committed Nov 21, 2024
1 parent af4821f commit a0fb6bc
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions object_store_factory/src/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ mod tests {
}

#[test]
fn test_to_hashmap() {
fn test_get_options_and_credentials() {
let s3_config = S3Config {
region: Some("us-west-1".to_string()),
access_key_id: Some("ACCESS_KEY".to_string()),
Expand All @@ -566,40 +566,42 @@ mod tests {
skip_signature: true,
};

let hashmap = s3_config.get_options();

let options = s3_config.get_options();
assert_eq!(
hashmap.get(AmazonS3ConfigKey::Region.as_ref()),
options.get(AmazonS3ConfigKey::Region.as_ref()),
Some(&"us-west-1".to_string())
);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::AccessKeyId.as_ref()),
Some(&"ACCESS_KEY".to_string())
options.get(AmazonS3ConfigKey::Endpoint.as_ref()),
Some(&"https://s3.amazonaws.com".to_string())
);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::SecretAccessKey.as_ref()),
Some(&"SECRET_KEY".to_string())
options.get(AmazonS3ConfigKey::Client(ClientConfigKey::AllowHttp).as_ref()),
Some(&"true".to_string())
);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::Token.as_ref()),
Some(&"SESSION_TOKEN".to_string())
options.get(AmazonS3ConfigKey::SkipSignature.as_ref()),
Some(&"true".to_string())
);

let credentials = s3_config.get_credentials();

assert_eq!(
hashmap.get(AmazonS3ConfigKey::Endpoint.as_ref()),
Some(&"https://s3.amazonaws.com".to_string())
credentials.get(AmazonS3ConfigKey::AccessKeyId.as_ref()),
Some(&"ACCESS_KEY".to_string())
);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::Client(ClientConfigKey::AllowHttp).as_ref()),
Some(&"true".to_string())
credentials.get(AmazonS3ConfigKey::SecretAccessKey.as_ref()),
Some(&"SECRET_KEY".to_string())
);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::SkipSignature.as_ref()),
Some(&"true".to_string())
credentials.get(AmazonS3ConfigKey::Token.as_ref()),
Some(&"SESSION_TOKEN".to_string())
);
}

#[test]
fn test_to_hashmap_with_none_fields() {
fn test_get_options_and_credentials_with_none_fields() {
let s3_config = S3Config {
region: None,
access_key_id: None,
Expand All @@ -612,24 +614,28 @@ mod tests {
skip_signature: true,
};

let hashmap = s3_config.get_options();

assert_eq!(hashmap.get(AmazonS3ConfigKey::Region.as_ref()), None);
assert_eq!(hashmap.get(AmazonS3ConfigKey::AccessKeyId.as_ref()), None);
let options = s3_config.get_options();
assert_eq!(options.get(AmazonS3ConfigKey::Region.as_ref()), None);
assert_eq!(options.get(AmazonS3ConfigKey::Endpoint.as_ref()), None);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::SecretAccessKey.as_ref()),
None
options.get(AmazonS3ConfigKey::Client(ClientConfigKey::AllowHttp).as_ref()),
Some(&"true".to_string())
);
assert_eq!(hashmap.get(AmazonS3ConfigKey::Token.as_ref()), None);
assert_eq!(hashmap.get(AmazonS3ConfigKey::Endpoint.as_ref()), None);
assert_eq!(
hashmap.get(AmazonS3ConfigKey::Client(ClientConfigKey::AllowHttp).as_ref()),
options.get(AmazonS3ConfigKey::SkipSignature.as_ref()),
Some(&"true".to_string())
);

let credentials = s3_config.get_credentials();
assert_eq!(
hashmap.get(AmazonS3ConfigKey::SkipSignature.as_ref()),
Some(&"true".to_string())
credentials.get(AmazonS3ConfigKey::AccessKeyId.as_ref()),
None
);
assert_eq!(
credentials.get(AmazonS3ConfigKey::SecretAccessKey.as_ref()),
None
);
assert_eq!(credentials.get(AmazonS3ConfigKey::Token.as_ref()), None);
}

#[test]
Expand Down

0 comments on commit a0fb6bc

Please sign in to comment.