Skip to content

Commit a3770bc

Browse files
authored
Merge pull request #114 from G-Core/fix/victoria_log_feature
add support for victoria_log feature with deserialization tests
2 parents 1f4b311 + 9dd93ac commit a3770bc

4 files changed

Lines changed: 68 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.14.0"
6+
version = "0.14.1"
77
edition = "2021"
88
publish = false
99
authors = ["FastEdge Development Team"]

crates/runtime/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ publish.workspace = true
66
authors.workspace = true
77

88
[features]
9-
default = ["kafka_log"]
9+
default = ["kafka_log", "victoria_log"]
1010
kafka_log = []
11+
victoria_log = []
1112
metrics = ["prometheus", "lazy_static"]
1213

1314
[dependencies]

crates/runtime/src/app.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pub enum Log {
7979
None,
8080
#[cfg(feature = "kafka_log")]
8181
Kafka,
82+
#[cfg(feature = "victoria_log")]
83+
Victoria,
8284
}
8385

8486
#[derive(Debug, Clone, PartialEq)]
@@ -192,6 +194,61 @@ mod tests {
192194
assert_eq!(expected, assert_ok!(serde_json::from_str(&json)));
193195
}
194196

197+
#[test]
198+
fn test_log_deserialize_default() {
199+
let log: Log = assert_ok!(serde_json::from_str("\"none\""));
200+
assert_eq!(log, Log::None);
201+
}
202+
203+
#[test]
204+
fn test_log_deserialize_missing_defaults_to_none() {
205+
#[derive(Deserialize)]
206+
struct Wrapper {
207+
#[serde(default)]
208+
log: Log,
209+
}
210+
let w: Wrapper = assert_ok!(serde_json::from_str("{}"));
211+
assert_eq!(w.log, Log::None);
212+
}
213+
214+
#[cfg(feature = "kafka_log")]
215+
#[test]
216+
fn test_log_deserialize_kafka() {
217+
let log: Log = assert_ok!(serde_json::from_str("\"kafka\""));
218+
assert_eq!(log, Log::Kafka);
219+
}
220+
221+
#[cfg(feature = "victoria_log")]
222+
#[test]
223+
fn test_log_deserialize_victoria_logs() {
224+
let log: Log = assert_ok!(serde_json::from_str("\"victoria\""));
225+
assert_eq!(log, Log::Victoria);
226+
}
227+
228+
#[cfg(feature = "victoria_log")]
229+
#[test]
230+
fn deserialize_app_with_victoria_log() {
231+
let json = json!({
232+
"binary_id": 1,
233+
"max_duration": 5,
234+
"mem_limit": 512000,
235+
"app_id": 1,
236+
"client_id": 2,
237+
"plan": "basic",
238+
"plan_id": 0,
239+
"status": 1,
240+
"log": "victoria"
241+
});
242+
let json = assert_ok!(serde_json::to_string(&json));
243+
let app: App = assert_ok!(serde_json::from_str(&json));
244+
assert_eq!(app.log, Log::Victoria);
245+
}
246+
247+
#[test]
248+
fn test_log_deserialize_invalid() {
249+
assert_err!(serde_json::from_str::<Log>("\"unknown\""));
250+
}
251+
195252
#[test]
196253
fn test_kv_store_option_deserialize_defaults() {
197254
let json = r#"{

0 commit comments

Comments
 (0)