Skip to content

Commit

Permalink
Move coverage tool tweaking.
Browse files Browse the repository at this point in the history
  • Loading branch information
dacut committed Sep 18, 2022
1 parent 0a3e127 commit 32637ac
Show file tree
Hide file tree
Showing 5 changed files with 1,131 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Cargo.lock
*.profdata
*.profraw
coverage-html
lcov.info
15 changes: 14 additions & 1 deletion arn/src/arn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
/// ARNs used to match resource statements, see [ArnPattern].
///
/// [Arn] objects are immutable.
#[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct Arn {
partition: String,
service: String,
Expand All @@ -29,6 +29,17 @@ pub struct Arn {
resource: String,
}

#[allow(clippy::derive_hash_xor_eq)]
impl Hash for Arn {
fn hash<H: Hasher>(&self, state: &mut H) {
self.partition.hash(state);
self.service.hash(state);
self.region.hash(state);
self.account_id.hash(state);
self.resource.hash(state);
}
}

impl Arn {
/// Create a new ARN from the specified components.
///
Expand Down Expand Up @@ -651,6 +662,8 @@ mod test {
assert_ne!(pat1a, pat2);
assert_eq!(pat1c, pat1b);

assert!(pat1a.service().eq(&ArnSegmentPattern::Exact("ec2".to_string())));

// Ensure we can derive a hash for the arn.
let mut h2 = DefaultHasher::new();
pat3.hash(&mut h2);
Expand Down
23 changes: 21 additions & 2 deletions arn/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,28 @@ mod tests {

#[test]
fn check_derived() {
let errors = vec![
ArnError::InvalidAccountId("1234".to_string()),
ArnError::InvalidArn("arn:aws:iam::1234:role/role-name".to_string()),
ArnError::InvalidPartition("aws".to_string()),
ArnError::InvalidRegion("us-east-1".to_string()),
ArnError::InvalidResource("role/role-name".to_string()),
ArnError::InvalidScheme("arn".to_string()),
ArnError::InvalidService("iam".to_string()),
];

for i in 0..errors.len() {
for j in 0..errors.len() {
if i == j {
assert_eq!(errors[i], errors[j]);
} else {
assert_ne!(errors[i], errors[j]);
}
}
}

// Ensure we can debug print the error.
let err = ArnError::InvalidAccountId("1234".to_string());
let _ = format!("{:?}", err);
let _ = format!("{:?}", errors[0]);
}

#[test]
Expand Down
Loading

0 comments on commit 32637ac

Please sign in to comment.