Skip to content

Commit

Permalink
More concise TestFilter ctx.values manipulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmandel committed Sep 17, 2020
1 parent 75e232c commit f2ba1b1
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,10 @@ impl Filter for TestFilter {
ctx.endpoints.push(noop_endpoint());

// append values on each run
let key = "downstream";
match ctx.values.get(key) {
None => {
ctx.values
.insert(key.into(), Box::new("receive".to_string()));
}
Some(value) => {
let mut value = value.downcast_ref::<String>().unwrap().clone();
value.push_str(":receive");
ctx.values.insert(key.into(), Box::new(value));
}
}
ctx.values
.entry("downstream".into())
.and_modify(|e| e.downcast_mut::<String>().unwrap().push_str(":receive"))
.or_insert(Box::new("receive".to_string()));

ctx.contents
.append(&mut format!(":odr:{}", ctx.from).into_bytes());
Expand All @@ -84,18 +76,11 @@ impl Filter for TestFilter {

fn on_upstream_receive(&self, mut ctx: UpstreamContext) -> Option<UpstreamResponse> {
// append values on each run
let key = "upstream";
match ctx.values.get(key) {
None => {
ctx.values
.insert(key.into(), Box::new("receive".to_string()));
}
Some(value) => {
let mut value = value.downcast_ref::<String>().unwrap().clone();
value.push_str(":receive");
ctx.values.insert(key.into(), Box::new(value));
}
}
ctx.values
.entry("upstream".into())
.and_modify(|e| e.downcast_mut::<String>().unwrap().push_str(":receive"))
.or_insert(Box::new("receive".to_string()));

ctx.contents.append(
&mut format!(":our:{}:{}:{}", ctx.endpoint.name, ctx.from, ctx.to).into_bytes(),
);
Expand Down

0 comments on commit f2ba1b1

Please sign in to comment.