use magnetar_admin::{AdminAuth, AdminClient, AdminError, TenantInfo};
#[test]
fn builder_defaults_no_auth() {
let client = AdminClient::builder()
.service_url("http://localhost:8080".parse().unwrap())
.build()
.unwrap();
assert!(matches!(client.auth(), AdminAuth::None));
}
#[test]
fn builder_with_https_url() {
let client = AdminClient::builder()
.service_url("https://broker.example:443".parse().unwrap())
.build()
.unwrap();
assert_eq!(
client.base_url().as_str(),
"https://broker.example/admin/v2/"
);
}
#[test]
fn builder_with_trailing_slash() {
let client = AdminClient::builder()
.service_url("http://localhost:8080/".parse().unwrap())
.build()
.unwrap();
assert_eq!(
client.base_url().as_str(),
"http://localhost:8080/admin/v2/"
);
}
#[test]
fn builder_with_path_prefix_is_preserved() {
let client = AdminClient::builder()
.service_url("http://localhost:8080/pulsar".parse().unwrap())
.build()
.unwrap();
assert_eq!(
client.base_url().as_str(),
"http://localhost:8080/pulsar/admin/v2/"
);
}
#[test]
fn tenant_info_serializes_with_java_keys() {
let info = TenantInfo {
admin_roles: vec!["admin".into()],
allowed_clusters: vec!["standalone".into()],
};
let json = serde_json::to_string(&info).unwrap();
assert!(json.contains("\"adminRoles\""));
assert!(json.contains("\"allowedClusters\""));
}
#[test]
fn tenant_info_deserializes_with_java_keys() {
let json = r#"{"adminRoles":["a"],"allowedClusters":["c"]}"#;
let info: TenantInfo = serde_json::from_str(json).unwrap();
assert_eq!(info.admin_roles, vec!["a".to_owned()]);
assert_eq!(info.allowed_clusters, vec!["c".to_owned()]);
}
#[test]
fn builder_requires_url() {
let err = AdminClient::builder().build().unwrap_err();
assert!(matches!(err, AdminError::Builder(_)));
}
#[test]
fn builder_timeout_accepts_value() {
let client = AdminClient::builder()
.service_url("http://localhost:8080".parse().unwrap())
.timeout(std::time::Duration::from_secs(5))
.build()
.unwrap();
assert_eq!(
client.base_url().as_str(),
"http://localhost:8080/admin/v2/"
);
}