mononoke-types-mocks: fix make_file to set the right content type

Summary: Found while writing a test against this.

Reviewed By: StanislavGlebik

Differential Revision: D7555159

fbshipit-source-id: c6f279f41974e08ab690befcc84718c2bb22ddc0
This commit is contained in:
Siddharth Agarwal 2018-04-10 11:57:16 -07:00 committed by Facebook Github Bot
parent 57671d0907
commit e25f690275
2 changed files with 13 additions and 3 deletions

View File

@ -24,9 +24,9 @@ use errors::*;
pub type ContentFactory = Arc<Fn() -> Content + Send + Sync>; pub type ContentFactory = Arc<Fn() -> Content + Send + Sync>;
pub fn make_file<C: Into<Bytes>>(content: C) -> ContentFactory { pub fn make_file<C: Into<Bytes>>(file_type: FileType, content: C) -> ContentFactory {
let content = content.into(); let content = content.into();
Arc::new(move || Content::File(Blob::Dirty(content.clone()))) Arc::new(move || Content::new_file(file_type, Blob::Dirty(content.clone())))
} }
#[derive(Clone)] #[derive(Clone)]
@ -89,7 +89,7 @@ impl MockManifest {
let basename = path.basename().clone(); let basename = path.basename().clone();
let cf = make_file(content); let cf = make_file(file_type, content);
let mut entry = MockEntry::new(RepoPath::FilePath(path), cf); let mut entry = MockEntry::new(RepoPath::FilePath(path), cf);
entry.set_type(Type::File(file_type)); entry.set_type(Type::File(file_type));
wip.last_mut() wip.last_mut()

View File

@ -153,6 +153,16 @@ pub enum Content {
Tree(Box<Manifest + Sync>), Tree(Box<Manifest + Sync>),
} }
impl Content {
pub fn new_file(file_type: FileType, blob: Blob) -> Self {
match file_type {
FileType::Regular => Content::File(blob),
FileType::Executable => Content::Executable(blob),
FileType::Symlink => Content::Symlink(blob),
}
}
}
/// An entry represents a single entry in a Manifest /// An entry represents a single entry in a Manifest
/// ///
/// The Entry has at least a name, a type, and the identity of the object it refers to /// The Entry has at least a name, a type, and the identity of the object it refers to