about summary refs log tree commit diff
path: root/tvix/derivation/src/tests
diff options
context:
space:
mode:
authorJürgen Hahn <mail.jhahn@gmail.com>2023-01-02T15·09+0100
committerjrhahn <mail.jhahn@gmail.com>2023-01-04T12·24+0000
commit6f993b8bde8201213fe2953ea663ac387de916e3 (patch)
treef82cd8094172c18a5eb0601f278fa4205e48344c /tvix/derivation/src/tests
parent79c05f38109d2eac07b9ba893b9b6f67fd34c29c (diff)
feat(tvix/derivation): add nix drv path generation to Derivation r/5580
This adds a function to generate the derivation path. The computation
is based on the Go implementation.

Change-Id: Iae89db4976f5fd9208f0453f73688689a245cd66
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7729
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/derivation/src/tests')
-rw-r--r--tvix/derivation/src/tests/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/tvix/derivation/src/tests/mod.rs b/tvix/derivation/src/tests/mod.rs
index 3d4aae3fe4d4..435d82144067 100644
--- a/tvix/derivation/src/tests/mod.rs
+++ b/tvix/derivation/src/tests/mod.rs
@@ -2,8 +2,11 @@ use crate::derivation::Derivation;
 use std::fs::File;
 use std::io::Read;
 use std::path::Path;
+use test_case::test_case;
 use test_generator::test_resources;
 
+const RESOURCES_PATHS: &str = "src/tests/derivation_tests";
+
 fn read_file(path: &str) -> String {
     let path = Path::new(path);
     let mut file = File::open(path).unwrap();
@@ -36,3 +39,17 @@ fn check_to_string(path_to_drv_file: &str) {
 
     assert_eq!(expected, derivation.to_string());
 }
+
+#[test_case("bar","0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv"; "fixed_sha256")]
+#[test_case("foo", "4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv"; "simple-sha256")]
+#[test_case("bar", "ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv"; "fixed-sha1")]
+#[test_case("foo", "ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv"; "simple-sha1")]
+#[test_case("has-multi-out", "h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv"; "multiple-outputs")]
+#[test_case("structured-attrs", "9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv"; "structured-attrs")]
+#[test_case("unicode", "52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv"; "unicode")]
+fn derivation_path(name: &str, expected_path: &str) {
+    let data = read_file(&format!("{}/{}.json", RESOURCES_PATHS, expected_path));
+    let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted");
+
+    assert_eq!(derivation.calculate_derivation_path(name), expected_path);
+}