mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-04-23 14:28:18 +00:00
cuprated: config versioning + backwards compat test (#394)
* apply * typo * fix path
This commit is contained in:
parent
d795b51e4d
commit
f554be73b9
5 changed files with 40 additions and 8 deletions
binaries/cuprated
1
binaries/cuprated/config/Cuprated.toml
Symbolic link
1
binaries/cuprated/config/Cuprated.toml
Symbolic link
|
@ -0,0 +1 @@
|
|||
0.0.1.toml
|
6
binaries/cuprated/config/README.md
Normal file
6
binaries/cuprated/config/README.md
Normal 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.
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue