about summary refs log tree commit diff
path: root/tvix/glue
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-13T10·05+0200
committerflokli <flokli@flokli.de>2023-12-13T13·42+0000
commit9c5c717a990a1ba427e5e76c7613034c8aabee33 (patch)
tree8cb79ec9f042df12b7445dd0813edeb2874ba2e7 /tvix/glue
parent3cdde8ad5a4650cbb248b070891daf72ccfc9af0 (diff)
feat(tvix/glue): add single-file import tests r/7213
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 <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/glue')
-rw-r--r--tvix/glue/src/tvix_store_io.rs23
1 files changed, 23 insertions, 0 deletions
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"))
+        );
+    }
 }