-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change test dir structure for better coverage and update tests accord…
…ingly
- Loading branch information
Showing
21 changed files
with
610 additions
and
224 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
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,58 @@ | ||
#[cfg(test)] | ||
use mockall::{automock, predicate::*}; | ||
use std::{ | ||
env::{self, VarError}, | ||
io::{self}, | ||
ops::Deref, | ||
path::PathBuf, | ||
}; | ||
|
||
#[cfg_attr(test, automock)] | ||
pub(crate) trait EnvServiceTrait { | ||
fn var(&self, key: &str) -> Result<String, VarError>; | ||
fn current_dir(&self) -> io::Result<PathBuf>; | ||
} | ||
|
||
#[derive(Default)] | ||
pub(crate) struct DefaultEnvService {} | ||
|
||
impl EnvServiceTrait for DefaultEnvService { | ||
fn var(&self, key: &str) -> Result<String, VarError> { | ||
env::var(key) | ||
} | ||
|
||
fn current_dir(&self) -> io::Result<PathBuf> { | ||
env::current_dir() | ||
} | ||
} | ||
|
||
impl EnvServiceTrait for Box<dyn EnvServiceTrait> { | ||
fn var(&self, key: &str) -> Result<String, VarError> { | ||
self.deref().var(key) | ||
} | ||
|
||
fn current_dir(&self) -> io::Result<PathBuf> { | ||
self.deref().current_dir() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::{DefaultEnvService, EnvServiceTrait}; | ||
|
||
#[test] | ||
fn default_env_service_current_dir_returns_env_current_dir() { | ||
// Arrange | ||
let service = DefaultEnvService::default(); | ||
|
||
// Act | ||
let current_dir = service | ||
.current_dir() | ||
.expect("Should be able to get current dir via service"); | ||
|
||
// Assert | ||
let env_current_dir = | ||
std::env::current_dir().expect("Should be able to get current dir via env"); | ||
assert_eq!(env_current_dir, current_dir); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod cli_command; | ||
pub mod environment; | ||
pub mod tui; | ||
pub mod view_command; | ||
|
||
|
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
Oops, something went wrong.