Skip to main content

auths_cli/commands/artifact/
file.rs

1//! File artifact adapter.
2//!
3//! Re-exports `LocalFileArtifact` from the adapters layer for
4//! backwards compatibility with existing command code.
5
6pub use crate::adapters::local_file::LocalFileArtifact as FileArtifact;
7
8#[cfg(test)]
9mod tests {
10    use super::*;
11    use auths_sdk::ports::artifact::ArtifactSource;
12    use std::io::Write;
13    use std::path::Path;
14    use tempfile::NamedTempFile;
15
16    #[test]
17    fn file_artifact_digest_is_deterministic() {
18        let mut tmp = NamedTempFile::new().unwrap();
19        tmp.write_all(b"hello world").unwrap();
20        tmp.flush().unwrap();
21
22        let a = FileArtifact::new(tmp.path());
23        let d1 = a.digest().unwrap();
24        let d2 = a.digest().unwrap();
25
26        assert_eq!(d1, d2);
27        assert_eq!(d1.algorithm, "sha256");
28        assert_eq!(
29            d1.hex,
30            "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
31        );
32    }
33
34    #[test]
35    fn file_artifact_metadata_includes_name_and_size() {
36        let mut tmp = NamedTempFile::new().unwrap();
37        tmp.write_all(b"some content").unwrap();
38        tmp.flush().unwrap();
39
40        let a = FileArtifact::new(tmp.path());
41        let meta = a.metadata().unwrap();
42
43        assert_eq!(meta.artifact_type, "file");
44        assert!(meta.name.is_some());
45        assert_eq!(meta.size, Some(12));
46    }
47
48    #[test]
49    fn file_artifact_nonexistent_returns_error() {
50        let a = FileArtifact::new(Path::new("/nonexistent/path/to/file.txt"));
51        assert!(a.digest().is_err());
52    }
53}