pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn api_client() -> String {
format!("kopi/api/{VERSION}")
}
pub fn metadata_client() -> String {
format!("kopi/metadata/{VERSION}")
}
pub fn download_client() -> String {
format!("kopi/download/{VERSION}")
}
pub fn doctor_client() -> String {
format!("kopi/doctor/{VERSION}")
}
pub fn for_feature(feature: &str) -> String {
format!("kopi/{feature}/{VERSION}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_user_agents() {
assert_eq!(api_client(), format!("kopi/api/{VERSION}"));
assert_eq!(metadata_client(), format!("kopi/metadata/{VERSION}"));
assert_eq!(download_client(), format!("kopi/download/{VERSION}"));
assert_eq!(doctor_client(), format!("kopi/doctor/{VERSION}"));
assert_eq!(for_feature("custom"), format!("kopi/custom/{VERSION}"));
}
#[test]
fn test_version_format() {
let parts: Vec<&str> = VERSION.split('.').collect();
assert_eq!(
parts.len(),
3,
"Version should have 3 parts (major.minor.patch)"
);
for part in parts {
assert!(
part.parse::<u32>().is_ok(),
"Version part should be a number"
);
}
}
}