Skip to content

Commit

Permalink
Merge pull request #5 from javitonino/multiple_variants
Browse files Browse the repository at this point in the history
Support multiple variants (combined with OR)
  • Loading branch information
vangheem authored Jul 18, 2024
2 parents 9ceff3a + af5e13b commit f50996c
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ impl FlagService {
&& value.iter().any(|v| v == ucontext.get(key).unwrap())
{
return true;
} else {
return false;
}
}
}
Expand Down Expand Up @@ -219,6 +217,54 @@ mod tests {
);
}

#[test]
fn it_handles_multiple_variants() {
let server = SERVER_POOL.get_server();
server.expect(
Expectation::matching(any()).respond_with(status_code(200).body(
r#"
{
"feature_variant": {
"rollout": 0,
"variants": {
"user_id": ["123"],
"env": ["dev"]
}
}
}"#,
)),
);

let flag_service = FlagService::new(crate::service::FlagServiceOptions {
refresh_interval: 0,
finder_type: crate::types::FlagFinderType::URL,
url: Some(server.url("/").to_string()),
env_var: None,
data: None,
});

assert_eq!(
flag_service.enabled(
"feature_variant",
false,
Some(HashMap::from([("user_id".to_string(), "123".to_string()),]))
),
true
);
assert_eq!(
flag_service.enabled(
"feature_variant",
false,
Some(HashMap::from([("env".to_string(), "dev".to_string()),]))
),
true
);
assert_eq!(
flag_service.enabled("feature_variant", false, Some(HashMap::new())),
false
);
}

#[test]
fn it_hashes_context_rollout() {
let server = SERVER_POOL.get_server();
Expand Down

0 comments on commit f50996c

Please sign in to comment.