Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #358

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
Loading