From 9c5c717a990a1ba427e5e76c7613034c8aabee33 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 13 Dec 2023 12:05:24 +0200 Subject: feat(tvix/glue): add single-file import tests This ensures importing these paths also behave the same way as Nix. Change-Id: Icaa507bbe3d9867a301fc7a300c5d2b3f9feb911 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10355 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/glue/src/tvix_store_io.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs index 325e11e97397..611e354414e0 100644 --- a/tvix/glue/src/tvix_store_io.rs +++ b/tvix/glue/src/tvix_store_io.rs @@ -446,4 +446,27 @@ mod tests { import_path_and_compare(src_path.join(".")) ); } + + /// Import a file into the store. Nix uses the "recursive"/NAR-based hashing + /// scheme for these. + #[test] + fn import_file() { + let tmpdir = TempDir::new().unwrap(); + + // write a regular file `empty`. + std::fs::write(tmpdir.path().join("empty"), vec![]).unwrap(); + + assert_eq!( + Some("/nix/store/lx5i78a4izwk2qj1nq8rdc07y8zrwy90-empty".to_string()), + import_path_and_compare(tmpdir.path().join("empty")) + ); + + // write a regular file `hello.txt`. + std::fs::write(tmpdir.path().join("hello.txt"), b"Hello World!").unwrap(); + + assert_eq!( + Some("/nix/store/925f1jb1ajrypjbyq7rylwryqwizvhp0-hello.txt".to_string()), + import_path_and_compare(tmpdir.path().join("hello.txt")) + ); + } } -- cgit 1.4.1