From 192a203db4493997caceb8c859920a27447950cd Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Wed, 24 Sep 2025 10:24:27 -0400 Subject: [PATCH] Wrap some tests in a `mod` so that I can `--skip` them In environemnts without dotnet installed, these tests were the only thing preventing `cargo test --all -- --skip csharp` from completing successfully. I also included `rust` in the name, though running tests in an environment without cargo/rustc installed seems less likely to work. --- crates/schema/tests/ensure_same_schema.rs | 108 +++++++++++----------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/crates/schema/tests/ensure_same_schema.rs b/crates/schema/tests/ensure_same_schema.rs index fcdfae6dfb0..3625330181d 100644 --- a/crates/schema/tests/ensure_same_schema.rs +++ b/crates/schema/tests/ensure_same_schema.rs @@ -1,61 +1,65 @@ -use serial_test::serial; -use spacetimedb_schema::auto_migrate::{ponder_auto_migrate, AutoMigrateStep}; -use spacetimedb_schema::def::ModuleDef; -use spacetimedb_testing::modules::{CompilationMode, CompiledModule}; +// Wrap these tests in a `mod` whose name contains `csharp` +// so that we can run tests with `--skip csharp` in environments without dotnet installed. +mod ensure_same_schema_rust_csharp { + use serial_test::serial; + use spacetimedb_schema::auto_migrate::{ponder_auto_migrate, AutoMigrateStep}; + use spacetimedb_schema::def::ModuleDef; + use spacetimedb_testing::modules::{CompilationMode, CompiledModule}; -fn get_normalized_schema(module_name: &str) -> ModuleDef { - let module = CompiledModule::compile(module_name, CompilationMode::Debug); - module.extract_schema_blocking() -} + fn get_normalized_schema(module_name: &str) -> ModuleDef { + let module = CompiledModule::compile(module_name, CompilationMode::Debug); + module.extract_schema_blocking() + } -fn assert_identical_modules(module_name_prefix: &str) { - let rs = get_normalized_schema(module_name_prefix); - let cs = get_normalized_schema(&format!("{module_name_prefix}-cs")); - let mut diff = ponder_auto_migrate(&cs, &rs) - .expect("could not compute a diff between Rust and C#") - .steps; + fn assert_identical_modules(module_name_prefix: &str) { + let rs = get_normalized_schema(module_name_prefix); + let cs = get_normalized_schema(&format!("{module_name_prefix}-cs")); + let mut diff = ponder_auto_migrate(&cs, &rs) + .expect("could not compute a diff between Rust and C#") + .steps; - // In any migration plan, all `RowLevelSecurityDef`s are ALWAYS removed and - // re-added to ensure the core engine reinintializes the policies. - // This is slightly silly (and arguably should be hidden inside `core`), - // but for now, we just ignore these steps and manually compare the `RowLevelSecurityDef`s. - diff.retain(|step| { - !matches!( - step, - AutoMigrateStep::AddRowLevelSecurity(_) | AutoMigrateStep::RemoveRowLevelSecurity(_) - ) - }); + // In any migration plan, all `RowLevelSecurityDef`s are ALWAYS removed and + // re-added to ensure the core engine reinintializes the policies. + // This is slightly silly (and arguably should be hidden inside `core`), + // but for now, we just ignore these steps and manually compare the `RowLevelSecurityDef`s. + diff.retain(|step| { + !matches!( + step, + AutoMigrateStep::AddRowLevelSecurity(_) | AutoMigrateStep::RemoveRowLevelSecurity(_) + ) + }); - assert!( - diff.is_empty(), - "Rust and C# modules are not identical. Here are the steps to migrate from C# to Rust: {diff:#?}" - ); + assert!( + diff.is_empty(), + "Rust and C# modules are not identical. Here are the steps to migrate from C# to Rust: {diff:#?}" + ); - let mut rls_rs = rs.row_level_security().collect::>(); - rls_rs.sort(); - let mut rls_cs = cs.row_level_security().collect::>(); - rls_cs.sort(); - assert_eq!( - rls_rs, rls_cs, - "Rust and C# modules are not identical: different row level security policies" - ) -} + let mut rls_rs = rs.row_level_security().collect::>(); + rls_rs.sort(); + let mut rls_cs = cs.row_level_security().collect::>(); + rls_cs.sort(); + assert_eq!( + rls_rs, rls_cs, + "Rust and C# modules are not identical: different row level security policies" + ) + } -macro_rules! declare_tests { - ($($name:ident => $path:literal,)*) => { - $( - #[test] - #[serial] - fn $name() { - assert_identical_modules($path); - } - )* + macro_rules! declare_tests { + ($($name:ident => $path:literal,)*) => { + $( + #[test] + #[serial] + fn $name() { + assert_identical_modules($path); + } + )* + } } -} -declare_tests! { - module_test => "module-test", - sdk_test_connect_disconnect => "sdk-test-connect-disconnect", - sdk_test => "sdk-test", - benchmarks => "benchmarks", + declare_tests! { + module_test => "module-test", + sdk_test_connect_disconnect => "sdk-test-connect-disconnect", + sdk_test => "sdk-test", + benchmarks => "benchmarks", + } }