use assert_cmd::Command;

fn b_doc_cmd() -> Command {
    Command::cargo_bin("b-doc").unwrap()
}

#[test]
fn test_cli_no_file_fails() {
    b_doc_cmd()
        .write_stdin("")
        .assert()
        .failure()
        .stderr(predicates::str::contains("EOF"));
}

#[test]
#[ignore]
fn test_cli_success_with_timeout() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hosts_01.json", "-t", "10"])
        .assert()
        .success();
}

#[test]
#[ignore]
fn test_cli_success_with_concurrent_test() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hosts_01.json", "-c", "10"])
        .assert()
        .success();
}

#[test]
#[ignore]
fn test_cli_fails_on_timeout() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hosts_01.json", "-t", "0"])
        .assert()
        .success()
        .stdout(predicates::str::contains(
            "the timeout of the request was reached",
        ));
}

#[test]
#[ignore]
fn test_cli_success_with_default_values() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hosts_01.json"])
        .assert()
        .success();
}

#[test]
#[ignore]
fn test_cli_stdin_success() {
    b_doc_cmd()
        .args(["-t", "10"])
        .write_stdin(
            r#"
            {"hosts": [{ "name": "Google", "url": "https://google.com" }]}
            "#,
        )
        .assert()
        .success();
}

#[test]
fn test_cli_fails_on_not_exists_file() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hostss.toml"])
        .assert()
        .failure()
        .stderr(predicates::str::contains("No such file"));
}

#[test]
fn test_cli_fails_on_wrong_format_file() {
    b_doc_cmd()
        .args(["-f", "tests/inputs/hosts_bad.json"])
        .assert()
        .failure();
}
