cuprated: config versioning + backwards compat test ()

* apply

* typo

* fix path
This commit is contained in:
hinto-janai 2025-03-05 20:35:14 -05:00 committed by GitHub
parent d795b51e4d
commit f554be73b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 8 deletions

View file

@ -0,0 +1 @@
0.0.1.toml

View file

@ -0,0 +1,6 @@
# `cuprated` configs
This directory holds configuration files for all `cuprated` versions.
For example, `0.0.1.toml` is the config file for `cuprated v0.0.1`.
`Cuprated.toml` is a symlink to the latest config file.

View file

@ -177,3 +177,35 @@ impl Config {
self.p2p.block_downloader.clone().into()
}
}
#[cfg(test)]
mod test {
use toml::from_str;
use crate::constants::EXAMPLE_CONFIG;
use super::*;
/// Tests the latest config is the `Default`.
#[test]
fn config_latest() {
let config: Config = from_str(EXAMPLE_CONFIG).unwrap();
assert_eq!(config, Config::default());
}
/// Tests backwards compatibility.
#[test]
fn config_backwards_compat() {
// (De)serialization tests.
#[expect(
clippy::single_element_loop,
reason = "Remove after adding other versions"
)]
for version in ["0.0.1"] {
let path = format!("config/{version}.toml");
println!("Testing config serde backwards compat: {path}");
let string = read_to_string(path).unwrap();
from_str::<Config>(&string).unwrap();
}
}
}

View file

@ -23,7 +23,7 @@ pub const VERSION_BUILD: &str = formatcp!("{VERSION}-{}", cuprate_constants::bui
pub const PANIC_CRITICAL_SERVICE_ERROR: &str =
"A service critical to Cuprate's function returned an unexpected error.";
pub const EXAMPLE_CONFIG: &str = include_str!("../Cuprated.toml");
pub const EXAMPLE_CONFIG: &str = include_str!("../config/Cuprated.toml");
#[cfg(test)]
mod test {
@ -45,11 +45,4 @@ mod test {
assert_eq!(VERSION_BUILD, "0.0.1-release");
}
}
#[test]
fn generate_config_text_is_valid() {
let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap();
assert_eq!(config, Config::default());
}
}