diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-02-05 22:35:05 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-02-05 22:35:05 +0800 |
| commit | 27f6414ad1ff451feb0044af62f37dc2a6255ffa (patch) | |
| tree | cb5693bc014cc8579dcf02a730fd4d2a5dfcf1a5 /data/tests/src/test_virtual_file_creation_and_update.rs | |
| parent | ade2fcb9302a4ab759795820dbde3b2b269490ee (diff) | |
Remove examples and legacy code, update .gitignore
- Delete examples directory and its example action system
- Rename actions/ to legacy_actions/ and data/ to legacy_data/
- Update Cargo.toml license file reference
- Move setup scripts to scripts/dev/ directory
- Add todo.txt patterns to .gitignore
Diffstat (limited to 'data/tests/src/test_virtual_file_creation_and_update.rs')
| -rw-r--r-- | data/tests/src/test_virtual_file_creation_and_update.rs | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/data/tests/src/test_virtual_file_creation_and_update.rs b/data/tests/src/test_virtual_file_creation_and_update.rs deleted file mode 100644 index a09f7dc..0000000 --- a/data/tests/src/test_virtual_file_creation_and_update.rs +++ /dev/null @@ -1,162 +0,0 @@ -use std::time::Duration; - -use cfg_file::config::ConfigFile; -use tcp_connection_test::{ - handle::{ClientHandle, ServerHandle}, - target::TcpServerTarget, - target_configure::ServerTargetConfig, -}; -use tokio::{ - join, - time::{sleep, timeout}, -}; -use vcs_data::{ - constants::SERVER_FILE_VAULT, - data::{ - member::Member, - vault::{Vault, vault_config::VaultConfig, virtual_file::VirtualFileVersionDescription}, - }, -}; - -use crate::get_test_dir; - -struct VirtualFileCreateClientHandle; -struct VirtualFileCreateServerHandle; - -impl ClientHandle<VirtualFileCreateServerHandle> for VirtualFileCreateClientHandle { - async fn process(mut instance: tcp_connection::instance::ConnectionInstance) { - let dir = get_test_dir("virtual_file_creation_and_update_2") - .await - .unwrap(); - // Create first test file for virtual file creation - let test_content_1 = b"Test file content for virtual file creation"; - let temp_file_path_1 = dir.join("test_virtual_file_1.txt"); - - tokio::fs::write(&temp_file_path_1, test_content_1) - .await - .unwrap(); - - // Send the first file to server for virtual file creation - instance.write_file(&temp_file_path_1).await.unwrap(); - - // Create second test file for virtual file update - let test_content_2 = b"Updated test file content for virtual file"; - let temp_file_path_2 = dir.join("test_virtual_file_2.txt"); - - tokio::fs::write(&temp_file_path_2, test_content_2) - .await - .unwrap(); - - // Send the second file to server for virtual file update - instance.write_file(&temp_file_path_2).await.unwrap(); - } -} - -impl ServerHandle<VirtualFileCreateClientHandle> for VirtualFileCreateServerHandle { - async fn process(mut instance: tcp_connection::instance::ConnectionInstance) { - let dir = get_test_dir("virtual_file_creation_and_update") - .await - .unwrap(); - - // Setup vault - Vault::setup_vault(dir.clone(), "TestVault").await.unwrap(); - - // Read vault - let Some(vault) = Vault::init( - VaultConfig::read_from(dir.join(SERVER_FILE_VAULT)) - .await - .unwrap(), - &dir, - ) else { - panic!("No vault found!"); - }; - - // Register member - let member_id = "test_member"; - vault - .register_member_to_vault(Member::new(member_id)) - .await - .unwrap(); - - // Create visual file - let virtual_file_id = vault - .create_virtual_file_from_connection(&mut instance, &member_id.to_string()) - .await - .unwrap(); - - // Grant edit right to member - vault - .grant_virtual_file_edit_right(&member_id.to_string(), &virtual_file_id) - .await - .unwrap(); - - // Update visual file - vault - .update_virtual_file_from_connection( - &mut instance, - &member_id.to_string(), - &virtual_file_id, - &"2".to_string(), - VirtualFileVersionDescription { - creator: member_id.to_string(), - description: "Update".to_string(), - }, - ) - .await - .unwrap(); - } -} - -#[tokio::test] -async fn test_virtual_file_creation_and_update() -> Result<(), std::io::Error> { - let host = "localhost:5009"; - - // Server setup - let Ok(server_target) = TcpServerTarget::< - VirtualFileCreateClientHandle, - VirtualFileCreateServerHandle, - >::from_domain(host) - .await - else { - panic!("Test target built failed from a domain named `{}`", host); - }; - - // Client setup - let Ok(client_target) = TcpServerTarget::< - VirtualFileCreateClientHandle, - VirtualFileCreateServerHandle, - >::from_domain(host) - .await - else { - panic!("Test target built failed from a domain named `{}`", host); - }; - - let future_server = async move { - // Only process once - let configured_server = server_target.server_cfg(ServerTargetConfig::default().once()); - - // Listen here - let _ = configured_server.listen().await; - }; - - let future_client = async move { - // Wait for server start - let _ = sleep(Duration::from_secs_f32(1.5)).await; - - // Connect here - let _ = client_target.connect().await; - }; - - let test_timeout = Duration::from_secs(15); - - timeout(test_timeout, async { join!(future_client, future_server) }) - .await - .map_err(|_| { - std::io::Error::new( - std::io::ErrorKind::TimedOut, - format!("Test timed out after {:?}", test_timeout), - ) - })?; - - Ok(()) -} |
