Abstract out random choosing

This commit is contained in:
Matthew Esposito 2023-06-08 16:27:36 -04:00
parent c00beaa5d8
commit f7f1aa4bde
No known key found for this signature in database
1 changed files with 9 additions and 3 deletions

View File

@ -157,7 +157,7 @@ impl Device {
let uuid = uuid::Uuid::new_v4().to_string();
// Select random user agent from ANDROID_USER_AGENT
let android_user_agent = ANDROID_USER_AGENT[fastrand::usize(..ANDROID_USER_AGENT.len())].to_string();
let android_user_agent = choose(&ANDROID_USER_AGENT).to_string();
// Android device headers
let headers = HashMap::from([
@ -178,10 +178,10 @@ impl Device {
let uuid = uuid::Uuid::new_v4().to_string();
// Select random user agent from IOS_USER_AGENT
let ios_user_agent = IOS_USER_AGENT[fastrand::usize(..IOS_USER_AGENT.len())].to_string();
let ios_user_agent = choose(&IOS_USER_AGENT).to_string();
// Select random iOS device from IOS_DEVICES
let ios_device = IOS_DEVICES[fastrand::usize(..IOS_DEVICES.len())].to_string();
let ios_device = choose(&IOS_DEVICES).to_string();
// iOS device headers
let headers = HashMap::from([
@ -209,6 +209,12 @@ impl Device {
}
}
// Waiting on fastrand 2.0.0 for the `choose` function
// https://github.com/smol-rs/fastrand/pull/59/
fn choose<T: Copy>(list: &[T]) -> T {
list[fastrand::usize(..list.len())]
}
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_oauth_client() {
assert!(!OAUTH_CLIENT.read().await.token.is_empty());