fix eviction policy parsing

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2023-06-01 13:56:44 -04:00
parent d70fcbd007
commit e4c2713dc6

View File

@@ -235,7 +235,7 @@ pub struct TenantConfig {
// Otherwise we'd have to move the types for eviction policy into this package.
// We might do that once the eviction feature has stabilizied.
// For now, this field is not even documented in the openapi_spec.yml.
#[clap(long, value_parser = clap::value_parser!(serde_json::Value))]
#[clap(long, value_parser = parse_json)]
pub eviction_policy: Option<serde_json::Value>,
#[clap(long)]
pub min_resident_size_override: Option<u64>,
@@ -244,6 +244,10 @@ pub struct TenantConfig {
pub gc_feedback: Option<bool>,
}
fn parse_json(s: &str) -> Result<serde_json::Value, serde_json::Error> {
serde_json::from_str(s)
}
impl TenantConfig {
pub fn deserialize_from_settings(settings: HashMap<&str, &str>) -> Result<Self, anyhow::Error> {
let config = TenantConfig::try_parse_from(
@@ -928,6 +932,15 @@ mod tests {
);
}
#[test]
fn test_parse_json_field() {
let config = vec![(
"eviction_policy",
"eviction_policy:{\"kind\": \"NoEviction\"}",
)];
TenantConfig::deserialize_from_settings(config.into_iter().collect()).unwrap();
}
#[test]
fn tenantstatus_activating_serde() {
let states = [