use hotdata::Configuration;
fn cargo_toml_package_version() -> String {
let manifest = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml"))
.expect("Cargo.toml should be readable");
let mut in_package = false;
for line in manifest.lines() {
let trimmed = line.trim();
if trimmed.starts_with('[') {
in_package = trimmed == "[package]";
continue;
}
if in_package {
if let Some(rest) = trimmed.strip_prefix("version") {
let rest = rest.trim_start();
if let Some(rest) = rest.strip_prefix('=') {
return rest.trim().trim_matches('"').to_owned();
}
}
}
}
panic!("could not find [package] version in Cargo.toml");
}
#[test]
fn default_user_agent_matches_crate_version() {
let expected = format!("hotdata-rust/{}", cargo_toml_package_version());
assert_eq!(
Configuration::default().user_agent.as_deref(),
Some(expected.as_str()),
"default user-agent must match the [package] version in Cargo.toml"
);
}