|
1 | | -use serial_test::serial; |
2 | | -use spacetimedb_schema::auto_migrate::{ponder_auto_migrate, AutoMigrateStep}; |
3 | | -use spacetimedb_schema::def::ModuleDef; |
4 | | -use spacetimedb_testing::modules::{CompilationMode, CompiledModule}; |
| 1 | +// Wrap these tests in a `mod` whose name contains `csharp` |
| 2 | +// so that we can run tests with `--skip csharp` in environments without dotnet installed. |
| 3 | +mod ensure_same_schema_rust_csharp { |
| 4 | + use serial_test::serial; |
| 5 | + use spacetimedb_schema::auto_migrate::{ponder_auto_migrate, AutoMigrateStep}; |
| 6 | + use spacetimedb_schema::def::ModuleDef; |
| 7 | + use spacetimedb_testing::modules::{CompilationMode, CompiledModule}; |
5 | 8 |
|
6 | | -fn get_normalized_schema(module_name: &str) -> ModuleDef { |
7 | | - let module = CompiledModule::compile(module_name, CompilationMode::Debug); |
8 | | - module.extract_schema_blocking() |
9 | | -} |
| 9 | + fn get_normalized_schema(module_name: &str) -> ModuleDef { |
| 10 | + let module = CompiledModule::compile(module_name, CompilationMode::Debug); |
| 11 | + module.extract_schema_blocking() |
| 12 | + } |
10 | 13 |
|
11 | | -fn assert_identical_modules(module_name_prefix: &str) { |
12 | | - let rs = get_normalized_schema(module_name_prefix); |
13 | | - let cs = get_normalized_schema(&format!("{module_name_prefix}-cs")); |
14 | | - let mut diff = ponder_auto_migrate(&cs, &rs) |
15 | | - .expect("could not compute a diff between Rust and C#") |
16 | | - .steps; |
| 14 | + fn assert_identical_modules(module_name_prefix: &str) { |
| 15 | + let rs = get_normalized_schema(module_name_prefix); |
| 16 | + let cs = get_normalized_schema(&format!("{module_name_prefix}-cs")); |
| 17 | + let mut diff = ponder_auto_migrate(&cs, &rs) |
| 18 | + .expect("could not compute a diff between Rust and C#") |
| 19 | + .steps; |
17 | 20 |
|
18 | | - // In any migration plan, all `RowLevelSecurityDef`s are ALWAYS removed and |
19 | | - // re-added to ensure the core engine reinintializes the policies. |
20 | | - // This is slightly silly (and arguably should be hidden inside `core`), |
21 | | - // but for now, we just ignore these steps and manually compare the `RowLevelSecurityDef`s. |
22 | | - diff.retain(|step| { |
23 | | - !matches!( |
24 | | - step, |
25 | | - AutoMigrateStep::AddRowLevelSecurity(_) | AutoMigrateStep::RemoveRowLevelSecurity(_) |
26 | | - ) |
27 | | - }); |
| 21 | + // In any migration plan, all `RowLevelSecurityDef`s are ALWAYS removed and |
| 22 | + // re-added to ensure the core engine reinintializes the policies. |
| 23 | + // This is slightly silly (and arguably should be hidden inside `core`), |
| 24 | + // but for now, we just ignore these steps and manually compare the `RowLevelSecurityDef`s. |
| 25 | + diff.retain(|step| { |
| 26 | + !matches!( |
| 27 | + step, |
| 28 | + AutoMigrateStep::AddRowLevelSecurity(_) | AutoMigrateStep::RemoveRowLevelSecurity(_) |
| 29 | + ) |
| 30 | + }); |
28 | 31 |
|
29 | | - assert!( |
30 | | - diff.is_empty(), |
31 | | - "Rust and C# modules are not identical. Here are the steps to migrate from C# to Rust: {diff:#?}" |
32 | | - ); |
| 32 | + assert!( |
| 33 | + diff.is_empty(), |
| 34 | + "Rust and C# modules are not identical. Here are the steps to migrate from C# to Rust: {diff:#?}" |
| 35 | + ); |
33 | 36 |
|
34 | | - let mut rls_rs = rs.row_level_security().collect::<Vec<_>>(); |
35 | | - rls_rs.sort(); |
36 | | - let mut rls_cs = cs.row_level_security().collect::<Vec<_>>(); |
37 | | - rls_cs.sort(); |
38 | | - assert_eq!( |
39 | | - rls_rs, rls_cs, |
40 | | - "Rust and C# modules are not identical: different row level security policies" |
41 | | - ) |
42 | | -} |
| 37 | + let mut rls_rs = rs.row_level_security().collect::<Vec<_>>(); |
| 38 | + rls_rs.sort(); |
| 39 | + let mut rls_cs = cs.row_level_security().collect::<Vec<_>>(); |
| 40 | + rls_cs.sort(); |
| 41 | + assert_eq!( |
| 42 | + rls_rs, rls_cs, |
| 43 | + "Rust and C# modules are not identical: different row level security policies" |
| 44 | + ) |
| 45 | + } |
43 | 46 |
|
44 | | -macro_rules! declare_tests { |
45 | | - ($($name:ident => $path:literal,)*) => { |
46 | | - $( |
47 | | - #[test] |
48 | | - #[serial] |
49 | | - fn $name() { |
50 | | - assert_identical_modules($path); |
51 | | - } |
52 | | - )* |
| 47 | + macro_rules! declare_tests { |
| 48 | + ($($name:ident => $path:literal,)*) => { |
| 49 | + $( |
| 50 | + #[test] |
| 51 | + #[serial] |
| 52 | + fn $name() { |
| 53 | + assert_identical_modules($path); |
| 54 | + } |
| 55 | + )* |
| 56 | + } |
53 | 57 | } |
54 | | -} |
55 | 58 |
|
56 | | -declare_tests! { |
57 | | - module_test => "module-test", |
58 | | - sdk_test_connect_disconnect => "sdk-test-connect-disconnect", |
59 | | - sdk_test => "sdk-test", |
60 | | - benchmarks => "benchmarks", |
| 59 | + declare_tests! { |
| 60 | + module_test => "module-test", |
| 61 | + sdk_test_connect_disconnect => "sdk-test-connect-disconnect", |
| 62 | + sdk_test => "sdk-test", |
| 63 | + benchmarks => "benchmarks", |
| 64 | + } |
61 | 65 | } |
0 commit comments