refactor conf

This commit is contained in:
Marc Planard 2023-06-04 17:33:28 +02:00
parent 61ede78868
commit edba874ae7
6 changed files with 69 additions and 37 deletions

View file

@ -1,4 +1,5 @@
# file: valid.toml
# file: Settings.toml
# Rename me !
# The main key of your laser in LJ
laser_id = 0
@ -6,14 +7,14 @@ laser_id = 0
# Activate for more debug
debug = "true"
# Redis URL as IP:port
redis_url = "127.0.0.1"
# Redis URL as redis://IP:port/
redis_url = "redis://127.0.0.1:6379/"
# Either Helios or Etherdream
dac_family = "Helios"
# For Helios. USB Device Id of the DAC
dac_id = 0
[dac.helios]
id = 0
# For Etherdream. IP of the DAC
dac_url = "192.168.1.68"
# [dac.etherdream]
# url = "192.168.1.68"

View file

@ -0,0 +1,15 @@
# file: Settings.toml
# Rename me !
# The main key of your laser in LJ
laser_id = 0
# Activate for more debug
debug = "true"
# Redis URL as redis://IP:port/
redis_url = "redis://127.0.0.1:6379/"
# For Etherdream. IP of the DAC
[dac.etherdream]
url = "192.168.1.68"

View file

@ -1,4 +1,4 @@
use lj_rust::conf::{Conf, DacFamily};
use lj_rust::conf::{Conf, DacFamily, HeliosConf, EtherDreamConf};
#[test]
fn it_loads_a_valid_conf() {
@ -14,19 +14,21 @@ fn it_fails_invalid_conf() {
#[test]
fn it_finds_struct_fields() {
let config = match Conf::new("tests/settings/valid") {
Ok(c) => c,
Err(err) => {
panic!("Unable to load config file: {:?}", err)
}
};
assert_eq!(config.laser_id, u8::from(0));
let config = Conf::new("tests/settings/valid").unwrap();
assert_eq!(config.laser_id, 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,
assert_eq!(config.redis_url, "redis://127.0.0.1:6379/");
assert!(match config.dac {
DacFamily::Helios(HeliosConf { id: 0 }) => true,
_ => false,
});
}
#[test]
fn it_finds_etherdream_fields() {
let config = Conf::new("tests/settings/valid_etherdream").unwrap();
assert!(match config.dac {
DacFamily::Etherdream(EtherDreamConf { url }) if url == "192.168.1.68" => true,
_ => false,
});
assert_eq!(config.dac_id, Some(0));
assert_eq!(config.dac_url, Some(String::from("192.168.1.68")));
}