this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: move tests outside of the rust again

+93 -13
+21
mise/tasks/check.toml
··· 22 22 [clippy_watch] 23 23 tools.watchexec = "latest" 24 24 run = "watchexec -c clear -restart -e rs,toml 'clear ; cargo clippy'" 25 + 26 + 27 + [test] 28 + description = "Run the check command on both server and client." 29 + run = { tasks = ["check-server", "check-client"] } 30 + 31 + [test-server] 32 + depends = ["build-client"] 33 + hide = true 34 + run = "cargo test" 35 + dir = "./server" 36 + 37 + [test-client] 38 + hide = true 39 + run = "gleam test" 40 + dir = "./client/" 41 + 42 + [test-watch] 43 + tools.watchexec = "latest" 44 + description = "Run the server in development mode with file watching" 45 + run = "mise watch --restart -e rs,gleam,toml,css,ts,json --clear=clear test"
+72 -13
server/src/tests.rs
··· 17 17 */ 18 18 19 19 #[cfg(test)] 20 - #[test] 21 - fn gleam_test() { 22 - // Sometimes 23 - println!("Checking Gleam client code..."); 24 - let lustre_result = std::process::Command::new("gleam") 25 - .current_dir("../client/") 26 - .args(&["test"]) 27 - .output() 28 - .expect("Could not run gleam test command. The outcome of the tests itself is unknown."); 20 + mod tests { 21 + use crate::database::{self, DatabaseConnections}; 22 + use crate::timeline; 29 23 30 - eprint!("{}", String::from_utf8_lossy(&lustre_result.stderr)); 31 - print!("{}", String::from_utf8_lossy(&lustre_result.stdout)); 24 + #[tokio::test] 25 + async fn test_database_setup() { 26 + let result = database::setup().await; 27 + assert!(result.is_ok(), "Database setup should succeed"); 28 + } 29 + 30 + #[tokio::test] 31 + async fn test_redis_bloom_filter() { 32 + let db = database::setup().await.expect("DB setup"); 33 + let redis_pool = db.get_redis_pool(); 34 + let mut conn = redis_pool.get().await.expect("Redis conn"); 35 + let email_key = "test_bloom:email"; 36 + let test_email = "testuser@example.com"; 37 + 38 + // Add to bloom filter 39 + let _: () = redis::cmd("BF.ADD") 40 + .arg(email_key) 41 + .arg(test_email) 42 + .query_async(&mut *conn) 43 + .await 44 + .expect("BF.ADD"); 45 + 46 + // Check if exists 47 + let exists: bool = redis::cmd("BF.EXISTS") 48 + .arg(email_key) 49 + .arg(test_email) 50 + .query_async(&mut *conn) 51 + .await 52 + .expect("BF.EXISTS"); 53 + 54 + assert!(exists, "Bloom filter should contain the test email"); 55 + 56 + // Clean up 57 + let _: () = redis::cmd("DEL") 58 + .arg(email_key) 59 + .query_async(&mut *conn) 60 + .await 61 + .unwrap_or(()); 62 + } 32 63 33 - if !lustre_result.status.success() { 34 - panic!("Gleam tests failed."); 64 + #[tokio::test] 65 + async fn test_timeline_invalidation() { 66 + let db = database::setup().await.expect("DB setup"); 67 + let redis_pool = db.get_redis_pool(); 68 + let mut conn = redis_pool.get().await.expect("Redis conn"); 69 + let timeline_id = "test-timeline-invalidation"; 70 + 71 + // Set a test cache key 72 + let cache_key = format!("timeline_cache:{}:page:0", timeline_id); 73 + let _: () = redis::cmd("SET") 74 + .arg(&cache_key) 75 + .arg("test_data") 76 + .query_async(&mut *conn) 77 + .await 78 + .expect("SET"); 79 + 80 + // Invalidate the timeline 81 + timeline::invalidate_timeline_cache(&mut conn, timeline_id) 82 + .await 83 + .expect("Invalidate cache"); 84 + 85 + // Verify cache was cleared 86 + let result: Option<String> = redis::cmd("GET") 87 + .arg(&cache_key) 88 + .query_async(&mut *conn) 89 + .await 90 + .unwrap_or(None); 91 + 92 + assert!(result.is_none(), "Cache should be invalidated"); 35 93 } 36 94 } 95 +