File: no_server.rs

package info (click to toggle)
rust-interprocess 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 980 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 863 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
//! Tests what happens when a client attempts to connect to a local socket that doesn't exist.

use {super::util::*, anyhow::*, interprocess::local_socket::LocalSocketStream, std::io};
use std::result::Result::Ok;

pub fn run_and_verify_error(prefer_namespaced: bool) -> TestResult {
    use io::ErrorKind::*;
    let err = match client(prefer_namespaced) {
        Err(e) => e.downcast::<io::Error>()?,
        Ok(()) => bail!("client successfully connected to nonexistent server"),
    };
    ensure!(
        matches!(err.kind(), NotFound | ConnectionRefused),
        "expected error to be 'not found', received '{}'",
        err
    );
    Ok(())
}
fn client(prefer_namespaced: bool) -> TestResult {
    let name = NameGen::new_auto(prefer_namespaced).next().unwrap();

    LocalSocketStream::connect(name.as_str()).context("Connect failed")?;
    Ok(())
}