diff options
author | Neil Kistner <neil.kistner@gmail.com> | 2019-09-07 12:27:29 -0500 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-09-07 12:27:29 -0500 |
commit | 86c4a4bdcf3f4db499a1ccb5d3b31e8c1af03db8 (patch) | |
tree | 651158350011aedcb35d6a10abc68431db92f3fd | |
parent | 6658b7f0aa09f2edb96bfe7c7be25377b939f2be (diff) |
refactor: Cleanup unwraps in create_fixture_repo function (#311)
-rw-r--r-- | tests/testsuite/common.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs index 60da0e26a..babe43a17 100644 --- a/tests/testsuite/common.rs +++ b/tests/testsuite/common.rs @@ -1,5 +1,6 @@ use lazy_static::lazy_static; use std::io::prelude::*; +use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; use std::process::Command; use std::{env, fs, io, process}; @@ -46,34 +47,38 @@ pub fn new_tempdir() -> io::Result<tempfile::TempDir> { } /// 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 repo_dir = new_tempdir()?.path().join("rocket"); - let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle"); +pub fn create_fixture_repo() -> io::Result<PathBuf> { + let fixture_repo_path = new_tempdir()?.path().join("fixture"); + let repo_path = new_tempdir()?.path().join("rocket"); + let fixture_path = env::current_dir()?.join("tests/fixtures/rocket.bundle"); + + let fixture_repo_dir = path_str(&fixture_repo_path)?; + let repo_dir = path_str(&repo_path)?; + let fixture = path_str(&fixture_path)?; Command::new("git") - .args(&[ - "clone", - "-b", - "master", - &fixture.to_str().unwrap(), - fixture_repo_dir.to_str().unwrap(), - ]) + .args(&["clone", "-b", "master", fixture, fixture_repo_dir]) .output()?; - git2::Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + git2::Repository::clone(fixture_repo_dir, repo_dir).ok(); Command::new("git") .args(&["config", "--local", "user.email", "starship@example.com"]) - .current_dir(repo_dir.as_path()) + .current_dir(repo_dir) .output()?; Command::new("git") .args(&["config", "--local", "user.name", "starship"]) - .current_dir(repo_dir.as_path()) + .current_dir(repo_dir) .output()?; - Ok(repo_dir) + Ok(repo_path) +} + +fn path_str(repo_dir: &PathBuf) -> io::Result<&str> { + repo_dir + .to_str() + .ok_or_else(|| Error::from(ErrorKind::Other)) } /// Extends `std::process::Command` with methods for testing |