Skip to content

Commit

Permalink
fix: an issue where client features wouldn't correctly update in memo…
Browse files Browse the repository at this point in the history
…ry provider (#64)
  • Loading branch information
sighphyre authored Feb 15, 2023
1 parent ecd3eae commit b8b25d3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion server/src/data_sources/memory_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl MemoryProvider {
self.data_store
.entry(key(token))
.and_modify(|data| {
data.clone().merge(features.clone());
*data = data.clone().merge(features.clone());
})
.or_insert(features);
}
Expand Down Expand Up @@ -335,6 +335,53 @@ mod tests {
assert!(found_feature.name == *"James Bond");
}

#[tokio::test]
async fn memory_provider_can_update_data() {
let mut provider = MemoryProvider::default();
let token = EdgeToken {
environment: Some("development".into()),
projects: vec!["default".into()],
token: "some-secret".into(),
..EdgeToken::default()
};

let first_features = ClientFeatures {
version: 1,
features: vec![ClientFeature {
name: "James Bond".into(),
project: Some("default".into()),
..ClientFeature::default()
}],
segments: None,
query: None,
};
let second_features = ClientFeatures {
version: 1,
features: vec![ClientFeature {
name: "Jason Bourne".into(),
project: Some("default".into()),
..ClientFeature::default()
}],
segments: None,
query: None,
};

provider.sink_features(
&token,
second_features.clone(),
into_entity_tag(second_features),
);
provider.sink_features(
&token,
first_features.clone(),
into_entity_tag(first_features),
);

let all_features = provider.get_client_features(&token).await.unwrap().features;

assert!(all_features.len() == 2);
}

#[tokio::test]
async fn memory_provider_respects_all_projects_in_token() {
let mut provider = MemoryProvider::default();
Expand Down

0 comments on commit b8b25d3

Please sign in to comment.