Added port, host and noart options in config file

next
Sayan Nandan 4 years ago
parent 86d15120e4
commit 914b1f06e3
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

1
Cargo.lock generated

@ -512,6 +512,7 @@ dependencies = [
"libtdb",
"parking_lot",
"serde",
"serde_derive",
"tokio",
"toml",
]

@ -0,0 +1,4 @@
[server]
host = '127.0.0.1' # i.e localhost
port = 2003 # The port to bind to
noart = true # No terminal artwork

@ -1,4 +1,5 @@
# This is a 'good' configuration file since it contains a valid port
# and appropriate keys
[server]
host = '127.0.0.1'
port = 2003 # Set the server's port to 2003

@ -13,6 +13,7 @@ libtdb = {path ="../libtdb"}
bincode = "1.3.1"
parking_lot = "0.11.0"
lazy_static = "1.4.0"
serde_derive = "1.0.115"
serde = {version = "1.0.115", features= ["derive"]}
toml = "0.5.6"
clap = {version = "2.33.3", features=["yaml"]}

@ -32,7 +32,9 @@ struct Config {
#[derive(Deserialize, Debug, PartialEq)]
struct ServerConfig {
host: String,
port: u16,
noart: Option<bool>,
}
impl Config {
@ -47,6 +49,7 @@ impl Config {
fn test_config_toml_okayport() {
let file = r#"
[server]
host = "127.0.0.1"
port = 2003
"#
.to_owned();
@ -54,7 +57,11 @@ fn test_config_toml_okayport() {
assert_eq!(
cfg,
Config {
server: ServerConfig { port: 2003 }
server: ServerConfig {
port: 2003,
host: "127.0.0.1".to_owned(),
noart: None,
}
}
);
}
@ -80,7 +87,11 @@ fn test_config_file_ok() {
assert_eq!(
cfg,
Config {
server: ServerConfig { port: 2003 }
server: ServerConfig {
port: 2003,
host: "127.0.0.1".to_owned(),
noart: None,
}
}
);
}
@ -96,7 +107,7 @@ fn test_config_file_err() {
use clap::{load_yaml, App};
/// Get the command line arguments
pub fn get_args() -> Option<String> {
pub fn get_config_file() -> Option<String> {
let cfg_layout = load_yaml!("../cli.yml");
let matches = App::from_yaml(cfg_layout).get_matches();
let filename = matches.value_of("config");
@ -115,7 +126,29 @@ fn test_args() {
assert_eq!(
cfg,
Config {
server: ServerConfig { port: 2003 }
server: ServerConfig {
port: 2003,
host: "127.0.0.1".to_owned(),
noart: None,
}
}
);
}
#[test]
#[cfg(test)]
fn test_config_file_noart() {
let fileloc = "../examples/config-files/secure-noart.toml";
let file = std::fs::read_to_string(fileloc).unwrap();
let cfg: Config = Config::new(file).unwrap();
assert_eq!(
cfg,
Config {
server: ServerConfig {
port: 2003,
host: "127.0.0.1".to_owned(),
noart: Some(true),
}
}
);
}

Loading…
Cancel
Save