Skip to content

Commit 1260ca0

Browse files
committed
test: add new integration tests
1 parent 3b6a5bb commit 1260ca0

9 files changed

+189
-24
lines changed

test_cfgs/malformed_appender.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
refresh_rate: 5 seconds
2+
3+
appenders:
4+
file:
5+
kind: file
6+
pah: "log/file.log"
7+
encoder:
8+
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
9+
10+
root:
11+
level: info
12+
appenders:
13+
- file

test_cfgs/test.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"refresh_rate": "5 seconds",
3+
"appenders": {
4+
"stdout": {
5+
"kind": "console",
6+
"encoder": {
7+
"pattern": "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"
8+
},
9+
"filters": [
10+
{
11+
"kind": "threshold",
12+
"level": "info"
13+
}
14+
]
15+
},
16+
"file": {
17+
"kind": "file",
18+
"path": "log/file.log",
19+
"encoder": {
20+
"pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
21+
}
22+
},
23+
"rollingfile": {
24+
"kind": "rolling_file",
25+
"path": "log/rolling_file.log",
26+
"encoder": {
27+
"pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
28+
},
29+
"policy": {
30+
"trigger": {
31+
"kind": "time",
32+
"interval": "1 minute"
33+
},
34+
"roller": {
35+
"kind": "fixed_window",
36+
"pattern": "log/old-rolling_file-{}.log",
37+
"base": 0,
38+
"count": 2
39+
}
40+
}
41+
}
42+
},
43+
"root": {
44+
"level": "info",
45+
"appenders": [
46+
"stdout",
47+
"file",
48+
"rollingfile"
49+
]
50+
}
51+
}

test_cfgs/test.toml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
refresh_rate = "5 seconds"
2+
3+
[appenders.stdout]
4+
kind = "console"
5+
6+
[appenders.stdout.encoder]
7+
pattern = "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"
8+
9+
[[appenders.stdout.filters]]
10+
kind = "threshold"
11+
level = "info"
12+
13+
[appenders.file]
14+
kind = "file"
15+
path = "log/file.log"
16+
17+
[appenders.file.encoder]
18+
pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
19+
20+
[appenders.rollingfile]
21+
kind = "rolling_file"
22+
path = "log/rolling_file.log"
23+
24+
[appenders.rollingfile.encoder]
25+
pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
26+
27+
[appenders.rollingfile.policy.trigger]
28+
kind = "time"
29+
interval = "1 minute"
30+
31+
[appenders.rollingfile.policy.roller]
32+
kind = "fixed_window"
33+
pattern = "log/old-rolling_file-{}.log"
34+
base = 0
35+
count = 2
36+
37+
[root]
38+
level = "info"
39+
appenders = [ "stdout", "file", "rollingfile" ]

test_cfgs/test.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
refresh_rate: 5 seconds
2+
3+
appenders:
4+
stdout:
5+
kind: console
6+
encoder:
7+
pattern: "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}"
8+
filters:
9+
- kind: threshold
10+
level: info
11+
file:
12+
kind: file
13+
path: "log/file.log"
14+
encoder:
15+
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
16+
rollingfile:
17+
kind: rolling_file
18+
path: "log/rolling_file.log"
19+
encoder:
20+
pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
21+
policy:
22+
trigger:
23+
kind: time
24+
interval: 1 minute
25+
roller:
26+
kind: fixed_window
27+
pattern: "log/old-rolling_file-{}.log"
28+
base: 0
29+
count: 2
30+
31+
root:
32+
level: info
33+
appenders:
34+
- stdout
35+
- file
36+
- rollingfile

tests/color_control.rs

-24
This file was deleted.

tests/init_json_config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[test]
2+
#[cfg(all(feature = "config_parsing", feature = "json_format"))]
3+
fn test_init_json_cfg() {
4+
use log4rs;
5+
use std::path::Path;
6+
7+
assert!(log4rs::init_file(
8+
Path::new("./test_cfgs/test.json"),
9+
log4rs::config::Deserializers::default()
10+
)
11+
.is_ok());
12+
}

tests/init_malformed_appenders.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[test]
2+
#[cfg(all(feature = "config_parsing", feature = "yaml_format"))]
3+
fn test_malformed_appenders() {
4+
use std::fs;
5+
6+
let config_str = fs::read_to_string("test_cfgs/malformed_appender.yml").unwrap();
7+
let cfg = ::serde_yaml::from_str::<log4rs::config::RawConfig>(&config_str);
8+
9+
assert!(cfg.is_ok());
10+
let cfg = cfg.unwrap();
11+
12+
let res = log4rs::config::create_raw_config(cfg);
13+
assert!(res.is_err());
14+
}

tests/init_toml_config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[test]
2+
#[cfg(all(feature = "config_parsing", feature = "toml_format"))]
3+
fn test_init_toml_cfg() {
4+
use log4rs;
5+
use std::path::Path;
6+
7+
assert!(log4rs::init_file(
8+
Path::new("./test_cfgs/test.toml"),
9+
log4rs::config::Deserializers::default()
10+
)
11+
.is_ok());
12+
}

tests/init_yaml_config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[test]
2+
#[cfg(all(feature = "config_parsing", feature = "yaml_format"))]
3+
fn test_init_yaml_cfg() {
4+
use log4rs;
5+
use std::path::Path;
6+
7+
assert!(log4rs::init_file(
8+
Path::new("./test_cfgs/test.yml"),
9+
log4rs::config::Deserializers::default()
10+
)
11+
.is_ok());
12+
}

0 commit comments

Comments
 (0)