diff --git a/autopush-common/src/db/bigtable/bigtable_client/mod.rs b/autopush-common/src/db/bigtable/bigtable_client/mod.rs index 23d6baf26..acd51ae27 100644 --- a/autopush-common/src/db/bigtable/bigtable_client/mod.rs +++ b/autopush-common/src/db/bigtable/bigtable_client/mod.rs @@ -1142,7 +1142,7 @@ mod tests { use uuid; use super::*; - use crate::{db::DbSettings, util::ms_since_epoch}; + use crate::{db::DbSettings, test_support::gen_test_uaid, util::ms_since_epoch}; const TEST_USER: &str = "DEADBEEF-0000-0000-0000-0123456789AB"; const TEST_CHID: &str = "DECAFBAD-0000-0000-0000-0123456789AB"; @@ -1407,15 +1407,7 @@ mod tests { #[actix_rt::test] async fn read_cells_family_id() -> DbResult<()> { - // let uaid = Uuid::parse_str(TEST_USER).unwrap(); - // generate a somewhat random test UAID to prevent possible false test fails - // if the account is deleted before this test completes. - let uaid = { - let temp = Uuid::new_v4().to_string(); - let mut parts: Vec<&str> = temp.split('-').collect(); - parts[0] = "DEADBEEF"; - Uuid::parse_str(&parts.join("-")).unwrap() - }; + let uaid = gen_test_uaid(); let client = new_client().unwrap(); client.remove_user(&uaid).await.unwrap(); @@ -1442,8 +1434,8 @@ mod tests { #[actix_rt::test] async fn add_user_existing() { + let uaid = gen_test_uaid(); let client = new_client().unwrap(); - let uaid = Uuid::new_v4(); let user = User { uaid, ..Default::default() @@ -1457,8 +1449,8 @@ mod tests { #[actix_rt::test] async fn version_check() { + let uaid = gen_test_uaid(); let client = new_client().unwrap(); - let uaid = Uuid::new_v4(); let user = User { uaid, ..Default::default() @@ -1473,5 +1465,7 @@ mod tests { assert_ne!(user.version, fetched.version); // should now fail w/ a stale version assert!(!client.update_user(&user).await.unwrap()); + + client.remove_user(&uaid).await.unwrap(); } } diff --git a/autopush-common/src/lib.rs b/autopush-common/src/lib.rs index b8dc4c844..a96df47b5 100644 --- a/autopush-common/src/lib.rs +++ b/autopush-common/src/lib.rs @@ -15,6 +15,7 @@ pub mod middleware; pub mod notification; pub mod sentry; pub mod tags; +pub mod test_support; #[macro_use] pub mod util; diff --git a/autopush-common/src/test_support.rs b/autopush-common/src/test_support.rs new file mode 100644 index 000000000..787efd708 --- /dev/null +++ b/autopush-common/src/test_support.rs @@ -0,0 +1,11 @@ +use uuid::Uuid; + +/// Generate a UAID that is prefixed with the test-identification ID "DEADBEEF". +/// Note: It's absolutely possible that this might cause a conflict with valid UAIDs, but +/// the risk is reasonably small, and we could limit pruning to whenever we had +/// accidentally run the test script against production. +pub fn gen_test_uaid() -> Uuid { + let temp = Uuid::new_v4(); + let (_, d2, d3, d4) = temp.as_fields(); + Uuid::from_fields(0xdeadbeef, d2, d3, d4) +}