Additional tests for configuration
This commit is contained in:
parent
e1768a0433
commit
6736cdd431
2 changed files with 59 additions and 0 deletions
|
|
@ -20,6 +20,11 @@ impl ServerConfig {
|
||||||
ServerConfig { auto: true, ports: HashMap::new() }
|
ServerConfig { auto: true, ports: HashMap::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn insert(&mut self, port: u16, config: PortConfig) {
|
||||||
|
self.ports.insert(port, config);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn contains_key(&self, port: u16) -> bool {
|
pub fn contains_key(&self, port: u16) -> bool {
|
||||||
self.ports.contains_key(&port)
|
self.ports.contains_key(&port)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -674,6 +674,8 @@ fn centered_rect(width_chars: u16, height_chars: u16, r: Rect) -> Rect {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::client::config::PortConfig;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
|
|
||||||
|
|
@ -938,4 +940,56 @@ mod tests {
|
||||||
assert_eq!(centered.width, 10);
|
assert_eq!(centered.width, 10);
|
||||||
assert_eq!(centered.height, 10);
|
assert_eq!(centered.height, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn port_config_description_respected() {
|
||||||
|
let (sender, receiver) = mpsc::channel(64);
|
||||||
|
let mut config = ServerConfig::default();
|
||||||
|
config.insert(
|
||||||
|
8080,
|
||||||
|
PortConfig {
|
||||||
|
enabled: true,
|
||||||
|
description: Some("override".to_string()),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut ui = UI::new(receiver, config);
|
||||||
|
|
||||||
|
// There are ports...
|
||||||
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![PortDesc {
|
||||||
|
port: 8080,
|
||||||
|
desc: "my-service".to_string(),
|
||||||
|
}])));
|
||||||
|
|
||||||
|
let description = ui.ports.get(&8080).unwrap().desc.as_ref().unwrap();
|
||||||
|
assert_eq!(description.desc, "override");
|
||||||
|
|
||||||
|
drop(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn port_config_enabled_respected() {
|
||||||
|
let (sender, receiver) = mpsc::channel(64);
|
||||||
|
let mut config = ServerConfig::default();
|
||||||
|
config.insert(
|
||||||
|
8080,
|
||||||
|
PortConfig {
|
||||||
|
enabled: false,
|
||||||
|
description: Some("override".to_string()),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut ui = UI::new(receiver, config);
|
||||||
|
|
||||||
|
// There are ports...
|
||||||
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![PortDesc {
|
||||||
|
port: 8080,
|
||||||
|
desc: "my-service".to_string(),
|
||||||
|
}])));
|
||||||
|
|
||||||
|
let state = ui.ports.get(&8080).unwrap().state();
|
||||||
|
assert_eq!(state, State::Disabled);
|
||||||
|
|
||||||
|
drop(sender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue