Skip to content

Commit

Permalink
Calculate hash of result first
Browse files Browse the repository at this point in the history
  • Loading branch information
LostQuasar committed Jun 12, 2024
1 parent 78e95c0 commit 8ba1b20
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub enum ShockerSource {

#[cfg(test)]
mod tests {
use std::hash::{DefaultHasher, Hash, Hasher};

use super::*;
use dotenv::dotenv;
use reqwest::header;
Expand Down Expand Up @@ -98,14 +100,20 @@ mod tests {
(client, api_url.to_string())
}

fn calculate_hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
t.hash(&mut s);
s.finish()
}

#[tokio::test]
async fn get_shockers_test() {
dotenv().ok();
let shocker_test_id = dotenv::var("SHOCKER_TEST_ID").expect("missing SHOCKER_TEST_ID");

let (client, api_url) = setup();
let result = get_shockers(&client, api_url.as_str(), ShockerSource::Own);
assert_eq!(result.await.unwrap()[0].shockers[0].id, shocker_test_id);
assert_eq!(calculate_hash(&result.await.unwrap()[0].shockers[0].id), calculate_hash(&shocker_test_id));
}

#[tokio::test]
Expand All @@ -120,7 +128,7 @@ mod tests {
shocker_test_id,
ControlType::Sound,
);
assert_eq!(result.await.unwrap(), "Successfully sent control messages");
assert_eq!(calculate_hash(&result.await.unwrap()), calculate_hash(&"Successfully sent control messages"));
}

#[tokio::test]
Expand All @@ -130,6 +138,6 @@ mod tests {

let (client, api_url) = setup();
let result = get_user_info(&client, api_url.as_str());
assert_eq!(result.await.unwrap().id, user_test_id);
assert_eq!(calculate_hash(&result.await.unwrap().id), calculate_hash(&user_test_id));
}
}

0 comments on commit 8ba1b20

Please sign in to comment.