Skip to content

Commit

Permalink
added test for black snapshot and evalutor error
Browse files Browse the repository at this point in the history
  • Loading branch information
erka committed Apr 26, 2024
1 parent 0ab10f9 commit 14f7554
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
35 changes: 35 additions & 0 deletions flipt-engine-ffi/src/evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,38 @@ where
batch_evaluation(&self.store, &self.namespace, requests)
}
}
#[cfg(test)]
mod tests {
use super::*;
use fliptevaluation::models::source;
use fliptevaluation::parser;
use mockall::predicate::*;
use mockall::*;

mock! {
pub Parser{}
impl parser::Parser for Parser {
fn parse(&self, namespace: &str) -> Result<source::Document, Error>;
}
}

#[test]
fn test_batch_with_error() {
let mut parser = MockParser::new();
parser
.expect_parse()
.returning(|_| Err(Error::Server("can't connect".to_owned())));
let evaluator =
Evaluator::new_snapshot_evaluator("namespace", parser).expect("expect valid evaluator");
let requests = vec![];
let response = evaluator.batch(requests);
match response {
Err(err) => {
assert_eq!("server error: can't connect", err.to_string());
}
Ok(_) => {
panic!("expected error but got okay");
}
}
}
}
11 changes: 11 additions & 0 deletions flipt-evaluation/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,15 @@ mod tests {
}
assert_eq!(found, 2);
}

#[test]
fn test_blank_snapshot() {
let snapshot = Snapshot::blank("staging");
let namespace = snapshot.namespace;
assert_eq!("staging", namespace._key);
assert_eq!(0, namespace.flags.len());
assert_eq!(0, namespace.eval_rules.len());
assert_eq!(0, namespace.eval_distributions.len());
assert_eq!(0, namespace.eval_rollouts.len());
}
}

0 comments on commit 14f7554

Please sign in to comment.