diff --git a/tests/common.rs b/tests/common.rs index 3a85ffb..5c50f35 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -13,6 +13,14 @@ pub fn search_start() -> SearchChannel { SearchChannel::start(HOST, PASS).expect("The Sonic server must be running") } +pub fn control_start() -> ControlChannel { + ControlChannel::start(HOST, PASS).expect("The Sonic server must be running") +} + +pub fn consolidate() { + control_start().consolidate().unwrap(); +} + pub fn flush_bucket(collection: &str, bucket: &str) { ingest_start().flushb(collection, bucket).unwrap(); } diff --git a/tests/suggest_command.rs b/tests/suggest_command.rs new file mode 100644 index 0000000..62ee0e5 --- /dev/null +++ b/tests/suggest_command.rs @@ -0,0 +1,32 @@ +mod common; +use common::*; + +const COLLECTION: &str = "Search"; + +#[test] +fn should_suggest_nearest_word() { + let bucket = "suggest_nearest"; + let title = "Sweet Teriyaki Beef Skewers"; + + let ingest_channel = ingest_start(); + ingest_channel.push(COLLECTION, bucket, "1", title).unwrap(); + + consolidate(); + + let pairs = [ + ("Sweat", "sweet"), + ("teriaki", "teriyaki"), + ("Beff", "beef"), + ("skwers", "skewers"), + ]; + + let search_channel = search_start(); + for (input, expected) in pairs { + match search_channel.suggest(COLLECTION, bucket, input) { + Ok(object_ids) => assert_eq!(object_ids, vec![expected]), + Err(_) => unreachable!(), + } + } + + flush_bucket(COLLECTION, bucket); +}