Skip to content

Commit

Permalink
test: add new integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bconn98 committed Mar 4, 2024
1 parent 3b6a5bb commit 1260ca0
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 24 deletions.
13 changes: 13 additions & 0 deletions test_cfgs/malformed_appender.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
refresh_rate: 5 seconds

appenders:
file:
kind: file
pah: "log/file.log"
encoder:
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"

root:
level: info
appenders:
- file
51 changes: 51 additions & 0 deletions test_cfgs/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"refresh_rate": "5 seconds",
"appenders": {
"stdout": {
"kind": "console",
"encoder": {
"pattern": "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"
},
"filters": [
{
"kind": "threshold",
"level": "info"
}
]
},
"file": {
"kind": "file",
"path": "log/file.log",
"encoder": {
"pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
}
},
"rollingfile": {
"kind": "rolling_file",
"path": "log/rolling_file.log",
"encoder": {
"pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
},
"policy": {
"trigger": {
"kind": "time",
"interval": "1 minute"
},
"roller": {
"kind": "fixed_window",
"pattern": "log/old-rolling_file-{}.log",
"base": 0,
"count": 2
}
}
}
},
"root": {
"level": "info",
"appenders": [
"stdout",
"file",
"rollingfile"
]
}
}
39 changes: 39 additions & 0 deletions test_cfgs/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
refresh_rate = "5 seconds"

[appenders.stdout]
kind = "console"

[appenders.stdout.encoder]
pattern = "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"

[[appenders.stdout.filters]]
kind = "threshold"
level = "info"

[appenders.file]
kind = "file"
path = "log/file.log"

[appenders.file.encoder]
pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"

[appenders.rollingfile]
kind = "rolling_file"
path = "log/rolling_file.log"

[appenders.rollingfile.encoder]
pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"

[appenders.rollingfile.policy.trigger]
kind = "time"
interval = "1 minute"

[appenders.rollingfile.policy.roller]
kind = "fixed_window"
pattern = "log/old-rolling_file-{}.log"
base = 0
count = 2

[root]
level = "info"
appenders = [ "stdout", "file", "rollingfile" ]
36 changes: 36 additions & 0 deletions test_cfgs/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
refresh_rate: 5 seconds

appenders:
stdout:
kind: console
encoder:
pattern: "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"
filters:
- kind: threshold
level: info
file:
kind: file
path: "log/file.log"
encoder:
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
rollingfile:
kind: rolling_file
path: "log/rolling_file.log"
encoder:
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
policy:
trigger:
kind: time
interval: 1 minute
roller:
kind: fixed_window
pattern: "log/old-rolling_file-{}.log"
base: 0
count: 2

root:
level: info
appenders:
- stdout
- file
- rollingfile
24 changes: 0 additions & 24 deletions tests/color_control.rs

This file was deleted.

12 changes: 12 additions & 0 deletions tests/init_json_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[test]
#[cfg(all(feature = "config_parsing", feature = "json_format"))]
fn test_init_json_cfg() {
use log4rs;
use std::path::Path;

assert!(log4rs::init_file(
Path::new("./test_cfgs/test.json"),
log4rs::config::Deserializers::default()
)
.is_ok());
}
14 changes: 14 additions & 0 deletions tests/init_malformed_appenders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[test]
#[cfg(all(feature = "config_parsing", feature = "yaml_format"))]
fn test_malformed_appenders() {
use std::fs;

let config_str = fs::read_to_string("test_cfgs/malformed_appender.yml").unwrap();
let cfg = ::serde_yaml::from_str::<log4rs::config::RawConfig>(&config_str);

assert!(cfg.is_ok());
let cfg = cfg.unwrap();

let res = log4rs::config::create_raw_config(cfg);
assert!(res.is_err());
}
12 changes: 12 additions & 0 deletions tests/init_toml_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[test]
#[cfg(all(feature = "config_parsing", feature = "toml_format"))]
fn test_init_toml_cfg() {
use log4rs;
use std::path::Path;

assert!(log4rs::init_file(
Path::new("./test_cfgs/test.toml"),
log4rs::config::Deserializers::default()
)
.is_ok());
}
12 changes: 12 additions & 0 deletions tests/init_yaml_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[test]
#[cfg(all(feature = "config_parsing", feature = "yaml_format"))]
fn test_init_yaml_cfg() {
use log4rs;
use std::path::Path;

assert!(log4rs::init_file(
Path::new("./test_cfgs/test.yml"),
log4rs::config::Deserializers::default()
)
.is_ok());
}

0 comments on commit 1260ca0

Please sign in to comment.