2022-12-29 21:39:28 +01:00
|
|
|
use tempfile::TempDir;
|
2023-01-18 20:37:48 +01:00
|
|
|
use tonic::Request;
|
2022-12-29 21:39:28 +01:00
|
|
|
|
2023-01-18 20:37:48 +01:00
|
|
|
use crate::proto::get_path_info_request::ByWhat::ByOutputHash;
|
|
|
|
use crate::proto::node::Node::Symlink;
|
2022-12-29 21:39:28 +01:00
|
|
|
use crate::proto::path_info_service_server::PathInfoService;
|
2023-01-18 20:37:48 +01:00
|
|
|
use crate::proto::PathInfo;
|
|
|
|
use crate::proto::{GetPathInfoRequest, Node, SymlinkNode};
|
2022-12-29 21:39:28 +01:00
|
|
|
use crate::sled_path_info_service::SledPathInfoService;
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref DUMMY_OUTPUT_HASH: Vec<u8> = vec![
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Trying to get a non-existent PathInfo should return a not found error.
|
|
|
|
#[tokio::test]
|
|
|
|
async fn not_found() -> anyhow::Result<()> {
|
|
|
|
let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
|
|
|
|
|
|
|
|
let resp = service
|
2023-01-18 20:37:48 +01:00
|
|
|
.get(Request::new(GetPathInfoRequest {
|
|
|
|
by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
|
2022-12-29 21:39:28 +01:00
|
|
|
}))
|
|
|
|
.await;
|
|
|
|
|
2023-01-18 20:37:48 +01:00
|
|
|
let resp = resp.expect_err("must fail");
|
|
|
|
assert_eq!(resp.code(), tonic::Code::NotFound);
|
2022-12-29 21:39:28 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Put a PathInfo into the store, get it back.
|
|
|
|
#[tokio::test]
|
|
|
|
async fn put_get() -> anyhow::Result<()> {
|
|
|
|
let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
|
|
|
|
|
|
|
|
let path_info = PathInfo {
|
2023-01-18 20:37:48 +01:00
|
|
|
node: Some(Node {
|
|
|
|
node: Some(Symlink(SymlinkNode {
|
|
|
|
name: "00000000000000000000000000000000-foo".to_string(),
|
|
|
|
target: "doesntmatter".to_string(),
|
|
|
|
})),
|
2022-12-29 21:39:28 +01:00
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2023-01-18 20:37:48 +01:00
|
|
|
let resp = service.put(Request::new(path_info.clone())).await;
|
2022-12-29 21:39:28 +01:00
|
|
|
|
|
|
|
assert!(resp.is_ok());
|
|
|
|
assert_eq!(resp.expect("must succeed").into_inner(), path_info);
|
|
|
|
|
|
|
|
let resp = service
|
2023-01-18 20:37:48 +01:00
|
|
|
.get(Request::new(GetPathInfoRequest {
|
|
|
|
by_what: Some(ByOutputHash(DUMMY_OUTPUT_HASH.to_vec())),
|
2022-12-29 21:39:28 +01:00
|
|
|
}))
|
|
|
|
.await;
|
|
|
|
|
|
|
|
assert!(resp.is_ok());
|
|
|
|
assert_eq!(resp.expect("must succeed").into_inner(), path_info);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|