rsiot/components_config/influxdb_v2/config.rs
1//! Тестирование:
2//!
3//! ```bash
4//! cargo test -p rsiot-components-config --doc influxdb_v2
5//! ```
6
7use crate::message::*;
8
9use super::LineProtocolItem;
10
11/// Конфигурация cmp_influxdb
12#[derive(Clone, Debug)]
13pub struct Config<TMsg> {
14 /// # Примеры
15 ///
16 /// ```ignore
17 /// host: String::from("influxdb"),
18 /// ```
19 pub host: String,
20
21 /// Порт базы данных
22 pub port: u16,
23
24 /// Огранизация
25 pub org: String,
26
27 /// Bucket
28 pub bucket: String,
29
30 /// Токен
31 pub token: String,
32
33 /// Функция преобразования сообщения в строки протокола InfluxDB
34 ///
35 /// # Примеры
36 ///
37 /// ## Заглушка
38 ///
39 /// ```rust
40 /// # use rsiot_components_config::influxdb_v2 as cmp_influxdb;
41 /// # // insert from tests::stub
42 /// # use rsiot_messages_core::example_message::*;
43 /// # cmp_influxdb::Config::<Custom> {
44 /// # host: String::from("influxdb"),
45 /// # port: 8086,
46 /// # org: String::from("org"),
47 /// # bucket: String::from("bucket"),
48 /// # token: String::from("token"),
49 /// fn_input: |_| None,
50 /// # };
51 /// ```
52 ///
53 /// ## Сохранение Custom
54 ///
55 /// ```rust
56 /// # use rsiot_components_config::influxdb_v2 as cmp_influxdb;
57 /// # // start tests::fn_input
58 /// # use rsiot_messages_core::{example_message::*, *};
59 /// # cmp_influxdb::Config::<Custom> {
60 /// # host: String::from("influxdb"),
61 /// # port: 8086,
62 /// # org: String::from("org"),
63 /// # bucket: String::from("bucket"),
64 /// # token: String::from("token"),
65 /// fn_input: |msg: &Message<Custom>| {
66 /// let value = match &msg.data {
67 /// MsgData::Custom(data) => match data {
68 /// Custom::ValueInstantF64(data) => {
69 /// cmp_influxdb::ValueType::f64(*data)
70 /// }
71 /// _ => return None,
72 /// },
73 /// _ => return None,
74 /// };
75 /// let line = cmp_influxdb::LineProtocolItem::new(&msg.key, value, &msg.ts);
76 /// Some(vec![line])
77 /// },
78 /// # };
79 /// # // end
80 /// ```
81 pub fn_input: fn(&Message<TMsg>) -> Option<Vec<LineProtocolItem>>,
82}
83
84#[cfg(test)]
85mod test {
86 use super::super::super::influxdb_v2 as cmp_influxdb;
87
88 #[test]
89 fn stub() {
90 use crate::message::example_message::*;
91 let _ = cmp_influxdb::Config::<Custom> {
92 host: String::from("influxdb"),
93 port: 8086,
94 org: String::from("org"),
95 bucket: String::from("bucket"),
96 token: String::from("token"),
97 fn_input: |_| None,
98 };
99 }
100
101 #[test]
102 fn fn_input() {
103 use crate::message::{example_message::*, *};
104 let _ = cmp_influxdb::Config::<Custom> {
105 host: String::from("influxdb"),
106 port: 8086,
107 org: String::from("org"),
108 bucket: String::from("bucket"),
109 token: String::from("token"),
110 fn_input: |msg: &Message<Custom>| {
111 let value = match &msg.data {
112 MsgData::Custom(Custom::ValueInstantF64(data)) => {
113 cmp_influxdb::ValueType::f64(*data)
114 }
115 _ => return None,
116 };
117 let line = cmp_influxdb::LineProtocolItem::new(&msg.key, value, &msg.ts);
118 Some(vec![line])
119 },
120 };
121 }
122}