about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-06T21·21+0300
committerflokli <flokli@flokli.de>2024-04-07T14·51+0000
commitd94ff54d42e91f8856fe5a6d5b0fa21b2e22a7e2 (patch)
tree0e19b64fc6b26ec2304edd8fbb25989a710cac71 /tvix
parentc715b6d4486b2c9fc0e42b1d8e62004dc91868bd (diff)
refactor(tvix/castore): migrate closure_validator to rstest r/7864
Change-Id: I6c594d2e670a681484b858c3e04bc25b9e5a2077
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11368
Tested-by: BuildkiteCI
Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/castore/src/directoryservice/closure_validator.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/tvix/castore/src/directoryservice/closure_validator.rs b/tvix/castore/src/directoryservice/closure_validator.rs
index cc421d4ab5ad..6f263157a9fb 100644
--- a/tvix/castore/src/directoryservice/closure_validator.rs
+++ b/tvix/castore/src/directoryservice/closure_validator.rs
@@ -174,7 +174,7 @@ mod tests {
         proto::{self, Directory},
     };
     use lazy_static::lazy_static;
-    use test_case::test_case;
+    use rstest::rstest;
 
     lazy_static! {
         pub static ref BROKEN_DIRECTORY : Directory = Directory {
@@ -197,28 +197,29 @@ mod tests {
 
     use super::ClosureValidator;
 
+    #[rstest]
     /// Uploading an empty directory should succeed.
-    #[test_case(vec![&DIRECTORY_A], false, Some(vec![&DIRECTORY_A]); "empty directory")]
+    #[case::empty_directory(&[&*DIRECTORY_A], false, Some(vec![&*DIRECTORY_A]))]
     /// Uploading A, then B (referring to A) should succeed.
-    #[test_case(vec![&DIRECTORY_A, &DIRECTORY_B], false, Some(vec![&DIRECTORY_A, &DIRECTORY_B]); "simple closure")]
+    #[case::simple_closure(&[&*DIRECTORY_A, &*DIRECTORY_B], false, Some(vec![&*DIRECTORY_A, &*DIRECTORY_B]))]
     /// Uploading A, then A, then C (referring to A twice) should succeed.
     /// We pretend to be a dumb client not deduping directories.
-    #[test_case(vec![&DIRECTORY_A, &DIRECTORY_A, &DIRECTORY_C], false, Some(vec![&DIRECTORY_A, &DIRECTORY_C]); "same child")]
+    #[case::same_child(&[&*DIRECTORY_A, &*DIRECTORY_A, &*DIRECTORY_C], false, Some(vec![&*DIRECTORY_A, &*DIRECTORY_C]))]
     /// Uploading A, then C (referring to A twice) should succeed.
-    #[test_case(vec![&DIRECTORY_A, &DIRECTORY_C], false, Some(vec![&DIRECTORY_A, &DIRECTORY_C]); "same child dedup")]
+    #[case::same_child_dedup(&[&*DIRECTORY_A, &*DIRECTORY_C], false, Some(vec![&*DIRECTORY_A, &*DIRECTORY_C]))]
     /// Uploading A, then C (referring to A twice), then B (itself referring to A) should fail during close,
     /// as B itself would be left unconnected.
-    #[test_case(vec![&DIRECTORY_A, &DIRECTORY_C, &DIRECTORY_B], false, None; "unconnected node")]
+    #[case::unconnected_node(&[&*DIRECTORY_A, &*DIRECTORY_C, &*DIRECTORY_B], false, None)]
     /// Uploading B (referring to A) should fail immediately, because A was never uploaded.
-    #[test_case(vec![&DIRECTORY_B], true, None; "dangling pointer")]
+    #[case::dangling_pointer(&[&*DIRECTORY_B], true, None)]
     /// Uploading a directory failing validation should fail immediately.
-    #[test_case(vec![&BROKEN_DIRECTORY], true, None; "failing validation")]
+    #[case::failing_validation(&[&*BROKEN_DIRECTORY], true, None)]
     /// Uploading a directory which refers to another Directory with a wrong size should fail.
-    #[test_case(vec![&DIRECTORY_A, &BROKEN_PARENT_DIRECTORY], true, None; "wrong size in parent")]
+    #[case::wrong_size_in_parent(&[&*DIRECTORY_A, &*BROKEN_PARENT_DIRECTORY], true, None)]
     fn test_uploads(
-        directories_to_upload: Vec<&Directory>,
-        exp_fail_upload_last: bool,
-        exp_finalize: Option<Vec<&Directory>>, // Some(_) if finalize successful, None if not.
+        #[case] directories_to_upload: &[&Directory],
+        #[case] exp_fail_upload_last: bool,
+        #[case] exp_finalize: Option<Vec<&Directory>>, // Some(_) if finalize successful, None if not.
     ) {
         let mut dcv = ClosureValidator::default();
         let len_directories_to_upload = directories_to_upload.len();
@@ -242,7 +243,7 @@ mod tests {
         match exp_finalize {
             Some(exp_drain) => {
                 assert_eq!(
-                    Vec::from_iter(exp_drain.into_iter().map(|e| e.to_owned())),
+                    Vec::from_iter(exp_drain.iter().map(|e| (*e).to_owned())),
                     resp.expect("drain should succeed")
                 );
             }