Files
RustProxy/src/update_check/tests.rs
T
2026-10-05 09:30:21 +02:00

62 lines
1.9 KiB
Rust

mod tests {
use super::*;
#[test]
fn embedded_defaults_are_valid() {
let config = Config::embedded().unwrap();
assert_eq!(
config.repository_url,
"https://git.linuxiarz.pl/gru/RustProxy"
);
assert_eq!(
config.version_url,
"https://git.linuxiarz.pl/gru/RustProxy/raw/branch/master/Cargo.toml"
);
assert_eq!(config.interval_seconds, 3600);
}
#[test]
fn reads_package_version_only() {
let document = r#"[workspace.package]
version = "99.0.0"
[package]
name = "rust-proxy"
version = "0.19.4"
[dependencies]
foo = { version = "100.0.0" }
"#;
assert_eq!(package_version(document).unwrap(), "0.19.4");
}
#[test]
fn update_redirects_accept_relative_https_and_reject_unsafe_targets() {
let base =
Url::parse("https://updates.example.invalid/releases/current/Cargo.toml").unwrap();
assert_eq!(
redirect_target(&base, "../next/Cargo.toml")
.unwrap()
.as_str(),
"https://updates.example.invalid/releases/next/Cargo.toml"
);
assert!(redirect_target(&base, "ftp://updates.example.invalid/Cargo.toml").is_err());
assert!(redirect_target(&base, "http://updates.example.invalid/Cargo.toml").is_err());
assert!(redirect_target(
&base,
"https://user:secret@updates.example.invalid/Cargo.toml"
)
.is_err());
}
#[test]
fn compares_release_versions() {
assert!(is_newer_version("0.19.5", "0.19.4"));
assert!(is_newer_version("0.20.0", "0.19.9"));
assert!(!is_newer_version("0.19.4", "0.19.4"));
assert!(!is_newer_version("0.19.3", "0.19.4"));
assert!(is_newer_version("0.19.4", "0.19.4-rc.1"));
assert!(!is_newer_version("0.19.4-rc.1", "0.19.4"));
}
}