feat: add tests for conf
This commit is contained in:
parent
ae14cb600d
commit
312a48ff5b
4 changed files with 56 additions and 11 deletions
0
tests/settings/empty.toml
Normal file
0
tests/settings/empty.toml
Normal file
19
tests/settings/valid.toml
Normal file
19
tests/settings/valid.toml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# file: valid.toml
|
||||
|
||||
# The main key of your laser in LJ
|
||||
laser_id = 0
|
||||
|
||||
# Activate for more debug
|
||||
debug = "true"
|
||||
|
||||
# Redis URL as IP:port
|
||||
redis_url = "127.0.0.1"
|
||||
|
||||
# Either Helios or Etherdream
|
||||
dac_family = "Helios"
|
||||
|
||||
# For Helios. USB Device Id of the DAC
|
||||
dac_id = 0
|
||||
|
||||
# For Etherdream. IP of the DAC
|
||||
dac_url = "192.168.1.68"
|
||||
|
|
@ -1,6 +1,32 @@
|
|||
use lj_rust::conf;
|
||||
use lj_rust::conf::{load_config, DacFamily};
|
||||
|
||||
#[test]
|
||||
fn it_adds_two() {
|
||||
assert_eq!(4, 4);
|
||||
}
|
||||
fn it_loads_a_valid_conf() {
|
||||
let result = load_config("tests/settings/valid");
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_fails_invalid_conf() {
|
||||
let result = load_config("tests/settings/empty");
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_finds_struct_fields() {
|
||||
let config = match load_config("tests/settings/valid") {
|
||||
Ok(c) => c,
|
||||
Err(err) => {
|
||||
panic!("Unable to load config file: {:?}", err)
|
||||
}
|
||||
};
|
||||
assert_eq!(config.laser_id, u8::from(0));
|
||||
assert_eq!(config.debug, true);
|
||||
assert_eq!(config.redis_url, String::from("127.0.0.1"));
|
||||
assert!(match config.dac_family {
|
||||
DacFamily::Helios => true,
|
||||
_ => false,
|
||||
});
|
||||
assert_eq!(config.dac_id, Some(0));
|
||||
assert_eq!(config.dac_url, Some(String::from("192.168.1.68")));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue