File: no_server.rs

package info (click to toggle)
rust-interprocess 2.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,016 kB
  • sloc: makefile: 2
file content (29 lines) | stat: -rw-r--r-- 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Tests what happens when a client attempts to connect to a local socket that doesn't exist.

use {
    crate::{
        local_socket::{prelude::*, Stream},
        tests::util::*,
    },
    color_eyre::eyre::{bail, ensure},
    std::io,
};

pub fn run_and_verify_error(id: &str, path: bool) -> TestResult {
    use io::ErrorKind::*;
    let err = match client(id, path) {
        Err(e) => e,
        Ok(()) => bail!("client successfully connected to nonexistent server"),
    };
    ensure!(
        matches!(err.kind(), NotFound | ConnectionRefused),
        "expected error to be 'not found' or 'connection refused', received '{}'",
        err
    );
    Ok(())
}
fn client(id: &str, path: bool) -> io::Result<()> {
    let nm = namegen_local_socket(id, path).next().unwrap();
    Stream::connect(nm?.borrow())?;
    Ok(())
}