mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +01:00
test: buffer fixture
Some checks are pending
test / test-beta (beta) (push) Blocked by required conditions
test / test-beta (nightly) (push) Blocked by required conditions
test / test-unit (push) Waiting to run
test / test-functional (push) Blocked by required conditions
test / test-build (java, macos-latest) (push) Blocked by required conditions
test / test-build (java, ubuntu-latest) (push) Blocked by required conditions
test / test-build (java, windows-latest) (push) Blocked by required conditions
test / test-build (js, macos-latest) (push) Blocked by required conditions
test / test-build (js, ubuntu-latest) (push) Blocked by required conditions
test / test-build (js, windows-latest) (push) Blocked by required conditions
test / test-build (luajit, macos-latest) (push) Blocked by required conditions
test / test-build (luajit, ubuntu-latest) (push) Blocked by required conditions
test / test-build (luajit, windows-latest) (push) Blocked by required conditions
test / test-build (py, macos-latest) (push) Blocked by required conditions
test / test-build (py, ubuntu-latest) (push) Blocked by required conditions
test / test-build (py, windows-latest) (push) Blocked by required conditions
Some checks are pending
test / test-beta (beta) (push) Blocked by required conditions
test / test-beta (nightly) (push) Blocked by required conditions
test / test-unit (push) Waiting to run
test / test-functional (push) Blocked by required conditions
test / test-build (java, macos-latest) (push) Blocked by required conditions
test / test-build (java, ubuntu-latest) (push) Blocked by required conditions
test / test-build (java, windows-latest) (push) Blocked by required conditions
test / test-build (js, macos-latest) (push) Blocked by required conditions
test / test-build (js, ubuntu-latest) (push) Blocked by required conditions
test / test-build (js, windows-latest) (push) Blocked by required conditions
test / test-build (luajit, macos-latest) (push) Blocked by required conditions
test / test-build (luajit, ubuntu-latest) (push) Blocked by required conditions
test / test-build (luajit, windows-latest) (push) Blocked by required conditions
test / test-build (py, macos-latest) (push) Blocked by required conditions
test / test-build (py, ubuntu-latest) (push) Blocked by required conditions
test / test-build (py, windows-latest) (push) Blocked by required conditions
This commit is contained in:
parent
cd4e09c1cd
commit
111020afd8
1 changed files with 86 additions and 13 deletions
|
@ -1,7 +1,5 @@
|
|||
use std::{error::Error, future::Future};
|
||||
|
||||
// TODO create a BufferFixture too
|
||||
|
||||
#[allow(async_fn_in_trait)]
|
||||
pub trait ScopedFixture<T: Sized> {
|
||||
async fn setup(&mut self) -> Result<T, Box<dyn Error>>;
|
||||
|
@ -44,6 +42,7 @@ pub struct ClientFixture {
|
|||
username: Option<String>,
|
||||
password: Option<String>,
|
||||
}
|
||||
|
||||
impl ClientFixture {
|
||||
pub fn of(name: &str) -> Self {
|
||||
Self {
|
||||
|
@ -77,14 +76,15 @@ impl ScopedFixture<crate::Client> for ClientFixture {
|
|||
|
||||
pub struct WorkspaceFixture {
|
||||
user: String,
|
||||
invite: Option<String>,
|
||||
invitee: Option<String>,
|
||||
workspace: String,
|
||||
}
|
||||
|
||||
impl WorkspaceFixture {
|
||||
pub fn of(user: &str, invite: &str, workspace: &str) -> Self {
|
||||
pub fn of(user: &str, invitee: &str, workspace: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invite: Some(invite.to_string()),
|
||||
invitee: Some(invitee.to_string()),
|
||||
workspace: workspace.to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ impl WorkspaceFixture {
|
|||
pub fn one(user: &str, ws: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invite: None,
|
||||
invitee: None,
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ impl WorkspaceFixture {
|
|||
pub fn two(user: &str, invite: &str, ws: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invite: Some(invite.to_string()),
|
||||
invitee: Some(invite.to_string()),
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ 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>> {
|
||||
let client = ClientFixture::of(&self.user).setup().await?;
|
||||
let invite_client = ClientFixture::of(
|
||||
let invitee_client = ClientFixture::of(
|
||||
&self
|
||||
.invite
|
||||
.invitee
|
||||
.clone()
|
||||
.unwrap_or(uuid::Uuid::new_v4().to_string()),
|
||||
)
|
||||
|
@ -137,15 +137,15 @@ impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Wo
|
|||
.await?;
|
||||
client.create_workspace(&self.workspace).await?;
|
||||
client
|
||||
.invite_to_workspace(&self.workspace, invite_client.current_user().name.clone())
|
||||
.invite_to_workspace(&self.workspace, invitee_client.current_user().name.clone())
|
||||
.await?;
|
||||
let workspace = client.attach_workspace(&self.workspace).await?;
|
||||
let invite = invite_client.attach_workspace(&self.workspace).await?;
|
||||
Ok(((client, workspace), (invite_client, invite)))
|
||||
let invitee_workspace = invitee_client.attach_workspace(&self.workspace).await?;
|
||||
Ok(((client, workspace), (invitee_client, invitee_workspace)))
|
||||
}
|
||||
|
||||
async fn cleanup(&mut self, resource: Option<((crate::Client, crate::Workspace), (crate::Client, crate::Workspace))>) {
|
||||
if let Some(((client, _workspace), (_, _))) = resource {
|
||||
if let Some(((client, _), (_, _))) = resource {
|
||||
client.leave_workspace(&self.workspace);
|
||||
if let Err(e) = client.delete_workspace(&self.workspace).await {
|
||||
eprintln!("could not delete workspace: {e}");
|
||||
|
@ -153,3 +153,76 @@ impl ScopedFixture<((crate::Client, crate::Workspace), (crate::Client, crate::Wo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BufferFixture {
|
||||
user: String,
|
||||
invitee: Option<String>,
|
||||
workspace: String,
|
||||
buffer: String
|
||||
}
|
||||
|
||||
impl BufferFixture {
|
||||
pub fn of(user: &str, invitee: &str, workspace: &str, buffer: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invitee: Some(invitee.to_string()),
|
||||
workspace: workspace.to_string(),
|
||||
buffer: buffer.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn one(user: &str, ws: &str, buf: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invitee: None,
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
buffer: buf.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn two(user: &str, invite: &str, ws: &str, buf: &str) -> Self {
|
||||
Self {
|
||||
user: user.to_string(),
|
||||
invitee: Some(invite.to_string()),
|
||||
workspace: format!("{ws}-{}", uuid::Uuid::new_v4()),
|
||||
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>> {
|
||||
let client = ClientFixture::of(&self.user).setup().await?;
|
||||
let invitee_client = ClientFixture::of(
|
||||
&self
|
||||
.invitee
|
||||
.clone()
|
||||
.unwrap_or(uuid::Uuid::new_v4().to_string()),
|
||||
)
|
||||
.setup()
|
||||
.await?;
|
||||
client.create_workspace(&self.workspace).await?;
|
||||
client
|
||||
.invite_to_workspace(&self.workspace, invitee_client.current_user().name.clone())
|
||||
.await?;
|
||||
|
||||
let workspace = client.attach_workspace(&self.workspace).await?;
|
||||
workspace.create_buffer(&self.buffer).await?;
|
||||
let buffer = workspace.attach_buffer(&self.buffer).await?;
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
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);
|
||||
if let Err(e) = client.delete_workspace(&self.workspace).await {
|
||||
eprintln!("could not delete workspace: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue