#![cfg(feature = "git")]
mod common;
use assert_cmd::prelude::*;
use common::dircat_cmd;
use predicates::prelude::*;
use tempfile::tempdir;
#[test]
#[ignore = "requires network access and is slow"]
fn test_api_download_public_directory() -> Result<(), Box<dyn std::error::Error>> {
let repo_folder_url = "https://github.com/git-fixtures/basic/tree/master/go";
let temp_cache = tempdir()?;
dircat_cmd()
.arg(repo_folder_url)
.env("DIRCAT_TEST_CACHE_DIR", temp_cache.path())
.assert()
.success()
.stdout(predicate::str::contains("## File: example.go"))
.stdout(predicate::str::contains("package harvesterd"))
.stdout(predicate::str::contains("## File: CHANGELOG").not())
.stdout(predicate::str::contains("## File: LICENSE").not());
Ok(())
}
#[test]
#[ignore = "requires network access and is slow"]
fn test_api_download_public_blob_url() -> Result<(), Box<dyn std::error::Error>> {
let repo_blob_url = "https://github.com/git-fixtures/basic/blob/master/go/example.go";
let temp_cache = tempdir()?;
dircat_cmd()
.arg(repo_blob_url)
.env("DIRCAT_TEST_CACHE_DIR", temp_cache.path())
.assert()
.success()
.stdout(predicate::str::contains("## File: go/example.go"))
.stdout(predicate::str::contains("package harvesterd"))
.stdout(predicate::str::contains("## File: CHANGELOG").not())
.stdout(predicate::str::contains("## File: LICENSE").not());
Ok(())
}
#[test]
#[ignore = "requires network access and is slow"]
fn test_sloppy_url_with_reserved_keyword_is_not_parsed_as_folder(
) -> Result<(), Box<dyn std::error::Error>> {
let repo_folder_url = "https://github.com/some-user/some-repo/releases/v1.0";
let temp_cache = tempdir()?;
dircat_cmd()
.arg(repo_folder_url)
.env("DIRCAT_TEST_CACHE_DIR", temp_cache.path())
.assert()
.failure()
.stderr(predicate::str::contains("Failed to clone repository"));
Ok(())
}