fmt: formatter shenanigans

This commit is contained in:
cschen 2024-11-03 17:18:47 +01:00
parent 7a535d4492
commit dc627dc6af
2 changed files with 92 additions and 40 deletions

View file

@ -124,8 +124,21 @@ impl ScopedFixture<(crate::Client, crate::Workspace)> for WorkspaceFixture {
} }
} }
impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace))> for WorkspaceFixture { impl
async fn setup(&mut self) -> Result<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace)), Box<dyn Error>> { 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 client = ClientFixture::of(&self.user).setup().await?;
let invitee_client = ClientFixture::of( let invitee_client = ClientFixture::of(
&self &self
@ -144,7 +157,13 @@ impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Wo
Ok(((client, workspace), (invitee_client, invitee_workspace))) 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 { if let Some(((client, _), (_, _))) = resource {
client.leave_workspace(&self.workspace); client.leave_workspace(&self.workspace);
if let Err(e) = client.delete_workspace(&self.workspace).await { if let Err(e) = client.delete_workspace(&self.workspace).await {
@ -158,7 +177,7 @@ pub struct BufferFixture {
user: String, user: String,
invitee: Option<String>, invitee: Option<String>,
workspace: String, workspace: String,
buffer: String buffer: String,
} }
impl BufferFixture { impl BufferFixture {
@ -167,7 +186,7 @@ impl BufferFixture {
user: user.to_string(), user: user.to_string(),
invitee: Some(invitee.to_string()), invitee: Some(invitee.to_string()),
workspace: workspace.to_string(), workspace: workspace.to_string(),
buffer: buffer.to_string() buffer: buffer.to_string(),
} }
} }
@ -176,7 +195,7 @@ impl BufferFixture {
user: user.to_string(), user: user.to_string(),
invitee: None, invitee: None,
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()), 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(), user: user.to_string(),
invitee: Some(invite.to_string()), invitee: Some(invite.to_string()),
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()), 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 { impl
async fn setup(&mut self) -> Result<((crate::Client, crate::Workspace, crate::buffer::Controller), (crate::Client, crate::Workspace, crate::buffer::Controller)), Box<dyn Error>> { 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 client = ClientFixture::of(&self.user).setup().await?;
let invitee_client = ClientFixture::of( let invitee_client = ClientFixture::of(
&self &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_workspace = invitee_client.attach_workspace(&self.workspace).await?;
let invitee_buffer = invitee_workspace.attach_buffer(&self.buffer).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 { if let Some(((client, _, _), (_, _, _))) = resource {
// buffer deletion is implied in workspace deletion // buffer deletion is implied in workspace deletion
client.leave_workspace(&self.workspace); client.leave_workspace(&self.workspace);

View file

@ -1,38 +1,46 @@
use super::{assert_or_err, fixtures::{ClientFixture, ScopedFixture, WorkspaceFixture}}; use super::{
assert_or_err,
fixtures::{ClientFixture, ScopedFixture, WorkspaceFixture},
};
#[tokio::test] // Moved this in client for now.
async fn cannot_delete_others_workspaces() { // #[tokio::test]
WorkspaceFixture::two("alice", "bob", "test-cannot-delete-others-workspaces") // async fn cannot_delete_others_workspaces() {
.with(|((_, ws_alice), (client_bob, _))| { // WorkspaceFixture::two("alice", "bob", "test-cannot-delete-others-workspaces")
let ws_alice = ws_alice.clone(); // .with(|((_, ws_alice), (client_bob, _))| {
let client_bob = client_bob.clone(); // let ws_alice = ws_alice.clone();
async move { // let client_bob = client_bob.clone();
assert_or_err!( // async move {
client_bob.delete_workspace(&ws_alice.id()).await.is_err(), // assert_or_err!(
"bob was allowed to delete a workspace he didn't own!" // client_bob.delete_workspace(&ws_alice.id()).await.is_err(),
); // "bob was allowed to delete a workspace he didn't own!"
Ok(()) // );
} // Ok(())
// }
}) // })
.await // .await
} // }
#[tokio::test] #[tokio::test]
async fn test_buffer_create() { async fn test_buffer_create() {
WorkspaceFixture::one("alice", "test-buffer-create") WorkspaceFixture::one("alice", "test-buffer-create")
.with(|(_, workspace_alice): &mut (crate::Client, crate::Workspace)| { .with(
let buffer_name = uuid::Uuid::new_v4().to_string(); |(_, workspace_alice): &mut (crate::Client, crate::Workspace)| {
let workspace_alice = workspace_alice.clone(); let buffer_name = uuid::Uuid::new_v4().to_string();
let workspace_alice = workspace_alice.clone();
async move { async move {
workspace_alice.create_buffer(&buffer_name).await?; workspace_alice.create_buffer(&buffer_name).await?;
assert_or_err!(vec![buffer_name.clone()] == workspace_alice.fetch_buffers().await?); assert_or_err!(
workspace_alice.delete_buffer(&buffer_name).await?; vec![buffer_name.clone()] == workspace_alice.fetch_buffers().await?
);
workspace_alice.delete_buffer(&buffer_name).await?;
Ok(()) Ok(())
} }
}) },
)
.await; .await;
} }
@ -76,7 +84,10 @@ async fn test_workspace_interactions() {
if let Err(e) = async { if let Err(e) = async {
let client_alice = ClientFixture::of("alice").setup().await?; let client_alice = ClientFixture::of("alice").setup().await?;
let client_bob = ClientFixture::of("bob").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?; client_alice.create_workspace(&workspace_name).await?;
let owned_workspaces = client_alice.fetch_owned_workspaces().await?; let owned_workspaces = client_alice.fetch_owned_workspaces().await?;