Skip to content

Commit

Permalink
add gen_test_uaid
Browse files Browse the repository at this point in the history
  • Loading branch information
pjenvey committed Feb 6, 2024
1 parent bf60706 commit fab3d46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
18 changes: 6 additions & 12 deletions autopush-common/src/db/bigtable/bigtable_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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();
}
}
1 change: 1 addition & 0 deletions autopush-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 11 additions & 0 deletions autopush-common/src/test_support.rs
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit fab3d46

Please sign in to comment.