mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-24 08:04:48 +01:00
test: split lookup and create/delete tests
This commit is contained in:
parent
2155f0d36c
commit
59f9096fb6
1 changed files with 37 additions and 16 deletions
|
@ -5,28 +5,24 @@ use super::{
|
||||||
use crate::api::{AsyncReceiver, AsyncSender};
|
use crate::api::{AsyncReceiver, AsyncSender};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_workspace_creation_and_lookup() {
|
async fn test_workspace_creation_and_deletion() {
|
||||||
super::fixture! {
|
super::fixture! {
|
||||||
ClientFixture::of("alice") => |client| {
|
ClientFixture::of("alice") => |client| {
|
||||||
let workspace_name = uuid::Uuid::new_v4().to_string();
|
let workspace_name = uuid::Uuid::new_v4().to_string();
|
||||||
let wrong_name = uuid::Uuid::new_v4().to_string();
|
|
||||||
|
|
||||||
client.create_workspace(&workspace_name).await?;
|
client.create_workspace(&workspace_name).await?;
|
||||||
let wslist = client.fetch_owned_workspaces().await.unwrap_or_default();
|
|
||||||
let ws = client.get_workspace(&workspace_name);
|
// we can't error, so we return empty vec which will be interpreted as err
|
||||||
let ws_exists = ws.is_some();
|
let workspace_list_before = client.fetch_owned_workspaces().await.unwrap_or_default();
|
||||||
let ws_name_matches = ws.map_or(false, |x| x.id() == workspace_name);
|
|
||||||
let ws_wrong_name_doesnt_exist = client.get_workspace(&wrong_name).is_none();
|
|
||||||
|
|
||||||
let res = client.delete_workspace(&workspace_name).await;
|
let res = client.delete_workspace(&workspace_name).await;
|
||||||
|
|
||||||
assert_or_err!(ws_exists);
|
// we can and should err here, because empty vec will be counted as success!
|
||||||
assert_or_err!(ws_name_matches);
|
let workspace_list_after = client.fetch_owned_workspaces().await?;
|
||||||
assert_or_err!(ws_wrong_name_doesnt_exist);
|
|
||||||
assert_or_err!(res.is_ok());
|
assert_or_err!(workspace_list_before.contains(&workspace_name));
|
||||||
assert_or_err!(client.get_workspace(&workspace_name).is_none());
|
assert_or_err!(res.is_ok(), "failed deleting workspace");
|
||||||
assert_or_err!(wslist.len() == 1);
|
assert_or_err!(workspace_list_after.contains(&workspace_name) == false);
|
||||||
assert_or_err!(wslist.contains(&workspace_name));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -67,6 +63,17 @@ async fn test_attach_and_leave_workspace() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_workspace_lookup() {
|
||||||
|
super::fixture! {
|
||||||
|
WorkspaceFixture::one("alice", "test-lookup") => |client, workspace| {
|
||||||
|
assert_or_err!(client.get_workspace(&workspace.id()).is_some());
|
||||||
|
assert_or_err!(client.get_workspace(&uuid::Uuid::new_v4().to_string()).is_none());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_leave_workspace_with_dangling_ref() {
|
async fn test_leave_workspace_with_dangling_ref() {
|
||||||
super::fixture! {
|
super::fixture! {
|
||||||
|
@ -77,11 +84,25 @@ async fn test_leave_workspace_with_dangling_ref() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_lookup_after_leave() {
|
||||||
|
super::fixture! {
|
||||||
|
WorkspaceFixture::one("alice", "test-lookup-after-leave") => |client, workspace| {
|
||||||
|
client.leave_workspace(&workspace.id());
|
||||||
|
assert_or_err!(client.get_workspace(&workspace.id()).is_none());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_attach_after_leave() {
|
async fn test_attach_after_leave() {
|
||||||
super::fixture! {
|
super::fixture! {
|
||||||
WorkspaceFixture::one("alice", "test-dangling-ref") => |client, workspace| {
|
WorkspaceFixture::one("alice", "test-attach-after-leave") => |client, workspace| {
|
||||||
client.leave_workspace(&workspace.id());
|
client.leave_workspace(&workspace.id());
|
||||||
|
// TODO this is very server specific! disconnect may be instant or caught with next
|
||||||
|
// keepalive, let's arbitrarily say that after 20 seconds we should have been disconnected
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(20)).await;
|
||||||
assert_or_err!(client.attach_workspace(&workspace.id()).await.is_ok());
|
assert_or_err!(client.attach_workspace(&workspace.id()).await.is_ok());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -137,7 +158,7 @@ async fn test_deleting_workspace_twice_is_an_error() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_invite_user_to_workspace_and_invited_lookup() {
|
async fn test_invite_user_to_workspace_and_invited_lookup() {
|
||||||
WorkspaceFixture::one("bob", "workspace-di-bob")
|
WorkspaceFixture::one("alice", "test-invite")
|
||||||
.with(
|
.with(
|
||||||
|(client_bob, workspace_bob)| {
|
|(client_bob, workspace_bob)| {
|
||||||
let client_bob = client_bob.clone();
|
let client_bob = client_bob.clone();
|
||||||
|
|
Loading…
Reference in a new issue