refactor(tvix/store): simplify test a bit
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>
This commit is contained in:
		
							parent
							
								
									e20c0d2fbf
								
							
						
					
					
						commit
						a8b13a0b57
					
				
					 1 changed files with 17 additions and 24 deletions
				
			
		| 
						 | 
					@ -1,8 +1,11 @@
 | 
				
			||||||
use tempfile::TempDir;
 | 
					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::path_info_service_server::PathInfoService;
 | 
				
			||||||
use crate::proto::GetPathInfoRequest;
 | 
					use crate::proto::PathInfo;
 | 
				
			||||||
use crate::proto::{get_path_info_request, PathInfo};
 | 
					use crate::proto::{GetPathInfoRequest, Node, SymlinkNode};
 | 
				
			||||||
use crate::sled_path_info_service::SledPathInfoService;
 | 
					use crate::sled_path_info_service::SledPathInfoService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use lazy_static::lazy_static;
 | 
					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 service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let resp = service
 | 
					    let resp = service
 | 
				
			||||||
        .get(tonic::Request::new(GetPathInfoRequest {
 | 
					        .get(Request::new(GetPathInfoRequest {
 | 
				
			||||||
            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
 | 
					            by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
 | 
				
			||||||
                DUMMY_OUTPUT_HASH.to_vec(),
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
        }))
 | 
					        }))
 | 
				
			||||||
        .await;
 | 
					        .await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match resp {
 | 
					    let resp = resp.expect_err("must fail");
 | 
				
			||||||
        Err(status) => {
 | 
					    assert_eq!(resp.code(), tonic::Code::NotFound);
 | 
				
			||||||
            assert_eq!(status.code(), tonic::Code::NotFound);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        Ok(_) => panic!("must fail"),
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -43,27 +40,23 @@ async fn put_get() -> anyhow::Result<()> {
 | 
				
			||||||
    let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
 | 
					    let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let path_info = PathInfo {
 | 
					    let path_info = PathInfo {
 | 
				
			||||||
        node: Some(crate::proto::Node {
 | 
					        node: Some(Node {
 | 
				
			||||||
            node: Some(crate::proto::node::Node::Symlink(
 | 
					            node: Some(Symlink(SymlinkNode {
 | 
				
			||||||
                crate::proto::SymlinkNode {
 | 
					 | 
				
			||||||
                name: "00000000000000000000000000000000-foo".to_string(),
 | 
					                name: "00000000000000000000000000000000-foo".to_string(),
 | 
				
			||||||
                target: "doesntmatter".to_string(),
 | 
					                target: "doesntmatter".to_string(),
 | 
				
			||||||
                },
 | 
					            })),
 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
        }),
 | 
					        }),
 | 
				
			||||||
        ..Default::default()
 | 
					        ..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!(resp.is_ok());
 | 
				
			||||||
    assert_eq!(resp.expect("must succeed").into_inner(), path_info);
 | 
					    assert_eq!(resp.expect("must succeed").into_inner(), path_info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let resp = service
 | 
					    let resp = service
 | 
				
			||||||
        .get(tonic::Request::new(GetPathInfoRequest {
 | 
					        .get(Request::new(GetPathInfoRequest {
 | 
				
			||||||
            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
 | 
					            by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
 | 
				
			||||||
                DUMMY_OUTPUT_HASH.to_vec(),
 | 
					 | 
				
			||||||
            )),
 | 
					 | 
				
			||||||
        }))
 | 
					        }))
 | 
				
			||||||
        .await;
 | 
					        .await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue