mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-17 02:25:17 +00:00
refactor: Move create_fixture_repo
into common in integration tests (#282)
This commit is contained in:
parent
6db0e20585
commit
dfade6d629
@ -1,7 +1,8 @@
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{io, process};
|
use std::process::Command;
|
||||||
|
use std::{env, io, process};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
|
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")
|
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
|
/// Extends `std::process::Command` with methods for testing
|
||||||
pub trait TestCommand {
|
pub trait TestCommand {
|
||||||
fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command;
|
fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command;
|
||||||
|
@ -106,7 +106,7 @@ fn test_truncate_length_with_config(
|
|||||||
truncation_symbol: &str,
|
truncation_symbol: &str,
|
||||||
config_options: &str,
|
config_options: &str,
|
||||||
) -> io::Result<()> {
|
) -> 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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
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);
|
assert_eq!(expected, actual);
|
||||||
Ok(())
|
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)
|
|
||||||
}
|
|
||||||
|
@ -7,35 +7,10 @@ use std::process::Command;
|
|||||||
|
|
||||||
use crate::common;
|
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]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_behind_count() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -63,7 +38,7 @@ fn shows_behind_count() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_ahead_count() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -93,7 +68,7 @@ fn shows_ahead_count() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_diverged() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -128,7 +103,7 @@ fn shows_diverged() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_conflicted() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -170,7 +145,7 @@ fn shows_conflicted() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_untracked_file() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -192,7 +167,7 @@ fn shows_untracked_file() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
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]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_stashed() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -246,7 +221,7 @@ fn shows_stashed() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_modified() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -268,7 +243,7 @@ fn shows_modified() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_staged_file() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -295,7 +270,7 @@ fn shows_staged_file() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_renamed_file() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
@ -325,7 +300,7 @@ fn shows_renamed_file() -> io::Result<()> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn shows_deleted_file() -> io::Result<()> {
|
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");
|
let repo_dir = common::new_tempdir()?.path().join("rocket");
|
||||||
|
|
||||||
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user