about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-11-13T10·06+0200
committerflokli <flokli@flokli.de>2023-11-15T06·43+0000
commit362117fbf56da6cef07bc661ce99e41e7d3cff64 (patch)
tree1cffc3cae9c41310829f3ccda879d59cba591831
parent9aef3cfc8989c491db05c4d66cdbf3d89429420e (diff)
feat(tvix/castore/src/channel): move from_url tests r/7016
These gRPC PathInfoService tests were actually not too useful in here,
what we're mostly testing is the channel construction, so move it to
there.

Change-Id: Ic8c07558a1b28b46f863d5c39bcaa3a79cea007a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10024
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
-rw-r--r--tvix/castore/src/channel.rs60
-rw-r--r--tvix/store/src/pathinfoservice/grpc.rs74
2 files changed, 61 insertions, 73 deletions
diff --git a/tvix/castore/src/channel.rs b/tvix/castore/src/channel.rs
index 53f9bd3344..2fe9724767 100644
--- a/tvix/castore/src/channel.rs
+++ b/tvix/castore/src/channel.rs
@@ -66,3 +66,63 @@ impl From<tonic::transport::Error> for Error {
         Self::TransportError(value)
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::from_url;
+
+    /// This uses the correct scheme for a unix socket.
+    /// The fact that /path/to/somewhere doesn't exist yet is no problem, because we connect lazily.
+    #[tokio::test]
+    async fn test_valid_unix_path() {
+        let url = url::Url::parse("grpc+unix:///path/to/somewhere").expect("must parse");
+
+        assert!(from_url(&url).is_ok())
+    }
+
+    /// This uses the correct scheme for a unix socket,
+    /// but sets a host, which is unsupported.
+    #[tokio::test]
+    async fn test_invalid_unix_path_with_domain() {
+        let url =
+            url::Url::parse("grpc+unix://host.example/path/to/somewhere").expect("must parse");
+
+        assert!(from_url(&url).is_err())
+    }
+
+    /// This uses the wrong scheme
+    #[test]
+    fn test_invalid_scheme() {
+        let url = url::Url::parse("http://foo.example/test").expect("must parse");
+
+        assert!(from_url(&url).is_err());
+    }
+
+    /// This uses the correct scheme for a HTTP server.
+    /// The fact that nothing is listening there is no problem, because we connect lazily.
+    #[tokio::test]
+    async fn test_valid_http() {
+        let url = url::Url::parse("grpc+http://localhost").expect("must parse");
+
+        assert!(from_url(&url).is_ok());
+    }
+
+    /// This uses the correct scheme for a HTTPS server.
+    /// The fact that nothing is listening there is no problem, because we connect lazily.
+    #[tokio::test]
+    async fn test_valid_https() {
+        let url = url::Url::parse("grpc+https://localhost").expect("must parse");
+
+        assert!(from_url(&url).is_ok());
+    }
+
+    /// This uses the correct scheme, but also specifies
+    /// an additional path, which is not supported for gRPC.
+    /// The fact that nothing is listening there is no problem, because we connect lazily.
+    #[tokio::test]
+    async fn test_invalid_http_with_path() {
+        let url = url::Url::parse("grpc+https://localhost/some-path").expect("must parse");
+
+        assert!(from_url(&url).is_err());
+    }
+}
diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs
index 7428830abd..a33f75c1fd 100644
--- a/tvix/store/src/pathinfoservice/grpc.rs
+++ b/tvix/store/src/pathinfoservice/grpc.rs
@@ -144,6 +144,7 @@ mod tests {
     use tokio_stream::wrappers::UnixListenerStream;
 
     use crate::pathinfoservice::MemoryPathInfoService;
+    use crate::proto::path_info_service_client::PathInfoServiceClient;
     use crate::proto::GRPCPathInfoServiceWrapper;
     use crate::tests::fixtures;
     use crate::tests::utils::gen_blob_service;
@@ -152,79 +153,6 @@ mod tests {
     use super::GRPCPathInfoService;
     use super::PathInfoService;
 
-    /// This uses the wrong scheme
-    #[test]
-    fn test_invalid_scheme() {
-        let url = url::Url::parse("http://foo.example/test").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_err()
-        );
-    }
-
-    /// This uses the correct scheme for a unix socket.
-    /// The fact that /path/to/somewhere doesn't exist yet is no problem, because we connect lazily.
-    #[tokio::test]
-    async fn test_valid_unix_path() {
-        let url = url::Url::parse("grpc+unix:///path/to/somewhere").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_ok()
-        );
-    }
-
-    /// This uses the correct scheme for a unix socket,
-    /// but sets a host, which is unsupported.
-    #[tokio::test]
-    async fn test_invalid_unix_path_with_domain() {
-        let url =
-            url::Url::parse("grpc+unix://host.example/path/to/somewhere").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_err()
-        );
-    }
-
-    /// This uses the correct scheme for a HTTP server.
-    /// The fact that nothing is listening there is no problem, because we connect lazily.
-    #[tokio::test]
-    async fn test_valid_http() {
-        let url = url::Url::parse("grpc+http://localhost").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_ok()
-        );
-    }
-
-    /// This uses the correct scheme for a HTTPS server.
-    /// The fact that nothing is listening there is no problem, because we connect lazily.
-    #[tokio::test]
-    async fn test_valid_https() {
-        let url = url::Url::parse("grpc+https://localhost").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_ok()
-        );
-    }
-
-    /// This uses the correct scheme, but also specifies
-    /// an additional path, which is not supported for gRPC.
-    /// The fact that nothing is listening there is no problem, because we connect lazily.
-    #[tokio::test]
-    async fn test_invalid_http_with_path() {
-        let url = url::Url::parse("grpc+https://localhost/some-path").expect("must parse");
-
-        assert!(
-            GRPCPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service())
-                .is_err()
-        );
-    }
-
     /// This ensures connecting via gRPC works as expected.
     #[tokio::test]
     async fn test_valid_unix_path_ping_pong() {