diff --git a/src/config.rs b/src/config.rs index 33d8684..4dc15d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,7 +66,7 @@ mod tests { #[test] fn test_build_config_yaml() { - build_config_yaml("./src/testdata/config-kinesis-to-kafka.json".to_string()); - build_config_yaml("./src/testdata/config-stdin-to-stdout.yaml".to_string()); + build_config_yaml("./src/testdata/config-kinesis-to-kafka.json".to_string()).unwrap(); + build_config_yaml("./src/testdata/config-stdin-to-stdout.yaml".to_string()).unwrap(); } } diff --git a/src/engine.rs b/src/engine.rs index a64a17c..048514b 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -23,7 +23,7 @@ impl InputEngine for InputEngineStdin { } #[cfg(test)] -mod test { +mod test_input { use super::*; struct InputEngineTest {} @@ -43,3 +43,43 @@ mod test { assert_eq!("hello world".to_string(), engine.get()); } } + +pub trait OutputEngine { + fn put(&self, v: String); +} + +pub fn build_output_engine(cfg: &Engine) -> Result, String> { + match cfg.name.as_str() { + "stdout" => return Ok(Box::new(OutputEngineStdout{})), + _ => return Err("unknown output engine name".to_string() + &cfg.name), + } +} + +struct OutputEngineStdout {} + +impl OutputEngine for OutputEngineStdout { + fn put(&self, v: String) { + println!("{}", v); + } +} + +#[cfg(test)] +mod test_output { + use super::*; + + struct OutputEngineTest {} + impl OutputEngine for OutputEngineTest { + fn put(&self, _v: String) { + } + } + + #[test] + fn test_output_engine_impl() { + let output_engine_test = OutputEngineTest{}; + _test_output_engine_impl(&output_engine_test); + } + + fn _test_output_engine_impl(engine: &dyn OutputEngine) { + engine.put("teehee".to_string()); + } +} diff --git a/src/main.rs b/src/main.rs index c63dfc7..6189a58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ mod engine; fn main() { let cfg = config::build_config().unwrap(); let input_engine = engine::build_input_engine(&cfg.streams.input.engine); + let output_engine = engine::build_output_engine(&cfg.streams.output.engine); println!("{:?} => {}", cfg.streams.input.engine.name, input_engine.is_ok()); - println!("{}", input_engine.unwrap().get()); + println!("{:?} => {}", cfg.streams.output.engine.name, output_engine.is_ok()); + output_engine.unwrap().put(input_engine.unwrap().get()); }