From 2a035f6fc715746d022c641ad94571b29c9ce7da Mon Sep 17 00:00:00 2001 From: Lukas Piatkowski Date: Fri, 8 Sep 2017 10:22:38 -0700 Subject: [PATCH] mercurial-types: add mocks for types in manifest.rs Reviewed By: jsgf Differential Revision: D5775718 fbshipit-source-id: 243eae8f82505d1c4b374ca13029065646605e36 --- mercurial-types/mocks/lib.rs | 12 ++++ mercurial-types/mocks/manifest.rs | 103 ++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 mercurial-types/mocks/lib.rs create mode 100644 mercurial-types/mocks/manifest.rs diff --git a/mercurial-types/mocks/lib.rs b/mercurial-types/mocks/lib.rs new file mode 100644 index 0000000000..6a4a5a15c2 --- /dev/null +++ b/mercurial-types/mocks/lib.rs @@ -0,0 +1,12 @@ +// Copyright (c) 2004-present, Facebook, Inc. +// All Rights Reserved. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +#![deny(warnings)] + +extern crate futures; +extern crate mercurial_types; + +pub mod manifest; diff --git a/mercurial-types/mocks/manifest.rs b/mercurial-types/mocks/manifest.rs new file mode 100644 index 0000000000..e56ea3b3e3 --- /dev/null +++ b/mercurial-types/mocks/manifest.rs @@ -0,0 +1,103 @@ +// Copyright (c) 2004-present, Facebook, Inc. +// All Rights Reserved. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +use std::marker::PhantomData; + +use futures::Stream; +use futures::future::BoxFuture; +use futures::stream; +use futures::stream::BoxStream; + +use mercurial_types::{Blob, Entry, Manifest, Path, Type}; +use mercurial_types::blobnode::Parents; +use mercurial_types::manifest::Content as MContent; +use mercurial_types::nodehash::NodeHash; + +pub struct MockManifest { + entries: Vec>, +} + +impl MockManifest { + pub fn new(paths: Vec<&'static str>) -> Self { + let entries = paths + .into_iter() + .map(|p| { + MockEntry::new(Path::new(p).expect(&format!("invalid path {}", p))) + }) + .collect(); + MockManifest { entries } + } +} + +impl Manifest for MockManifest +where + E: Send + 'static + ::std::error::Error, +{ + type Error = E; + + fn lookup( + &self, + _path: &Path, + ) -> BoxFuture + Sync>>, Self::Error> { + unimplemented!(); + } + fn list(&self) -> BoxStream + Sync>, Self::Error> { + stream::iter(self.entries.clone().into_iter().map(|e| Ok(e.boxed()))).boxed() + } +} + +struct MockEntry { + path: Path, + phantom: PhantomData, +} + +unsafe impl Sync for MockEntry {} + +impl Clone for MockEntry { + fn clone(&self) -> Self { + MockEntry { + path: self.path.clone(), + phantom: PhantomData, + } + } +} + +impl MockEntry { + fn new(path: Path) -> Self { + MockEntry { + path: path, + phantom: PhantomData, + } + } +} + +impl Entry for MockEntry +where + E: Send + 'static + ::std::error::Error, +{ + type Error = E; + fn get_type(&self) -> Type { + unimplemented!(); + } + fn get_parents(&self) -> BoxFuture { + unimplemented!(); + } + fn get_raw_content(&self) -> BoxFuture>, Self::Error> { + unimplemented!(); + } + fn get_content(&self) -> BoxFuture, Self::Error> { + unimplemented!(); + } + fn get_size(&self) -> BoxFuture, Self::Error> { + unimplemented!(); + } + fn get_hash(&self) -> &NodeHash { + unimplemented!(); + } + fn get_path(&self) -> &Path { + &self.path + } +}