mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 22:03:14 +00:00
This commit is contained in:
@@ -178,7 +178,7 @@ mod tests {
|
||||
fn test_compress_decompress_gzip() {
|
||||
let data = b"hello gzip compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Gzip);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Gzip).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Gzip).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ mod tests {
|
||||
fn test_compress_decompress_deflate() {
|
||||
let data = b"hello deflate compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Deflate);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Deflate).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Deflate).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ mod tests {
|
||||
fn test_compress_decompress_zstd() {
|
||||
let data = b"hello zstd compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Zstd);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Zstd).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Zstd).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ mod tests {
|
||||
fn test_compress_decompress_lz4() {
|
||||
let data = b"hello lz4 compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Lz4);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Lz4).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Lz4).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ mod tests {
|
||||
fn test_compress_decompress_brotli() {
|
||||
let data = b"hello brotli compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Brotli);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Brotli).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Brotli).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
@@ -218,18 +218,18 @@ mod tests {
|
||||
fn test_compress_decompress_snappy() {
|
||||
let data = b"hello snappy compress";
|
||||
let compressed = compress_block(data, CompressionAlgorithm::Snappy);
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Snappy).unwrap();
|
||||
let decompressed = decompress_block(&compressed, CompressionAlgorithm::Snappy).expect("operation should succeed");
|
||||
assert_eq!(decompressed, data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert_eq!(CompressionAlgorithm::from_str("gzip").unwrap(), CompressionAlgorithm::Gzip);
|
||||
assert_eq!(CompressionAlgorithm::from_str("deflate").unwrap(), CompressionAlgorithm::Deflate);
|
||||
assert_eq!(CompressionAlgorithm::from_str("zstd").unwrap(), CompressionAlgorithm::Zstd);
|
||||
assert_eq!(CompressionAlgorithm::from_str("lz4").unwrap(), CompressionAlgorithm::Lz4);
|
||||
assert_eq!(CompressionAlgorithm::from_str("brotli").unwrap(), CompressionAlgorithm::Brotli);
|
||||
assert_eq!(CompressionAlgorithm::from_str("snappy").unwrap(), CompressionAlgorithm::Snappy);
|
||||
assert_eq!(CompressionAlgorithm::from_str("gzip").expect("operation should succeed"), CompressionAlgorithm::Gzip);
|
||||
assert_eq!(CompressionAlgorithm::from_str("deflate").expect("operation should succeed"), CompressionAlgorithm::Deflate);
|
||||
assert_eq!(CompressionAlgorithm::from_str("zstd").expect("operation should succeed"), CompressionAlgorithm::Zstd);
|
||||
assert_eq!(CompressionAlgorithm::from_str("lz4").expect("operation should succeed"), CompressionAlgorithm::Lz4);
|
||||
assert_eq!(CompressionAlgorithm::from_str("brotli").expect("operation should succeed"), CompressionAlgorithm::Brotli);
|
||||
assert_eq!(CompressionAlgorithm::from_str("snappy").expect("operation should succeed"), CompressionAlgorithm::Snappy);
|
||||
assert!(CompressionAlgorithm::from_str("unknown").is_err());
|
||||
}
|
||||
|
||||
@@ -278,12 +278,12 @@ mod tests {
|
||||
println!("{name}: {size} bytes, {dur:?}");
|
||||
}
|
||||
// All should decompress to the original
|
||||
assert_eq!(decompress_block(&gzip, CompressionAlgorithm::Gzip).unwrap(), data);
|
||||
assert_eq!(decompress_block(&deflate, CompressionAlgorithm::Deflate).unwrap(), data);
|
||||
assert_eq!(decompress_block(&zstd, CompressionAlgorithm::Zstd).unwrap(), data);
|
||||
assert_eq!(decompress_block(&lz4, CompressionAlgorithm::Lz4).unwrap(), data);
|
||||
assert_eq!(decompress_block(&brotli, CompressionAlgorithm::Brotli).unwrap(), data);
|
||||
assert_eq!(decompress_block(&snappy, CompressionAlgorithm::Snappy).unwrap(), data);
|
||||
assert_eq!(decompress_block(&gzip, CompressionAlgorithm::Gzip).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&deflate, CompressionAlgorithm::Deflate).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&zstd, CompressionAlgorithm::Zstd).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&lz4, CompressionAlgorithm::Lz4).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&brotli, CompressionAlgorithm::Brotli).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&snappy, CompressionAlgorithm::Snappy).expect("operation should succeed"), data);
|
||||
// All compressed results should not be empty
|
||||
assert!(
|
||||
!gzip.is_empty()
|
||||
@@ -326,7 +326,7 @@ mod tests {
|
||||
|
||||
// Decompression test
|
||||
let start = Instant::now();
|
||||
let _decompressed = decompress_block(&compressed, algo).unwrap();
|
||||
let _decompressed = decompress_block(&compressed, algo).expect("operation should succeed");
|
||||
let _decompression_time = start.elapsed();
|
||||
|
||||
// Calculate compression ratio
|
||||
|
||||
@@ -84,7 +84,7 @@ pub fn is_sha256_checksum(s: &str) -> bool {
|
||||
/// A 20-byte array containing the HMAC-SHA1 hash of the input data using the provided key
|
||||
///
|
||||
pub fn hmac_sha1(key: impl AsRef<[u8]>, data: impl AsRef<[u8]>) -> [u8; 20] {
|
||||
let mut m = <Hmac<Sha1>>::new_from_slice(key.as_ref()).unwrap();
|
||||
let mut m = <Hmac<Sha1>>::new_from_slice(key.as_ref()).expect("operation should succeed");
|
||||
m.update(data.as_ref());
|
||||
m.finalize().into_bytes().into()
|
||||
}
|
||||
@@ -100,7 +100,7 @@ pub fn hmac_sha1(key: impl AsRef<[u8]>, data: impl AsRef<[u8]>) -> [u8; 20] {
|
||||
/// A 32-byte array containing the HMAC-SHA256 hash of the input data using the provided key
|
||||
///
|
||||
pub fn hmac_sha256(key: impl AsRef<[u8]>, data: impl AsRef<[u8]>) -> [u8; 32] {
|
||||
let mut m = Hmac::<Sha256>::new_from_slice(key.as_ref()).unwrap();
|
||||
let mut m = Hmac::<Sha256>::new_from_slice(key.as_ref()).expect("operation should succeed");
|
||||
m.update(data.as_ref());
|
||||
m.finalize().into_bytes().into()
|
||||
}
|
||||
@@ -149,8 +149,8 @@ fn test_base64_encoding_decoding() {
|
||||
|
||||
println!("Encoded: {}", &encoded_string);
|
||||
|
||||
let decoded_bytes = base64_decode_url_safe_no_pad(encoded_string.as_bytes()).unwrap();
|
||||
let decoded_string = String::from_utf8(decoded_bytes).unwrap();
|
||||
let decoded_bytes = base64_decode_url_safe_no_pad(encoded_string.as_bytes()).expect("operation should succeed");
|
||||
let decoded_string = String::from_utf8(decoded_bytes).expect("operation should succeed");
|
||||
|
||||
assert_eq!(decoded_string, original_uuid_timestamp)
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ use std::sync::LazyLock;
|
||||
/// let false_values = ["0", "f", "F", "false", "FALSE", "False", "off", "OFF", "Off", "disabled"];
|
||||
///
|
||||
/// for val in true_values.iter() {
|
||||
/// assert_eq!(parse_bool(val).unwrap(), true);
|
||||
/// assert_eq!(parse_bool(val).expect("operation should succeed"), true);
|
||||
/// }
|
||||
/// for val in false_values.iter() {
|
||||
/// assert_eq!(parse_bool(val).unwrap(), false);
|
||||
/// assert_eq!(parse_bool(val).expect("operation should succeed"), false);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
@@ -236,7 +236,7 @@ pub fn match_as_pattern_prefix(pattern: &str, text: &str) -> bool {
|
||||
text.len() <= pattern.len()
|
||||
}
|
||||
|
||||
static ELLIPSES_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(.*)(\{[0-9A-Fa-f]*\.\.\.[0-9A-Fa-f]*\})(.*)").unwrap());
|
||||
static ELLIPSES_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(.*)(\{[0-9A-Fa-f]*\.\.\.[0-9A-Fa-f]*\})(.*)").expect("operation should succeed"));
|
||||
|
||||
/// Ellipses constants
|
||||
const OPEN_BRACES: &str = "{";
|
||||
@@ -351,7 +351,7 @@ impl ArgPattern {
|
||||
/// use rustfs_utils::string::find_ellipses_patterns;
|
||||
///
|
||||
/// let pattern = "http://rustfs{2...3}/export/set{1...64}";
|
||||
/// let arg_pattern = find_ellipses_patterns(pattern).unwrap();
|
||||
/// let arg_pattern = find_ellipses_patterns(pattern).expect("operation should succeed");
|
||||
/// assert_eq!(arg_pattern.total_sizes(), 128);
|
||||
/// ```
|
||||
pub fn find_ellipses_patterns(arg: &str) -> Result<ArgPattern> {
|
||||
@@ -469,7 +469,7 @@ pub fn has_ellipses<T: AsRef<str>>(s: &[T]) -> bool {
|
||||
/// ```no_run
|
||||
/// use rustfs_utils::string::parse_ellipses_range;
|
||||
///
|
||||
/// let range = parse_ellipses_range("{1...5}").unwrap();
|
||||
/// let range = parse_ellipses_range("{1...5}").expect("operation should succeed");
|
||||
/// assert_eq!(range, vec!["1", "2", "3", "4", "5"]);
|
||||
/// ```
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user