-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break apart integration tests for "add" and "check" subcommands
- Loading branch information
Showing
6 changed files
with
130 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
mod common; | ||
|
||
use common::CommandExt; | ||
|
||
#[test] | ||
#[ignore = "Slow; performs git clone"] | ||
fn clone_herostratus() { | ||
let (mut cmd, temp) = common::herostratus(None); | ||
let data_dir = temp.as_ref().unwrap().path(); | ||
|
||
let expected_bare_repo = data_dir | ||
.join("git") | ||
.join("Notgnoshi") | ||
.join("herostratus.git"); | ||
|
||
let url = "https://github.com/Notgnoshi/herostratus.git"; | ||
cmd.arg("add").arg(url); | ||
|
||
assert!(!data_dir.join("git").exists()); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(output.status.success()); | ||
assert!(expected_bare_repo.exists()); | ||
|
||
// Adding the same URL again in the same data_dir fails ... | ||
let (mut cmd, _temp) = common::herostratus(Some(data_dir)); | ||
cmd.arg("add").arg(url); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(!output.status.success()); | ||
|
||
// ... unless the --force flag is given | ||
let (mut cmd, _temp) = common::herostratus(Some(data_dir)); | ||
cmd.arg("add").arg("--force").arg(url); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(output.status.success()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
mod common; | ||
|
||
use common::CommandExt; | ||
use predicates::prelude::*; | ||
use predicates::str; | ||
|
||
#[test] | ||
fn search_current_repo_for_test_simple_branch() { | ||
let (mut cmd, _temp) = common::herostratus(None); | ||
cmd.arg("check").arg(".").arg("origin/test/simple"); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(output.status.success()); | ||
} | ||
|
||
#[test] | ||
fn search_current_repo_for_branch_that_does_not_exist() { | ||
let (mut cmd, _temp) = common::herostratus(None); | ||
cmd.arg("check") | ||
.arg(".") | ||
.arg("origin/test/this-branch-will-never-exist"); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(!output.status.success()); | ||
} | ||
|
||
#[test] | ||
fn search_current_repo_for_fixup_commits() { | ||
let (mut cmd, _temp) = common::herostratus(None); | ||
cmd.arg("check").arg(".").arg("origin/test/fixup"); | ||
|
||
let output = cmd.captured_output().unwrap(); | ||
assert!(output.status.success()); | ||
|
||
// These are the three fixup! commits in the test/fixup branch | ||
let assertion = str::contains("60b480b554dbd5266eec0f2378f72df5170a6702") | ||
.and(str::contains("a987013884fc7dafbe9eb080d7cbc8625408a85f")) | ||
.and(str::contains("2721748d8fa0b0cc3302b41733d37e30161eabfd")); | ||
let stdout = String::from_utf8_lossy(&output.stdout); | ||
assert!(assertion.eval(&stdout)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Output; | ||
|
||
use assert_cmd::Command; | ||
use tempfile::{tempdir, TempDir}; | ||
|
||
// Cache the path to the binary as suggested by https://github.com/assert-rs/assert_cmd/issues/6 to | ||
// avoid expensive repeated lookups. | ||
lazy_static::lazy_static! { | ||
static ref HEROSTRATUS: PathBuf = assert_cmd::cargo::cargo_bin("herostratus"); | ||
} | ||
|
||
/// Get a [`Command`] for the herostratus binary and the [`TempDir`] data dir used in the test | ||
pub fn herostratus(data_dir: Option<&Path>) -> (Command, Option<TempDir>) { | ||
let (tempdir, path) = if let Some(data_dir) = data_dir { | ||
(None, data_dir.to_path_buf()) | ||
} else { | ||
let temp = tempdir().unwrap(); | ||
let data_dir = temp.path().to_path_buf(); | ||
(Some(temp), data_dir) | ||
}; | ||
|
||
let mut cmd = Command::new(&*HEROSTRATUS); | ||
cmd.arg("--log-level=DEBUG").arg("--data-dir").arg(path); | ||
|
||
(cmd, tempdir) | ||
} | ||
|
||
fn capture_output(output: &Output) { | ||
let stdout = String::from_utf8_lossy(&output.stdout); | ||
let stderr = String::from_utf8_lossy(&output.stderr); | ||
|
||
// Test output capture relies on magic in the print! and println! macros | ||
print!("{stdout}"); | ||
print!("{stderr}"); | ||
} | ||
|
||
pub trait CommandExt { | ||
/// Same as [Command::output], except with hooks to print stdout and stderr for failed tests | ||
fn captured_output(&mut self) -> std::io::Result<Output>; | ||
} | ||
|
||
impl CommandExt for Command { | ||
fn captured_output(&mut self) -> std::io::Result<Output> { | ||
let output = self.output()?; | ||
capture_output(&output); | ||
Ok(output) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.