diff options
author | Jill <kokakiwi@deuxfleurs.fr> | 2022-02-04 17:55:54 +0100 |
---|---|---|
committer | Jill <kokakiwi@deuxfleurs.fr> | 2022-02-10 17:55:50 +0100 |
commit | d7decda3f4423602e2a8064fa398181736b3a3ab (patch) | |
tree | f8b8ee686989bc987e036d47a897864016c7656e /src/garage/tests/common/util.rs | |
parent | cd13ea461b5e6011ddda28c4923260315d67482a (diff) | |
download | garage-d7decda3f4423602e2a8064fa398181736b3a3ab.tar.gz garage-d7decda3f4423602e2a8064fa398181736b3a3ab.zip |
garage(tests): Add random suffix to created buckets.
Diffstat (limited to 'src/garage/tests/common/util.rs')
-rw-r--r-- | src/garage/tests/common/util.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/garage/tests/common/util.rs b/src/garage/tests/common/util.rs new file mode 100644 index 00000000..49c72879 --- /dev/null +++ b/src/garage/tests/common/util.rs @@ -0,0 +1,13 @@ +pub fn random_id(len: usize) -> String { + use rand::distributions::Slice; + use rand::Rng; + + static ALPHABET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789."; + + let rng = rand::thread_rng(); + rng.sample_iter(Slice::new(ALPHABET).unwrap()) + .map(|b| char::from(*b)) + .filter(|c| c.is_ascii_lowercase() || c.is_ascii_digit()) + .take(len) + .collect() +} |