Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(iroh-cli): Also test for "minutes" in transfer time regex 😬 #2475

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
[dev-dependencies]
duct = "0.13.6"
nix = { version = "0.27", features = ["signal", "process"] }
rand_xorshift = "0.3.0"
regex = "1.10.3"
testdir = "0.9.1"
walkdir = "2"
Expand Down
22 changes: 16 additions & 6 deletions iroh-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@ use iroh::{
blobs::{Hash, HashAndFormat},
util::path::IrohPaths,
};
use rand::distributions::{Alphanumeric, DistString};
use rand::SeedableRng;
use rand::{RngCore, SeedableRng};
use regex::Regex;
use testdir::testdir;
use walkdir::WalkDir;

fn make_rand_file(size: usize, path: &Path) -> Result<Hash> {
let mut rng = rand::rngs::StdRng::seed_from_u64(1);
let content = Alphanumeric.sample_string(&mut rng, size);
// 64 chars makes for easy random sampling
const CHARS_LUT: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789 .";

// We do something custom to eek out a little bit more performance
// over just a simple `rand::distributions::Alphanumeric.sample_string`.
let mut rng = rand_xorshift::XorShiftRng::seed_from_u64(1);
let content = std::iter::from_fn(move || Some(rng.next_u32()))
.flat_map(u32::to_le_bytes)
.map(|num| CHARS_LUT[(num >> (8 - 6)) as usize])
.take(size)
.collect::<Vec<_>>();

let hash = blake3::hash(content.as_bytes());
let hash = blake3::hash(&content);
std::fs::write(path, content)?;
Ok(hash.into())
}
Expand Down Expand Up @@ -904,7 +914,7 @@ fn match_get_stderr(stderr: Vec<u8>) -> Result<Vec<(usize, Vec<String>)>> {
(r"", 1),
(r"Fetching: [\da-z]{52}", 1),
(
r"Transferred (\d*.?\d*? ?[BKMGT]i?B?) in \d* seconds?, \d*.?\d* ?(?:B|KiB|MiB|GiB|TiB)/s",
r"Transferred (\d*.?\d*? ?[BKMGT]i?B?) in \d* (second|minute)s?, \d*.?\d* ?(?:B|KiB|MiB|GiB|TiB)/s",
1,
),
],
Expand Down
Loading