Skip to content

Commit 57ec34c

Browse files
authored
Wrap some tests in a mod so that I can --skip them (#3284)
# Description of Changes In environments 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. Extracted from #3263 at request of @Centril . # API and ABI breaking changes N/a # Expected complexity level and risk 1 # Testing N/a
1 parent dcf8a2a commit 57ec34c

1 file changed

Lines changed: 56 additions & 52 deletions

File tree

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,65 @@
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};
58

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+
}
1013

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;
1720

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+
});
2831

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+
);
3336

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+
}
4346

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+
}
5357
}
54-
}
5558

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+
}
6165
}

0 commit comments

Comments
 (0)