From 7889816a0b45932e6c799e70c91ed3e6f20f3fe0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 17 Mar 2023 08:03:39 -0600 Subject: [PATCH] tests pass --- src/config.rs | 7 +++++++ src/engine.rs | 21 ++++++++++++++++++--- src/testdata/config-device-to-stdout.yaml | 8 ++++++++ src/testdata/config-kinesis-to-kafka.json | 4 +++- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/testdata/config-device-to-stdout.yaml diff --git a/src/config.rs b/src/config.rs index 8be004f..103c62e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,11 @@ pub struct Stream { pub struct Engine { pub name: String, pub kafka: Option, + pub device: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Device { } #[derive(Serialize, Deserialize, Debug)] @@ -58,12 +63,14 @@ fn build_config_std() -> Config { engine: Engine{ name: String::from("stdin"), kafka: None, + device: None, }, }, output: Stream { engine: Engine{ name: String::from("stdout"), kafka: None, + device: None, }, }, }, diff --git a/src/engine.rs b/src/engine.rs index 2fc4830..f31d208 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -8,10 +8,25 @@ pub fn build_input_engine(cfg: &Engine) -> Result, String> match cfg.name.as_str() { "stdin" => return Ok(Box::new(InputEngineStdin{})), "kafka" => return build_input_engine_kafka(&cfg), + "device" => return build_input_engine_device(&cfg), _ => return Err("unknown input engine name".to_string() + &cfg.name), } } +struct InputEngineDevice { +} + +pub fn build_input_engine_device(cfg: &Engine) -> Result, String> { + let device_cfg = cfg.device.as_ref().unwrap(); + return Err("do what".to_string()); +} + +impl InputEngine for InputEngineDevice { + fn get(&mut self) -> Vec { + Err("end".to_string()).unwrap() + } +} + struct InputEngineKafka { } @@ -50,11 +65,11 @@ mod test_input { #[test] fn test_input_engine_impl() { - let input_engine_test = InputEngineTest{}; - _test_input_engine_impl(&input_engine_test); + let mut input_engine_test = InputEngineTest{}; + _test_input_engine_impl(&mut input_engine_test); } - fn _test_input_engine_impl(engine: &dyn InputEngine) { + fn _test_input_engine_impl(engine: &mut dyn InputEngine) { assert_eq!("hello world".to_string(), engine.get().iter().cloned().collect::()); } } diff --git a/src/testdata/config-device-to-stdout.yaml b/src/testdata/config-device-to-stdout.yaml new file mode 100644 index 0000000..5f6a098 --- /dev/null +++ b/src/testdata/config-device-to-stdout.yaml @@ -0,0 +1,8 @@ +streams: + input: + engine: + name: device + device: {} + output: + engine: + name: stdout diff --git a/src/testdata/config-kinesis-to-kafka.json b/src/testdata/config-kinesis-to-kafka.json index b2ea698..af334a1 100644 --- a/src/testdata/config-kinesis-to-kafka.json +++ b/src/testdata/config-kinesis-to-kafka.json @@ -14,7 +14,9 @@ "name": "kafka", "kafka": { "topic": "topic-name", - "consumer_group": "consumer-group-name" + "consumer_group": "consumer-group-name", + "addr": "", + "crt": "" } } }