Add a test for that underflow I fixed
This commit is contained in:
parent
c75e684f5b
commit
e0d1efb997
2 changed files with 32 additions and 0 deletions
|
|
@ -15,6 +15,11 @@ pub struct ServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerConfig {
|
impl ServerConfig {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn default() -> ServerConfig {
|
||||||
|
ServerConfig { auto: true, ports: HashMap::new() }
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -504,3 +504,30 @@ impl Drop for UI {
|
||||||
_ = self.leave_alternate_screen();
|
_ = self.leave_alternate_screen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use assert_matches::assert_matches;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn empty_ports() {
|
||||||
|
let (sender, receiver) = mpsc::channel(64);
|
||||||
|
let config = ServerConfig::default();
|
||||||
|
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(),
|
||||||
|
}])));
|
||||||
|
ui.selection.select(Some(0));
|
||||||
|
|
||||||
|
// ...but now there are no ports!
|
||||||
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![])));
|
||||||
|
assert_eq!(ui.ports.len(), 0);
|
||||||
|
assert_matches!(ui.selection.selected(), None);
|
||||||
|
|
||||||
|
drop(sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue