mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +01:00
fmt: formatter shenanigans
This commit is contained in:
parent
7a535d4492
commit
dc627dc6af
2 changed files with 92 additions and 40 deletions
|
@ -124,8 +124,21 @@ impl ScopedFixture<(crate::Client, crate::Workspace)> for WorkspaceFixture {
|
|||
}
|
||||
}
|
||||
|
||||
impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace))> for WorkspaceFixture {
|
||||
async fn setup(&mut self) -> Result<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace)), Box<dyn Error>> {
|
||||
impl
|
||||
ScopedFixture<(
|
||||
(crate::Client, crate::Workspace),
|
||||
(crate::Client, crate::Workspace),
|
||||
)> for WorkspaceFixture
|
||||
{
|
||||
async fn setup(
|
||||
&mut self,
|
||||
) -> Result<
|
||||
(
|
||||
(crate::Client, crate::Workspace),
|
||||
(crate::Client, crate::Workspace),
|
||||
),
|
||||
Box<dyn Error>,
|
||||
> {
|
||||
let client = ClientFixture::of(&self.user).setup().await?;
|
||||
let invitee_client = ClientFixture::of(
|
||||
&self
|
||||
|
@ -144,7 +157,13 @@ impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Wo
|
|||
Ok(((client, workspace), (invitee_client, invitee_workspace)))
|
||||
}
|
||||
|
||||
async fn cleanup(&mut self, resource: Option<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace))>) {
|
||||
async fn cleanup(
|
||||
&mut self,
|
||||
resource: Option<(
|
||||
(crate::Client, crate::Workspace),
|
||||
(crate::Client, crate::Workspace),
|
||||
)>,
|
||||
) {
|
||||
if let Some(((client, _), (_, _))) = resource {
|
||||
client.leave_workspace(&self.workspace);
|
||||
if let Err(e) = client.delete_workspace(&self.workspace).await {
|
||||
|
@ -158,7 +177,7 @@ pub struct BufferFixture {
|
|||
user: String,
|
||||
invitee: Option<String>,
|
||||
workspace: String,
|
||||
buffer: String
|
||||
buffer: String,
|
||||
}
|
||||
|
||||
impl BufferFixture {
|
||||
|
@ -167,7 +186,7 @@ impl BufferFixture {
|
|||
user: user.to_string(),
|
||||
invitee: Some(invitee.to_string()),
|
||||
workspace: workspace.to_string(),
|
||||
buffer: buffer.to_string()
|
||||
buffer: buffer.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +195,7 @@ impl BufferFixture {
|
|||
user: user.to_string(),
|
||||
invitee: None,
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
buffer: buf.to_string()
|
||||
buffer: buf.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,13 +204,26 @@ impl BufferFixture {
|
|||
user: user.to_string(),
|
||||
invitee: Some(invite.to_string()),
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
buffer: buf.to_string()
|
||||
buffer: buf.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ScopedFixture<((crate::Client, crate::Workspace, crate::buffer::Controller), (crate::Client, crate::Workspace, crate::buffer::Controller))> for BufferFixture {
|
||||
async fn setup(&mut self) -> Result<((crate::Client, crate::Workspace, crate::buffer::Controller), (crate::Client, crate::Workspace, crate::buffer::Controller)), Box<dyn Error>> {
|
||||
impl
|
||||
ScopedFixture<(
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
)> for BufferFixture
|
||||
{
|
||||
async fn setup(
|
||||
&mut self,
|
||||
) -> Result<
|
||||
(
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
),
|
||||
Box<dyn Error>,
|
||||
> {
|
||||
let client = ClientFixture::of(&self.user).setup().await?;
|
||||
let invitee_client = ClientFixture::of(
|
||||
&self
|
||||
|
@ -213,10 +245,19 @@ impl ScopedFixture<((crate::Client, crate::Workspace, crate::buffer::Controller)
|
|||
let invitee_workspace = invitee_client.attach_workspace(&self.workspace).await?;
|
||||
let invitee_buffer = invitee_workspace.attach_buffer(&self.buffer).await?;
|
||||
|
||||
Ok(((client, workspace, buffer), (invitee_client, invitee_workspace, invitee_buffer)))
|
||||
Ok((
|
||||
(client, workspace, buffer),
|
||||
(invitee_client, invitee_workspace, invitee_buffer),
|
||||
))
|
||||
}
|
||||
|
||||
async fn cleanup(&mut self, resource: Option<((crate::Client, crate::Workspace, crate::buffer::Controller), (crate::Client, crate::Workspace, crate::buffer::Controller))>) {
|
||||
async fn cleanup(
|
||||
&mut self,
|
||||
resource: Option<(
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
(crate::Client, crate::Workspace, crate::buffer::Controller),
|
||||
)>,
|
||||
) {
|
||||
if let Some(((client, _, _), (_, _, _))) = resource {
|
||||
// buffer deletion is implied in workspace deletion
|
||||
client.leave_workspace(&self.workspace);
|
||||
|
|
|
@ -1,38 +1,46 @@
|
|||
use super::{assert_or_err, fixtures::{ClientFixture, ScopedFixture, WorkspaceFixture}};
|
||||
use super::{
|
||||
assert_or_err,
|
||||
fixtures::{ClientFixture, ScopedFixture, WorkspaceFixture},
|
||||
};
|
||||
|
||||
#[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(())
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// })
|
||||
// .await
|
||||
// }
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_buffer_create() {
|
||||
WorkspaceFixture::one("alice", "test-buffer-create")
|
||||
.with(|(_, workspace_alice): &mut (crate::Client, crate::Workspace)| {
|
||||
.with(
|
||||
|(_, workspace_alice): &mut (crate::Client, crate::Workspace)| {
|
||||
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?);
|
||||
assert_or_err!(
|
||||
vec![buffer_name.clone()] == workspace_alice.fetch_buffers().await?
|
||||
);
|
||||
workspace_alice.delete_buffer(&buffer_name).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
|
@ -76,7 +84,10 @@ 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().to_string());
|
||||
let workspace_name = format!(
|
||||
"test-workspace-interactions-{}",
|
||||
uuid::Uuid::new_v4().to_string()
|
||||
);
|
||||
|
||||
client_alice.create_workspace(&workspace_name).await?;
|
||||
let owned_workspaces = client_alice.fetch_owned_workspaces().await?;
|
||||
|
|
Loading…
Reference in a new issue