Skip to content

Commit 60d0e8c

Browse files
authored
Merge branch 'master' into master
2 parents 5234d61 + 365f13e commit 60d0e8c

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The following Benchmarking results demonstrate that Nydus images significantly o
6363
| ------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ |
6464
| Storage | Registry/OSS/S3/NAS | Support for OCI-compatible distribution implementations such as Docker Hub, Harbor, Github GHCR, Aliyun ACR, NAS, and Aliyun OSS-like object storage service ||
6565
| Storage/Build | [Harbor](https://github.com/goharbor/acceleration-service) | Provides a general service for Harbor to support acceleration image conversion based on kinds of accelerator like Nydus and eStargz etc ||
66-
| Distribution | [Dragonfly](https://github.com/dragonflyoss/Dragonfly2) | Improve the runtime performance of Nydus image even further with the Dragonfly P2P data distribution system ||
66+
| Distribution | [Dragonfly](https://github.com/dragonflyoss/dragonfly) | Improve the runtime performance of Nydus image even further with the Dragonfly P2P data distribution system ||
6767
| Build | [Buildkit](https://github.com/nydusaccelerator/buildkit/blob/master/docs/nydus.md) | Provides the ability to build and export Nydus images directly from Dockerfile ||
6868
| Build/Runtime | [Nerdctl](https://github.com/containerd/nerdctl/blob/master/docs/nydus.md) | The containerd client to build or run (requires nydus snapshotter) Nydus image ||
6969
| Runtime | [Docker / Moby](https://github.com/dragonflyoss/nydus/blob/master/docs/docker-env-setup.md) | Run Nydus image in Docker container with containerd and nydus-snapshotter ||

utils/src/compress/mod.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ pub enum Algorithm {
2929

3030
impl fmt::Display for Algorithm {
3131
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32-
write!(f, "{:?}", self)
32+
let output = match self {
33+
Algorithm::None => "none",
34+
Algorithm::Lz4Block => "lz4_block",
35+
Algorithm::GZip => "gzip",
36+
Algorithm::Zstd => "zstd",
37+
};
38+
write!(f, "{}", output)
3339
}
3440
}
3541

@@ -250,6 +256,7 @@ mod tests {
250256
use std::fs::OpenOptions;
251257
use std::io::{Seek, SeekFrom};
252258
use std::path::Path;
259+
use std::str::FromStr;
253260
use vmm_sys_util::tempfile::TempFile;
254261

255262
#[test]
@@ -593,4 +600,46 @@ mod tests {
593600
assert!(!Algorithm::GZip.is_none());
594601
assert!(!Algorithm::Zstd.is_none());
595602
}
603+
604+
#[test]
605+
fn test_algorithm_to_string() {
606+
assert_eq!(Algorithm::None.to_string(), "none");
607+
assert_eq!(Algorithm::Lz4Block.to_string(), "lz4_block");
608+
assert_eq!(Algorithm::GZip.to_string(), "gzip");
609+
assert_eq!(Algorithm::Zstd.to_string(), "zstd");
610+
}
611+
612+
#[test]
613+
fn test_algorithm_from_str() {
614+
assert_eq!(Algorithm::from_str("none").unwrap(), Algorithm::None);
615+
assert_eq!(
616+
Algorithm::from_str("lz4_block").unwrap(),
617+
Algorithm::Lz4Block
618+
);
619+
assert_eq!(Algorithm::from_str("gzip").unwrap(), Algorithm::GZip);
620+
assert_eq!(Algorithm::from_str("zstd").unwrap(), Algorithm::Zstd);
621+
}
622+
623+
#[test]
624+
fn test_algorithm_to_string_and_from_str_consistency() {
625+
let algorithms = vec![
626+
Algorithm::None,
627+
Algorithm::Lz4Block,
628+
Algorithm::GZip,
629+
Algorithm::Zstd,
630+
];
631+
632+
for algo in algorithms {
633+
let stringified = algo.to_string();
634+
let parsed = Algorithm::from_str(&stringified).unwrap();
635+
assert_eq!(algo, parsed, "Mismatch for algorithm: {:?}", algo);
636+
}
637+
}
638+
639+
#[test]
640+
fn test_algorithm_from_str_invalid_input() {
641+
assert!(Algorithm::from_str("invalid_algorithm").is_err());
642+
assert!(Algorithm::from_str("GZIP").is_err());
643+
assert!(Algorithm::from_str("LZ4_BLOCK").is_err());
644+
}
596645
}

0 commit comments

Comments
 (0)