about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-18T19·37+0100
committerflokli <flokli@flokli.de>2023-01-21T09·34+0000
commita8b13a0b579c91b972b370be90f9db1626953db1 (patch)
treef495bf8af0fb0bc6e6ee63f32aebd75fbe6ab473
parente20c0d2fbf5dfb1355c1375fd6ae1f9bf1b8b263 (diff)
refactor(tvix/store): simplify test a bit r/5719
Import more things, and use expect_err to unpack the response.

Change-Id: Ia319dd4d126b8d0e1df585234710d825a33a0002
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7868
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r--tvix/store/src/tests/path_info_service.rs41
1 files changed, 17 insertions, 24 deletions
diff --git a/tvix/store/src/tests/path_info_service.rs b/tvix/store/src/tests/path_info_service.rs
index dca61fe12a..42e6db36ca 100644
--- a/tvix/store/src/tests/path_info_service.rs
+++ b/tvix/store/src/tests/path_info_service.rs
@@ -1,8 +1,11 @@
 use tempfile::TempDir;
+use tonic::Request;
 
+use crate::proto::get_path_info_request::ByWhat::ByOutputHash;
+use crate::proto::node::Node::Symlink;
 use crate::proto::path_info_service_server::PathInfoService;
-use crate::proto::GetPathInfoRequest;
-use crate::proto::{get_path_info_request, PathInfo};
+use crate::proto::PathInfo;
+use crate::proto::{GetPathInfoRequest, Node, SymlinkNode};
 use crate::sled_path_info_service::SledPathInfoService;
 
 use lazy_static::lazy_static;
@@ -20,19 +23,13 @@ async fn not_found() -> anyhow::Result<()> {
     let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
 
     let resp = service
-        .get(tonic::Request::new(GetPathInfoRequest {
-            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
-                DUMMY_OUTPUT_HASH.to_vec(),
-            )),
+        .get(Request::new(GetPathInfoRequest {
+            by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
         }))
         .await;
 
-    match resp {
-        Err(status) => {
-            assert_eq!(status.code(), tonic::Code::NotFound);
-        }
-        Ok(_) => panic!("must fail"),
-    };
+    let resp = resp.expect_err("must fail");
+    assert_eq!(resp.code(), tonic::Code::NotFound);
 
     Ok(())
 }
@@ -43,27 +40,23 @@ async fn put_get() -> anyhow::Result<()> {
     let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
 
     let path_info = PathInfo {
-        node: Some(crate::proto::Node {
-            node: Some(crate::proto::node::Node::Symlink(
-                crate::proto::SymlinkNode {
-                    name: "00000000000000000000000000000000-foo".to_string(),
-                    target: "doesntmatter".to_string(),
-                },
-            )),
+        node: Some(Node {
+            node: Some(Symlink(SymlinkNode {
+                name: "00000000000000000000000000000000-foo".to_string(),
+                target: "doesntmatter".to_string(),
+            })),
         }),
         ..Default::default()
     };
 
-    let resp = service.put(tonic::Request::new(path_info.clone())).await;
+    let resp = service.put(Request::new(path_info.clone())).await;
 
     assert!(resp.is_ok());
     assert_eq!(resp.expect("must succeed").into_inner(), path_info);
 
     let resp = service
-        .get(tonic::Request::new(GetPathInfoRequest {
-            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
-                DUMMY_OUTPUT_HASH.to_vec(),
-            )),
+        .get(Request::new(GetPathInfoRequest {
+            by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
         }))
         .await;