about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-19T11·04+0300
committerclbot <clbot@tvl.fyi>2024-04-19T19·22+0000
commit57f6cb4b1fde4dbb4fc82e9eb57e5675e11f5e98 (patch)
treece286a9604e220f94e6f34a5544047a63f0d84ec /tvix
parent0ecd594c87e983be74ef6d79c6a0c344c5d937f9 (diff)
chore(tvix/build): migrate from test_case to rstest r/7967
Change-Id: I75d8d61f836c76e8765e0e3b49022c056de84850
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11466
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/Cargo.lock2
-rw-r--r--tvix/Cargo.nix4
-rw-r--r--tvix/build/Cargo.toml2
-rw-r--r--tvix/build/src/buildservice/from_addr.rs35
-rw-r--r--tvix/build/src/proto/mod.rs37
5 files changed, 41 insertions, 39 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock
index b82bbfd99c95..e62cbde8e3d9 100644
--- a/tvix/Cargo.lock
+++ b/tvix/Cargo.lock
@@ -4318,7 +4318,7 @@ dependencies = [
  "itertools 0.12.0",
  "prost 0.12.3",
  "prost-build",
- "test-case",
+ "rstest",
  "thiserror",
  "tokio",
  "tokio-listener",
diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix
index 693b5de316b6..4a9ad94d3a33 100644
--- a/tvix/Cargo.nix
+++ b/tvix/Cargo.nix
@@ -13730,8 +13730,8 @@ rec {
         ];
         devDependencies = [
           {
-            name = "test-case";
-            packageId = "test-case";
+            name = "rstest";
+            packageId = "rstest";
           }
         ];
         features = {
diff --git a/tvix/build/Cargo.toml b/tvix/build/Cargo.toml
index bda2d136c759..626fd35d7713 100644
--- a/tvix/build/Cargo.toml
+++ b/tvix/build/Cargo.toml
@@ -30,4 +30,4 @@ default = []
 tonic-reflection = ["dep:tonic-reflection"]
 
 [dev-dependencies]
-test-case = "3.3.1"
+rstest = "0.19.0"
diff --git a/tvix/build/src/buildservice/from_addr.rs b/tvix/build/src/buildservice/from_addr.rs
index f5c4e6a490bb..cc5403edefff 100644
--- a/tvix/build/src/buildservice/from_addr.rs
+++ b/tvix/build/src/buildservice/from_addr.rs
@@ -50,38 +50,41 @@ mod tests {
     use std::sync::Arc;
 
     use super::from_addr;
-    use test_case::test_case;
+    use rstest::rstest;
     use tvix_castore::{
         blobservice::{BlobService, MemoryBlobService},
         directoryservice::{DirectoryService, MemoryDirectoryService},
     };
 
+    #[rstest]
     /// This uses an unsupported scheme.
-    #[test_case("http://foo.example/test", false; "unsupported scheme")]
+    #[case::unsupported_scheme("http://foo.example/test", false)]
     /// This configures dummy
-    #[test_case("dummy://", true; "valid dummy")]
+    #[case::valid_dummy("dummy://", true)]
     /// Correct scheme to connect to a unix socket.
-    #[test_case("grpc+unix:///path/to/somewhere", true; "grpc valid unix socket")]
+    #[case::grpc_valid_unix_socket("grpc+unix:///path/to/somewhere", true)]
     /// Correct scheme for unix socket, but setting a host too, which is invalid.
-    #[test_case("grpc+unix://host.example/path/to/somewhere", false; "grpc invalid unix socket and host")]
+    #[case::grpc_invalid_unix_socket_and_host("grpc+unix://host.example/path/to/somewhere", false)]
     /// Correct scheme to connect to localhost, with port 12345
-    #[test_case("grpc+http://[::1]:12345", true; "grpc valid IPv6 localhost port 12345")]
+    #[case::grpc_valid_ipv6_localhost_port_12345("grpc+http://[::1]:12345", true)]
     /// Correct scheme to connect to localhost over http, without specifying a port.
-    #[test_case("grpc+http://localhost", true; "grpc valid http host without port")]
+    #[case::grpc_valid_http_host_without_port("grpc+http://localhost", true)]
     /// Correct scheme to connect to localhost over http, without specifying a port.
-    #[test_case("grpc+https://localhost", true; "grpc valid https host without port")]
+    #[case::grpc_valid_https_host_without_port("grpc+https://localhost", true)]
     /// Correct scheme to connect to localhost over http, but with additional path, which is invalid.
-    #[test_case("grpc+http://localhost/some-path", false; "grpc valid invalid host and path")]
+    #[case::grpc_invalid_host_and_path("grpc+http://localhost/some-path", false)]
     #[tokio::test]
-    async fn test_from_addr(uri_str: &str, is_ok: bool) {
+    async fn test_from_addr(#[case] uri_str: &str, #[case] exp_succeed: bool) {
         let blob_service: Arc<dyn BlobService> = Arc::from(MemoryBlobService::default());
         let directory_service: Arc<dyn DirectoryService> =
             Arc::from(MemoryDirectoryService::default());
-        assert_eq!(
-            from_addr(uri_str, blob_service, directory_service)
-                .await
-                .is_ok(),
-            is_ok
-        )
+
+        let resp = from_addr(uri_str, blob_service, directory_service).await;
+
+        if exp_succeed {
+            resp.expect("should succeed");
+        } else {
+            assert!(resp.is_err(), "should fail");
+        }
     }
 }
diff --git a/tvix/build/src/proto/mod.rs b/tvix/build/src/proto/mod.rs
index c7831795c30e..e359b5b5b70e 100644
--- a/tvix/build/src/proto/mod.rs
+++ b/tvix/build/src/proto/mod.rs
@@ -236,28 +236,27 @@ impl build_request::BuildConstraints {
 
 #[cfg(test)]
 mod tests {
-    use test_case::test_case;
-
-    use crate::proto::is_clean_relative_path;
-
-    use super::is_clean_path;
-
-    #[test_case("foo/bar/", false; "fail trailing slash")]
-    #[test_case("foo/../bar", false; "fail dotdot")]
-    #[test_case("foo/./bar", false; "fail singledot")]
-    #[test_case("foo//bar", false; "fail unnecessary slashes")]
-    #[test_case("//foo/bar", false; "fail absolute unnecessary slashes")]
-    #[test_case("", true; "ok empty")]
-    #[test_case("foo/bar", true; "ok relative")]
-    #[test_case("/", true; "ok absolute")]
-    #[test_case("/foo/bar", true; "ok absolute2")]
-    fn test_is_clean_path(s: &str, expected: bool) {
+    use super::{is_clean_path, is_clean_relative_path};
+    use rstest::rstest;
+
+    #[rstest]
+    #[case::fail_trailing_slash("foo/bar/", false)]
+    #[case::fail_dotdot("foo/../bar", false)]
+    #[case::fail_singledot("foo/./bar", false)]
+    #[case::fail_unnecessary_slashes("foo//bar", false)]
+    #[case::fail_absolute_unnecessary_slashes("//foo/bar", false)]
+    #[case::ok_empty("", true)]
+    #[case::ok_relative("foo/bar", true)]
+    #[case::ok_absolute("/", true)]
+    #[case::ok_absolute2("/foo/bar", true)]
+    fn test_is_clean_path(#[case] s: &str, #[case] expected: bool) {
         assert_eq!(is_clean_path(s), expected);
     }
 
-    #[test_case("/", false; "fail absolute")]
-    #[test_case("foo/bar", true; "ok relative")]
-    fn test_is_clean_relative_path(s: &str, expected: bool) {
+    #[rstest]
+    #[case::fail_absolute("/", false)]
+    #[case::ok_relative("foo/bar", true)]
+    fn test_is_clean_relative_path(#[case] s: &str, #[case] expected: bool) {
         assert_eq!(is_clean_relative_path(s), expected);
     }