rsiot/components_config/influxdb3/
config.rs1use std::time::Duration;
8
9use crate::message::*;
10
11use super::LineProtocolItem;
12
13pub type FnInput<TMsg> = fn(&Message<TMsg>) -> Option<Vec<LineProtocolItem>>;
14
15#[derive(Clone, Debug)]
17pub struct Config<TMsg> {
18 pub host: String,
24
25 pub port: u16,
27
28 pub database: String,
30
31 pub send_period: Duration,
33
34 pub fn_input: FnInput<TMsg>,
36}
37
38#[cfg(test)]
39mod test {
40 use super::super::super::influxdb_v2 as cmp_influxdb;
41
42 #[test]
43 fn stub() {
44 use crate::message::example_message::*;
45 let _ = cmp_influxdb::Config::<Custom> {
46 host: String::from("influxdb"),
47 port: 8086,
48 org: String::from("org"),
49 bucket: String::from("bucket"),
50 token: String::from("token"),
51 fn_input: |_| None,
52 };
53 }
54
55 #[test]
56 fn fn_input() {
57 use crate::message::{example_message::*, *};
58 let _ = cmp_influxdb::Config::<Custom> {
59 host: String::from("influxdb"),
60 port: 8086,
61 org: String::from("org"),
62 bucket: String::from("bucket"),
63 token: String::from("token"),
64 fn_input: |msg: &Message<Custom>| {
65 let value = match &msg.data {
66 MsgData::Custom(Custom::ValueInstantF64(data)) => {
67 cmp_influxdb::ValueType::f64(*data)
68 }
69 _ => return None,
70 };
71 let line = cmp_influxdb::LineProtocolItem::new(&msg.key, value, &msg.ts);
72 Some(vec![line])
73 },
74 };
75 }
76}