Skip to content

Commit 0463fc5

Browse files
committed
Add CI-local Veilid test mode via network overrides
1 parent 7de4993 commit 0463fc5

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

.github/workflows/lint_and_test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
- name: Run tests with retries
3333
env:
3434
RUST_MIN_STACK: 8388608
35+
SAVE_VEILID_LOCAL_TEST_MODE: "1"
36+
SAVE_VEILID_TEST_NETWORK_KEY: save-rust-ci-${{ github.run_id }}-${{ github.run_attempt }}
3537
# Retries configured in .config/nextest.toml (nextest default path)
3638
# --no-fail-fast: run all tests even when some fail, so we see full results
3739
run: cargo nextest run --test-threads=1 --no-fail-fast

src/lib.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod utils;
1919

2020
#[cfg(test)]
2121
mod tests {
22+
use std::env;
2223
use std::time::Duration;
2324

2425
use super::*;
@@ -33,6 +34,7 @@ mod tests {
3334
use base64_url::base64;
3435
use base64_url::base64::Engine;
3536
use save_dweb_backend::backend::Backend;
37+
use veilid_core::VeilidConfig;
3638
use veilid_core::VeilidUpdate;
3739
use serial_test::serial;
3840
use std::sync::Arc;
@@ -65,14 +67,59 @@ mod tests {
6567
(path, namespace)
6668
}
6769

70+
fn env_flag(name: &str) -> bool {
71+
match env::var(name) {
72+
Ok(value) => {
73+
let normalized = value.trim().to_ascii_lowercase();
74+
matches!(normalized.as_str(), "1" | "true" | "yes" | "on")
75+
}
76+
Err(_) => false,
77+
}
78+
}
79+
80+
fn csv_env(name: &str) -> Option<Vec<String>> {
81+
let value = env::var(name).ok()?;
82+
let values: Vec<String> = value
83+
.split(',')
84+
.map(|item| item.trim())
85+
.filter(|item| !item.is_empty())
86+
.map(ToOwned::to_owned)
87+
.collect();
88+
if values.is_empty() {
89+
None
90+
} else {
91+
Some(values)
92+
}
93+
}
94+
95+
fn apply_test_network_overrides(config: &mut VeilidConfig) {
96+
if !env_flag("SAVE_VEILID_LOCAL_TEST_MODE") {
97+
return;
98+
}
99+
100+
let network_key = env::var("SAVE_VEILID_TEST_NETWORK_KEY")
101+
.unwrap_or_else(|_| "save-rust-local-test-network".to_string());
102+
config.network.network_key_password = Some(network_key);
103+
104+
// Keep test nodes deterministic and less noisy in CI.
105+
config.network.upnp = false;
106+
config.network.detect_address_changes = Some(false);
107+
config.network.restricted_nat_retries = 0;
108+
109+
if let Some(bootstrap) = csv_env("SAVE_VEILID_TEST_BOOTSTRAP") {
110+
config.network.routing_table.bootstrap = bootstrap;
111+
}
112+
}
113+
68114
// Local Veilid init for tests so we can tune readiness timeouts without modifying
69115
// the published `save-dweb-backend` tag dependency.
70116
async fn init_veilid_for_tests(
71117
base_dir: &std::path::Path,
72118
namespace: String,
73119
ready_timeout: Duration,
74120
) -> anyhow::Result<(veilid_core::VeilidAPI, broadcast::Receiver<VeilidUpdate>)> {
75-
let config = save_dweb_backend::common::config_for_dir(base_dir.to_path_buf(), namespace);
121+
let mut config = save_dweb_backend::common::config_for_dir(base_dir.to_path_buf(), namespace);
122+
apply_test_network_overrides(&mut config);
76123

77124
let (tx, mut rx) = broadcast::channel(32);
78125
let update_callback: veilid_core::UpdateCallback = Arc::new(move |update| {

0 commit comments

Comments
 (0)