#![cfg(test)]

use std::io::Write;

use crate::{doctor::FakeDoctor, host::Host, media::FakeOutputDevice};

fn test_name() -> String {
    "John".into()
}

fn test_host() -> Host {
    Host::new("http".into(), test_name())
}

#[test]
fn test_a_host_tested_success() {
    let result = test_host().test_by(&FakeDoctor::new(true));

    assert!(result.ok());
    assert_eq!(result.host_name(), test_name());
}

#[test]
fn test_print_to_output_device() {
    let mut fake_output_device = FakeOutputDevice::default();
    let result = test_host().test_by(&FakeDoctor::new(true));

    result.print_to(&mut fake_output_device);

    assert!(String::from_utf8_lossy(fake_output_device.last_write()).contains("good"));
}

#[test]
fn test_a_host_tested_fails() {
    let result = test_host().test_by(&FakeDoctor::new(false));

    assert!(!result.ok());
    assert_eq!(result.host_name(), test_name());
}

#[test]
fn test_aoeu() {
    let mut media = std::io::stdout();

    let _ = media.write_all("aoeu".as_bytes());
}
