summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeil Kistner <neil.kistner@gmail.com>2019-09-03 23:20:22 -0500
committerMatan Kushner <hello@matchai.me>2019-09-04 00:20:22 -0400
commitdfade6d6298b52e04dc8622c676ac8174a900587 (patch)
treeb23cc8d8a247204139b628c159653bcd5426e907 /tests
parent6db0e205856db7f5ebe417c2e3753d699c212dd9 (diff)
refactor: Move `create_fixture_repo` into common in integration tests (#282)
Diffstat (limited to 'tests')
-rw-r--r--tests/testsuite/common.rs29
-rw-r--r--tests/testsuite/git_branch.rs27
-rw-r--r--tests/testsuite/git_status.rs47
3 files changed, 40 insertions, 63 deletions
diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs
index a2bc10f12..0f611a209 100644
--- a/tests/testsuite/common.rs
+++ b/tests/testsuite/common.rs
@@ -1,7 +1,8 @@
use lazy_static::lazy_static;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
-use std::{io, process};
+use std::process::Command;
+use std::{env, io, process};
lazy_static! {
static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
@@ -43,6 +44,32 @@ pub fn new_tempdir() -> io::Result<tempfile::TempDir> {
tempfile::tempdir_in("/tmp")
}
+/// Create a repo from the fixture to be used in git module tests
+pub fn create_fixture_repo() -> io::Result<std::path::PathBuf> {
+ let fixture_repo_dir = new_tempdir()?.path().join("fixture");
+ let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle");
+
+ Command::new("git")
+ .args(&["config", "--global", "user.email", "starship@example.com"])
+ .output()?;
+
+ Command::new("git")
+ .args(&["config", "--global", "user.name", "starship"])
+ .output()?;
+
+ Command::new("git")
+ .args(&[
+ "clone",
+ "-b",
+ "master",
+ &fixture.to_str().unwrap(),
+ fixture_repo_dir.to_str().unwrap(),
+ ])
+ .output()?;
+
+ Ok(fixture_repo_dir)
+}
+
/// Extends `std::process::Command` with methods for testing
pub trait TestCommand {
fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command;
diff --git a/tests/testsuite/git_branch.rs b/tests/testsuite/git_branch.rs
index 16d889b4d..c1cd31015 100644
--- a/tests/testsuite/git_branch.rs
+++ b/tests/testsuite/git_branch.rs
@@ -106,7 +106,7 @@ fn test_truncate_length_with_config(
truncation_symbol: &str,
config_options: &str,
) -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -141,28 +141,3 @@ fn test_truncate_length_with_config(
assert_eq!(expected, actual);
Ok(())
}
-
-fn create_fixture_repo() -> io::Result<std::path::PathBuf> {
- let fixture_repo_dir = common::new_tempdir()?.path().join("fixture");
- let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle");
-
- Command::new("git")
- .args(&["config", "--global", "user.email", "starship@example.com"])
- .output()?;
-
- Command::new("git")
- .args(&["config", "--global", "user.name", "starship"])
- .output()?;
-
- Command::new("git")
- .args(&[
- "clone",
- "-b",
- "master",
- &fixture.to_str().unwrap(),
- fixture_repo_dir.to_str().unwrap(),
- ])
- .output()?;
-
- Ok(fixture_repo_dir)
-}
diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs
index 510d1baaa..00866247b 100644
--- a/tests/testsuite/git_status.rs
+++ b/tests/testsuite/git_status.rs
@@ -7,35 +7,10 @@ use std::process::Command;
use crate::common;
-fn create_fixture_repo() -> io::Result<std::path::PathBuf> {
- let fixture_repo_dir = common::new_tempdir()?.path().join("fixture");
- let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle");
-
- Command::new("git")
- .args(&["config", "--global", "user.email", "starship@example.com"])
- .output()?;
-
- Command::new("git")
- .args(&["config", "--global", "user.name", "starship"])
- .output()?;
-
- Command::new("git")
- .args(&[
- "clone",
- "-b",
- "master",
- &fixture.to_str().unwrap(),
- fixture_repo_dir.to_str().unwrap(),
- ])
- .output()?;
-
- Ok(fixture_repo_dir)
-}
-
#[test]
#[ignore]
fn shows_behind_count() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -63,7 +38,7 @@ fn shows_behind_count() -> io::Result<()> {
#[test]
#[ignore]
fn shows_ahead_count() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -93,7 +68,7 @@ fn shows_ahead_count() -> io::Result<()> {
#[test]
#[ignore]
fn shows_diverged() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -128,7 +103,7 @@ fn shows_diverged() -> io::Result<()> {
#[test]
#[ignore]
fn shows_conflicted() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -170,7 +145,7 @@ fn shows_conflicted() -> io::Result<()> {
#[test]
#[ignore]
fn shows_untracked_file() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -192,7 +167,7 @@ fn shows_untracked_file() -> io::Result<()> {
#[test]
#[ignore]
fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -219,7 +194,7 @@ fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
#[test]
#[ignore]
fn shows_stashed() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -246,7 +221,7 @@ fn shows_stashed() -> io::Result<()> {
#[test]
#[ignore]
fn shows_modified() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -268,7 +243,7 @@ fn shows_modified() -> io::Result<()> {
#[test]
#[ignore]
fn shows_staged_file() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -295,7 +270,7 @@ fn shows_staged_file() -> io::Result<()> {
#[test]
#[ignore]
fn shows_renamed_file() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
@@ -325,7 +300,7 @@ fn shows_renamed_file() -> io::Result<()> {
#[test]
#[ignore]
fn shows_deleted_file() -> io::Result<()> {
- let fixture_repo_dir = create_fixture_repo()?;
+ let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();