Skip to content

Commit f024162

Browse files
committed
fix(ci): make CLI path tests portable
1 parent f35b1b1 commit f024162

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

crates/cli/src/main.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,8 +2288,12 @@ mod tests {
22882288
/// The scaffolded default frontend port, distinct from every default API port.
22892289
const TEST_FRONTEND_PORT: u16 = 3000;
22902290

2291-
fn test_binding(name: &str, api_port: u16, workdir: &str) -> OrchestratorNetworkBinding {
2292-
let workdir = PathBuf::from(workdir);
2291+
fn test_binding(
2292+
name: &str,
2293+
api_port: u16,
2294+
workdir: impl Into<PathBuf>,
2295+
) -> OrchestratorNetworkBinding {
2296+
let workdir = workdir.into();
22932297
OrchestratorNetworkBinding {
22942298
network: name.to_string(),
22952299
api_port,
@@ -2302,18 +2306,20 @@ mod tests {
23022306

23032307
#[test]
23042308
fn test_check_orchestrator_bindings_distinct_ports_and_dirs_ok() {
2309+
let dir = TempDir::new().unwrap();
23052310
let nets = vec![
2306-
test_binding("mainnet", 8101, "/root/mainnet"),
2307-
test_binding("testnet", 8102, "/root/testnet"),
2311+
test_binding("mainnet", 8101, dir.path().join("mainnet")),
2312+
test_binding("testnet", 8102, dir.path().join("testnet")),
23082313
];
23092314
assert!(check_orchestrator_bindings(&nets, TEST_FRONTEND_PORT).is_ok());
23102315
}
23112316

23122317
#[test]
23132318
fn test_check_orchestrator_bindings_duplicate_port_errors() {
2319+
let dir = TempDir::new().unwrap();
23142320
let nets = vec![
2315-
test_binding("mainnet", 8101, "/root/mainnet"),
2316-
test_binding("testnet", 8101, "/root/testnet"),
2321+
test_binding("mainnet", 8101, dir.path().join("mainnet")),
2322+
test_binding("testnet", 8101, dir.path().join("testnet")),
23172323
];
23182324
let err = check_orchestrator_bindings(&nets, TEST_FRONTEND_PORT)
23192325
.unwrap_err()
@@ -2329,9 +2335,10 @@ mod tests {
23292335
// the check only compared api-vs-api: a frontend/API clash reached
23302336
// runtime, where whichever lost the bind race restart-looped — and the
23312337
// frontend is the whole deployment's entry point.
2338+
let dir = TempDir::new().unwrap();
23322339
let nets = vec![
2333-
test_binding("mainnet", 8101, "/root/mainnet"),
2334-
test_binding("testnet", 3000, "/root/testnet"),
2340+
test_binding("mainnet", 8101, dir.path().join("mainnet")),
2341+
test_binding("testnet", 3000, dir.path().join("testnet")),
23352342
];
23362343
let err = check_orchestrator_bindings(&nets, TEST_FRONTEND_PORT)
23372344
.unwrap_err()
@@ -2348,7 +2355,8 @@ mod tests {
23482355
fn test_check_orchestrator_bindings_frontend_collides_with_the_first_network_too() {
23492356
// Guards the loop bound: the frontend must be compared against EVERY api
23502357
// port, not only the ones after the first.
2351-
let nets = vec![test_binding("mainnet", 8101, "/root/mainnet")];
2358+
let dir = TempDir::new().unwrap();
2359+
let nets = vec![test_binding("mainnet", 8101, dir.path().join("mainnet"))];
23522360
let err = check_orchestrator_bindings(&nets, 8101)
23532361
.unwrap_err()
23542362
.to_string();
@@ -2358,29 +2366,29 @@ mod tests {
23582366

23592367
#[test]
23602368
fn test_check_orchestrator_bindings_duplicate_workdir_errors() {
2369+
let dir = TempDir::new().unwrap();
2370+
let shared = dir.path().join("shared");
23612371
let nets = vec![
2362-
test_binding("mainnet", 8101, "/root/shared"),
2363-
test_binding("testnet", 8102, "/root/shared"),
2372+
test_binding("mainnet", 8101, shared.clone()),
2373+
test_binding("testnet", 8102, shared.clone()),
23642374
];
23652375
let err = check_orchestrator_bindings(&nets, TEST_FRONTEND_PORT)
23662376
.unwrap_err()
23672377
.to_string();
23682378
assert!(err.contains("mainnet"), "error names first network: {err}");
23692379
assert!(err.contains("testnet"), "error names second network: {err}");
2370-
assert!(
2371-
err.contains("/root/shared"),
2372-
"error names the shared workdir: {err}"
2373-
);
2380+
assert!(err.contains(&shared.display().to_string()), "got: {err}");
23742381
}
23752382

23762383
#[test]
23772384
fn test_check_orchestrator_bindings_rejects_each_duplicate_logical_store_path() {
2385+
let dir = TempDir::new().unwrap();
23782386
for logical_store in ["domain", "append-only", "network"] {
23792387
let mut nets = vec![
2380-
test_binding("mainnet", 8101, "/root/mainnet"),
2381-
test_binding("testnet", 8102, "/root/testnet"),
2388+
test_binding("mainnet", 8101, dir.path().join("mainnet")),
2389+
test_binding("testnet", 8102, dir.path().join("testnet")),
23822390
];
2383-
let shared = PathBuf::from(format!("/custom/shared-{logical_store}"));
2391+
let shared = dir.path().join(format!("shared-{logical_store}"));
23842392
match logical_store {
23852393
"domain" => {
23862394
nets[0].domain_data_path = shared.clone();
@@ -2409,9 +2417,10 @@ mod tests {
24092417

24102418
#[test]
24112419
fn test_check_orchestrator_bindings_rejects_cross_class_store_collision() {
2420+
let dir = TempDir::new().unwrap();
24122421
let mut nets = vec![
2413-
test_binding("mainnet", 8101, "/root/mainnet"),
2414-
test_binding("testnet", 8102, "/root/testnet"),
2422+
test_binding("mainnet", 8101, dir.path().join("mainnet")),
2423+
test_binding("testnet", 8102, dir.path().join("testnet")),
24152424
];
24162425
nets[1].network_data_path = nets[0].domain_data_path.clone();
24172426

@@ -2437,8 +2446,8 @@ mod tests {
24372446
let mainnet_workdir = root.join("mainnet");
24382447
let testnet_workdir = root.join("testnet");
24392448
let mut nets = vec![
2440-
test_binding("mainnet", 8101, mainnet_workdir.to_str().unwrap()),
2441-
test_binding("testnet", 8102, testnet_workdir.to_str().unwrap()),
2449+
test_binding("mainnet", 8101, mainnet_workdir),
2450+
test_binding("testnet", 8102, testnet_workdir),
24422451
];
24432452
nets[0].domain_data_path = store_link.join("domain");
24442453
nets[1].domain_data_path = shared.join("domain");

0 commit comments

Comments
 (0)