Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaarf committed Nov 5, 2024
1 parent fb6e1cd commit e25b82a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/ffi/js/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Workspace {
})?;
self.callback(move |controller: Workspace| {
tsfn.call(controller.clone(), ThreadsafeFunctionCallMode::Blocking); //check this with tracing also we could use Ok(event) to get the error
// If it blocks the main thread too many time we have to change this
// If it blocks the main thread too many time we have to change this
});

Ok(())
Expand Down
54 changes: 33 additions & 21 deletions src/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,28 @@ async fn test_attach_and_leave_workspace() {

#[tokio::test]
async fn test_invite_user_to_workspace() {
let client_alice = ClientFixture::of("alice").setup().await.expect("failed setting up alice's client");
let client_bob = ClientFixture::of("bob").setup().await.expect("failed setting up bob's client");
let client_alice = ClientFixture::of("alice")
.setup()
.await
.expect("failed setting up alice's client");
let client_bob = ClientFixture::of("bob")
.setup()
.await
.expect("failed setting up bob's client");
let ws_name = uuid::Uuid::new_v4().to_string();

// after this we can't just fail anymore: we need to cleanup, so store errs
client_alice.create_workspace(&ws_name).await.expect("failed creating workspace");
let could_invite = client_alice.invite_to_workspace(&ws_name, &client_bob.current_user().name).await;
let ws_list = client_bob.fetch_joined_workspaces().await.unwrap_or_default(); // can't fail, empty is err
client_alice
.create_workspace(&ws_name)
.await
.expect("failed creating workspace");
let could_invite = client_alice
.invite_to_workspace(&ws_name, &client_bob.current_user().name)
.await;
let ws_list = client_bob
.fetch_joined_workspaces()
.await
.unwrap_or_default(); // can't fail, empty is err
let could_delete = client_alice.delete_workspace(&ws_name).await;

could_invite.expect("could not invite bob");
Expand Down Expand Up @@ -224,22 +238,20 @@ async fn cannot_delete_others_workspaces() {
#[tokio::test]
async fn test_buffer_search() {
WorkspaceFixture::one("alice", "test-buffer-search")
.with(
|(_, workspace_alice)| {
let buffer_name = uuid::Uuid::new_v4().to_string();
let workspace_alice = workspace_alice.clone();

async move {
workspace_alice.create_buffer(&buffer_name).await?;
assert_or_err!(!workspace_alice
.search_buffers(Some(&buffer_name[0..4]))
.is_empty());
assert_or_err!(workspace_alice.search_buffers(Some("_")).is_empty());
workspace_alice.delete_buffer(&buffer_name).await?;
Ok(())
}
},
)
.with(|(_, workspace_alice)| {
let buffer_name = uuid::Uuid::new_v4().to_string();
let workspace_alice = workspace_alice.clone();

async move {
workspace_alice.create_buffer(&buffer_name).await?;
assert_or_err!(!workspace_alice
.search_buffers(Some(&buffer_name[0..4]))
.is_empty());
assert_or_err!(workspace_alice.search_buffers(Some("_")).is_empty());
workspace_alice.delete_buffer(&buffer_name).await?;
Ok(())
}
})
.await;
}

Expand Down
50 changes: 12 additions & 38 deletions src/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,21 @@ use super::{
fixtures::{ClientFixture, ScopedFixture, WorkspaceFixture},
};

// Moved this in client for now.
// #[tokio::test]
// async fn cannot_delete_others_workspaces() {
// WorkspaceFixture::two("alice", "bob", "test-cannot-delete-others-workspaces")
// .with(|((_, ws_alice), (client_bob, _))| {
// let ws_alice = ws_alice.clone();
// let client_bob = client_bob.clone();
// async move {
// assert_or_err!(
// client_bob.delete_workspace(&ws_alice.id()).await.is_err(),
// "bob was allowed to delete a workspace he didn't own!"
// );
// Ok(())
// }

// })
// .await
// }

#[tokio::test]
async fn test_buffer_create() {
WorkspaceFixture::one("alice", "test-buffer-create")
.with(
|(_, workspace_alice)| {
let buffer_name = uuid::Uuid::new_v4().to_string();
let workspace_alice = workspace_alice.clone();
.with(|(_, workspace_alice)| {
let buffer_name = uuid::Uuid::new_v4().to_string();
let workspace_alice = workspace_alice.clone();

async move {
workspace_alice.create_buffer(&buffer_name).await?;
assert_or_err!(
vec![buffer_name.clone()] == workspace_alice.fetch_buffers().await?
);
workspace_alice.delete_buffer(&buffer_name).await?;
async move {
workspace_alice.create_buffer(&buffer_name).await?;
assert_or_err!(vec![buffer_name.clone()] == workspace_alice.fetch_buffers().await?);
workspace_alice.delete_buffer(&buffer_name).await?;

Ok(())
}
},
)
Ok(())
}
})
.await;
}

Expand All @@ -62,7 +39,7 @@ async fn test_cant_create_buffer_twice() {
}

#[tokio::test]
#[ignore] // TODO server has no concept of buffer ownership!
#[ignore] // TODO reference server has no concept of buffer ownership yet!
async fn cannot_delete_others_buffers() {
WorkspaceFixture::two("alice", "bob", "test-cannot-delete-others-buffers")
.with(|(_, workspace_alice, _, workspace_bob)| {
Expand All @@ -84,10 +61,7 @@ async fn test_workspace_interactions() {
if let Err(e) = async {
let client_alice = ClientFixture::of("alice").setup().await?;
let client_bob = ClientFixture::of("bob").setup().await?;
let workspace_name = format!(
"test-workspace-interactions-{}",
uuid::Uuid::new_v4()
);
let workspace_name = format!("test-workspace-interactions-{}", uuid::Uuid::new_v4());

client_alice.create_workspace(&workspace_name).await?;
let owned_workspaces = client_alice.fetch_owned_workspaces().await?;
Expand Down

0 comments on commit e25b82a

Please sign in to comment.