From e7279b6063b3a4675f8ed37c797254de8a0c79e9 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 27 Feb 2023 09:12:09 +0100 Subject: refactor(tvix/store/tests): move fixtures into separate module Change-Id: I362dbf0899e4dc42114fd2e6a8fa7f537e9ea138 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8156 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/store/src/tests/fixtures.rs | 86 ++++++++++++++++++++++++++++++++++++ tvix/store/src/tests/mod.rs | 1 + tvix/store/src/tests/nar_renderer.rs | 38 +--------------- 3 files changed, 88 insertions(+), 37 deletions(-) create mode 100644 tvix/store/src/tests/fixtures.rs (limited to 'tvix/store/src/tests') diff --git a/tvix/store/src/tests/fixtures.rs b/tvix/store/src/tests/fixtures.rs new file mode 100644 index 000000000000..c6d80e279371 --- /dev/null +++ b/tvix/store/src/tests/fixtures.rs @@ -0,0 +1,86 @@ +use crate::proto::{self, Directory, DirectoryNode, FileNode, SymlinkNode}; +use lazy_static::lazy_static; + +pub const HELLOWORLD_BLOB_CONTENTS: &[u8] = b"Hello World!"; +pub const EMPTY_BLOB_CONTENTS: &[u8] = b""; + +lazy_static! { + pub static ref DUMMY_DIGEST: Vec = vec![ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + ]; + pub static ref DUMMY_DATA_1: Vec = vec![0x01, 0x02, 0x03]; + pub static ref DUMMY_DATA_2: Vec = vec![0x04, 0x05]; + pub static ref HELLOWORLD_BLOB_DIGEST: Vec = + blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().to_vec(); + pub static ref EMPTY_BLOB_DIGEST: Vec = + blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().to_vec(); + + // 2 bytes + pub static ref BLOB_A: Vec = vec![0x00, 0x01]; + pub static ref BLOB_A_DIGEST: Vec = blake3::hash(&BLOB_A).as_bytes().to_vec(); + + // 1MB + pub static ref BLOB_B: Vec = (0..255).collect::>().repeat(4 * 1024); + pub static ref BLOB_B_DIGEST: Vec = blake3::hash(&BLOB_B).as_bytes().to_vec(); + + // Directories + pub static ref DIRECTORY_WITH_KEEP: proto::Directory = proto::Directory { + directories: vec![], + files: vec![FileNode { + name: ".keep".to_string(), + digest: EMPTY_BLOB_DIGEST.to_vec(), + size: 0, + executable: false, + }], + symlinks: vec![], + }; + pub static ref DIRECTORY_COMPLICATED: proto::Directory = proto::Directory { + directories: vec![DirectoryNode { + name: "keep".to_string(), + digest: DIRECTORY_WITH_KEEP.digest(), + size: DIRECTORY_WITH_KEEP.size(), + }], + files: vec![FileNode { + name: ".keep".to_string(), + digest: EMPTY_BLOB_DIGEST.to_vec(), + size: 0, + executable: false, + }], + symlinks: vec![SymlinkNode { + name: "aa".to_string(), + target: "/nix/store/somewhereelse".to_string(), + }], + }; + pub static ref DIRECTORY_A: Directory = Directory::default(); + pub static ref DIRECTORY_B: Directory = Directory { + directories: vec![DirectoryNode { + name: "a".to_string(), + digest: DIRECTORY_A.digest(), + size: DIRECTORY_A.size(), + }], + ..Default::default() + }; + pub static ref DIRECTORY_C: Directory = Directory { + directories: vec![ + DirectoryNode { + name: "a".to_string(), + digest: DIRECTORY_A.digest(), + size: DIRECTORY_A.size(), + }, + DirectoryNode { + name: "a'".to_string(), + digest: DIRECTORY_A.digest(), + size: DIRECTORY_A.size(), + } + ], + ..Default::default() + }; + + // output hash + pub static ref DUMMY_OUTPUT_HASH: Vec = vec![ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 + ]; +} diff --git a/tvix/store/src/tests/mod.rs b/tvix/store/src/tests/mod.rs index 421858c03083..daea048deddf 100644 --- a/tvix/store/src/tests/mod.rs +++ b/tvix/store/src/tests/mod.rs @@ -1,2 +1,3 @@ +pub mod fixtures; mod nar_renderer; pub mod utils; diff --git a/tvix/store/src/tests/nar_renderer.rs b/tvix/store/src/tests/nar_renderer.rs index 4a72be5910fd..52cf43e9886d 100644 --- a/tvix/store/src/tests/nar_renderer.rs +++ b/tvix/store/src/tests/nar_renderer.rs @@ -6,46 +6,10 @@ use crate::proto; use crate::proto::DirectoryNode; use crate::proto::FileNode; use crate::proto::SymlinkNode; +use crate::tests::fixtures::*; use crate::tests::utils::*; -use lazy_static::lazy_static; use tempfile::TempDir; -const HELLOWORLD_BLOB_CONTENTS: &[u8] = b"Hello World!"; -const EMPTY_BLOB_CONTENTS: &[u8] = b""; - -lazy_static! { - static ref HELLOWORLD_BLOB_DIGEST: Vec = - blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().to_vec(); - static ref EMPTY_BLOB_DIGEST: Vec = blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().to_vec(); - static ref DIRECTORY_WITH_KEEP: proto::Directory = proto::Directory { - directories: vec![], - files: vec![FileNode { - name: ".keep".to_string(), - digest: EMPTY_BLOB_DIGEST.to_vec(), - size: 0, - executable: false, - }], - symlinks: vec![], - }; - static ref DIRECTORY_COMPLICATED: proto::Directory = proto::Directory { - directories: vec![DirectoryNode { - name: "keep".to_string(), - digest: DIRECTORY_WITH_KEEP.digest(), - size: DIRECTORY_WITH_KEEP.size(), - }], - files: vec![FileNode { - name: ".keep".to_string(), - digest: EMPTY_BLOB_DIGEST.to_vec(), - size: 0, - executable: false, - }], - symlinks: vec![SymlinkNode { - name: "aa".to_string(), - target: "/nix/store/somewhereelse".to_string(), - }], - }; -} - #[test] fn single_symlink() { let tmpdir = TempDir::new().unwrap(); -- cgit 1.4.1