Use FakeFs in all integration tests

This commit is contained in:
Max Brunsfeld 2021-07-13 12:48:00 -07:00
parent 82569a031f
commit 561cabbba2
2 changed files with 30 additions and 19 deletions

View file

@ -18,8 +18,8 @@ use zed::{
language::LanguageRegistry, language::LanguageRegistry,
rpc::Client, rpc::Client,
settings, settings,
test::{temp_tree, Channel}, test::Channel,
worktree::{FakeFs, Fs, RealFs, Worktree}, worktree::{FakeFs, Fs as _, Worktree},
}; };
use zrpc::{ForegroundRouter, Peer, Router}; use zrpc::{ForegroundRouter, Peer, Router};
@ -35,14 +35,19 @@ async fn test_share_worktree(mut cx_a: TestAppContext, mut cx_b: TestAppContext)
let client_b = server.create_client(&mut cx_b, "user_b").await; let client_b = server.create_client(&mut cx_b, "user_b").await;
// Share a local worktree as client A // Share a local worktree as client A
let dir = temp_tree(json!({ let fs = Arc::new(FakeFs::new());
"a.txt": "a-contents", fs.insert_tree(
"b.txt": "b-contents", "/a",
})); json!({
"a.txt": "a-contents",
"b.txt": "b-contents",
}),
)
.await;
let worktree_a = Worktree::open_local( let worktree_a = Worktree::open_local(
dir.path(), "/a".as_ref(),
lang_registry.clone(), lang_registry.clone(),
Arc::new(RealFs), fs,
&mut cx_a.to_async(), &mut cx_a.to_async(),
) )
.await .await
@ -148,7 +153,7 @@ async fn test_propagate_saves_and_fs_changes_in_shared_worktree(
.await; .await;
let worktree_a = Worktree::open_local( let worktree_a = Worktree::open_local(
Path::new("/a"), "/a".as_ref(),
lang_registry.clone(), lang_registry.clone(),
fs.clone(), fs.clone(),
&mut cx_a.to_async(), &mut cx_a.to_async(),
@ -226,7 +231,7 @@ async fn test_propagate_saves_and_fs_changes_in_shared_worktree(
buffer_a.update(&mut cx_a, |buf, cx| buf.edit([0..0], "hi-a, ", cx)); buffer_a.update(&mut cx_a, |buf, cx| buf.edit([0..0], "hi-a, ", cx));
save_b.await.unwrap(); save_b.await.unwrap();
assert_eq!( assert_eq!(
fs.load(Path::new("/a/file1")).await.unwrap(), fs.load("/a/file1".as_ref()).await.unwrap(),
"hi-a, i-am-c, i-am-b, i-am-a" "hi-a, i-am-c, i-am-b, i-am-a"
); );
buffer_a.read_with(&cx_a, |buf, _| assert!(!buf.is_dirty())); buffer_a.read_with(&cx_a, |buf, _| assert!(!buf.is_dirty()));
@ -234,7 +239,7 @@ async fn test_propagate_saves_and_fs_changes_in_shared_worktree(
buffer_c.condition(&cx_c, |buf, _| !buf.is_dirty()).await; buffer_c.condition(&cx_c, |buf, _| !buf.is_dirty()).await;
// Make changes on host's file system, see those changes on the guests. // Make changes on host's file system, see those changes on the guests.
fs.rename(Path::new("/a/file2"), Path::new("/a/file3")) fs.rename("/a/file2".as_ref(), "/a/file3".as_ref())
.await .await
.unwrap(); .unwrap();
fs.insert_file(Path::new("/a/file4"), "4".into()) fs.insert_file(Path::new("/a/file4"), "4".into())
@ -282,7 +287,7 @@ async fn test_buffer_conflict_after_save(mut cx_a: TestAppContext, mut cx_b: Tes
let worktree_a = Worktree::open_local( let worktree_a = Worktree::open_local(
"/".as_ref(), "/".as_ref(),
lang_registry.clone(), lang_registry.clone(),
Arc::new(RealFs), fs,
&mut cx_a.to_async(), &mut cx_a.to_async(),
) )
.await .await
@ -359,7 +364,7 @@ async fn test_editing_while_guest_opens_buffer(mut cx_a: TestAppContext, mut cx_
let worktree_a = Worktree::open_local( let worktree_a = Worktree::open_local(
"/".as_ref(), "/".as_ref(),
lang_registry.clone(), lang_registry.clone(),
Arc::new(RealFs), fs,
&mut cx_a.to_async(), &mut cx_a.to_async(),
) )
.await .await
@ -411,14 +416,19 @@ async fn test_peer_disconnection(mut cx_a: TestAppContext, cx_b: TestAppContext)
let client_b = server.create_client(&mut cx_a, "user_b").await; let client_b = server.create_client(&mut cx_a, "user_b").await;
// Share a local worktree as client A // Share a local worktree as client A
let dir = temp_tree(json!({ let fs = Arc::new(FakeFs::new());
"a.txt": "a-contents", fs.insert_tree(
"b.txt": "b-contents", "/a",
})); json!({
"a.txt": "a-contents",
"b.txt": "b-contents",
}),
)
.await;
let worktree_a = Worktree::open_local( let worktree_a = Worktree::open_local(
dir.path(), "/a".as_ref(),
lang_registry.clone(), lang_registry.clone(),
Arc::new(RealFs), fs,
&mut cx_a.to_async(), &mut cx_a.to_async(),
) )
.await .await

View file

@ -290,6 +290,7 @@ impl FakeFs {
Ok(()) Ok(())
} }
#[must_use]
pub fn insert_tree<'a>( pub fn insert_tree<'a>(
&'a self, &'a self,
path: impl 'a + AsRef<Path> + Send, path: impl 'a + AsRef<Path> + Send,