From bb185b2c6eb8c4e035cddb61be772169df1b0139 Mon Sep 17 00:00:00 2001 From: Jürgen Hahn Date: Wed, 28 Dec 2022 10:28:37 +0100 Subject: feat(tvix/derivation): serialize Nix Derivation This adds a Derivation structure and allows to write it to a structure that implements std::fmt:Write. The implementation is based on the go-nix version. Change-Id: Ib54e1202b5c67f5d206b21bc109a751e971064cf Reviewed-on: https://cl.tvl.fyi/c/depot/+/7659 Reviewed-by: flokli Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/derivation/src/tests/mod.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tvix/derivation/src/tests/mod.rs (limited to 'tvix/derivation/src/tests/mod.rs') diff --git a/tvix/derivation/src/tests/mod.rs b/tvix/derivation/src/tests/mod.rs new file mode 100644 index 000000000000..9c8ffd061c11 --- /dev/null +++ b/tvix/derivation/src/tests/mod.rs @@ -0,0 +1,32 @@ +use super::{serialize_derivation, Derivation}; +use std::fs::File; +use std::io::Read; +use std::path::Path; +use test_generator::test_resources; + +fn read_file(path: &str) -> String { + let path = Path::new(path); + let mut file = File::open(path).unwrap(); + let mut data = String::new(); + + file.read_to_string(&mut data).unwrap(); + + return data; +} + +fn assert_derivation_ok(path_to_drv_file: &str) { + let data = read_file(&format!("{}.json", path_to_drv_file)); + let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted"); + + let mut serialized_derivation = String::new(); + serialize_derivation(derivation, &mut serialized_derivation).unwrap(); + + let expected = read_file(path_to_drv_file); + + assert_eq!(expected, serialized_derivation); +} + +#[test_resources("src/tests/derivation_tests/*.drv")] +fn derivation_files_ok(path: &str) { + assert_derivation_ok(path); +} -- cgit 1.4.1