aboutsummaryrefslogtreecommitdiffstats
path: root/tests/error.rs
blob: 67176db6a51f9358e3a79052c2a25687bc18c41c (plain) (blame)
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
30
31
32
33
34
35
36
37
extern crate wireguard;

use wireguard::WgError;
use std::error::Error;
use std::fmt::Write;
use std::io;

static TEST_STR: &'static str = "Some error message";

#[test]
fn success_convert_wg_from_io_error() {
    let io_error = io::Error::new(io::ErrorKind::NotFound, TEST_STR);
    let wg_error: WgError = io_error.into();
    assert_eq!(wg_error.description(), TEST_STR.to_string());
    assert_eq!(wg_error.kind(), io::ErrorKind::Other);
}

#[test]
fn success_convert_io_from_wg_error() {
    let wg_error = WgError::new(TEST_STR);
    let io_error: io::Error = wg_error.into();
    assert_eq!(io_error.description(), TEST_STR.to_string());
    assert_eq!(io_error.kind(), io::ErrorKind::Other);
}

#[test]
fn success_wg_error_display_debug() {
    let error = WgError::new(TEST_STR);
    let mut string = String::new();

    write!(string, "{}", error).unwrap();
    assert_eq!(string, TEST_STR);
    string.clear();

    write!(string, "{:?}", error).unwrap();
    assert_eq!(string, TEST_STR);
}