From 9aef3cfc8989c491db05c4d66cdbf3d89429420e Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 13 Nov 2023 11:45:22 +0200 Subject: refactor(tvix/store/pathinfosvc): inline MemoryPathInfoSvc::from_url Change-Id: If27eb518d372f4004b7b38fc765a42957f2a6b50 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10023 Tested-by: BuildkiteCI Reviewed-by: Connor Brewster --- tvix/store/src/pathinfoservice/memory.rs | 83 -------------------------------- 1 file changed, 83 deletions(-) (limited to 'tvix/store/src/pathinfoservice/memory.rs') diff --git a/tvix/store/src/pathinfoservice/memory.rs b/tvix/store/src/pathinfoservice/memory.rs index 90a151fd04e5..6f96c083476c 100644 --- a/tvix/store/src/pathinfoservice/memory.rs +++ b/tvix/store/src/pathinfoservice/memory.rs @@ -29,26 +29,6 @@ impl MemoryPathInfoService { directory_service, } } - - /// Constructs a [MemoryPathInfoService] from the passed [url::Url]: - /// - scheme has to be `memory://` - /// - there may not be a host. - /// - there may not be a path. - pub fn from_url( - url: &url::Url, - blob_service: Arc, - directory_service: Arc, - ) -> Result { - if url.scheme() != "memory" { - return Err(Error::StorageError("invalid scheme".to_string())); - } - - if url.has_host() || !url.path().is_empty() { - return Err(Error::StorageError("invalid url".to_string())); - } - - Ok(Self::new(blob_service, directory_service)) - } } #[async_trait] @@ -106,66 +86,3 @@ impl PathInfoService for MemoryPathInfoService { Box::pin(iter(items)) } } - -#[cfg(test)] -mod tests { - use crate::tests::utils::gen_blob_service; - use crate::tests::utils::gen_directory_service; - - use super::MemoryPathInfoService; - - /// This uses a wrong scheme. - #[test] - fn test_invalid_scheme() { - let url = url::Url::parse("http://foo.example/test").expect("must parse"); - - assert!( - MemoryPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service()) - .is_err() - ); - } - - /// This correctly sets the scheme, and doesn't set a path. - #[test] - fn test_valid_scheme() { - let url = url::Url::parse("memory://").expect("must parse"); - - assert!( - MemoryPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service()) - .is_ok() - ); - } - - /// This sets the host to `foo` - #[test] - fn test_invalid_host() { - let url = url::Url::parse("memory://foo").expect("must parse"); - - assert!( - MemoryPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service()) - .is_err() - ); - } - - /// This has the path "/", which is invalid. - #[test] - fn test_invalid_has_path() { - let url = url::Url::parse("memory:///").expect("must parse"); - - assert!( - MemoryPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service()) - .is_err() - ); - } - - /// This has the path "/foo", which is invalid. - #[test] - fn test_invalid_path2() { - let url = url::Url::parse("memory:///foo").expect("must parse"); - - assert!( - MemoryPathInfoService::from_url(&url, gen_blob_service(), gen_directory_service()) - .is_err() - ); - } -} -- cgit 1.4.1