test: Add tests for 'get_git_url'

pull/1/head
sgoudham 3 years ago
parent 80465ec514
commit ddf02376c3
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -434,7 +434,7 @@ mod lib_tests {
}
#[test]
fn is_not_branch() {
fn is_not_branch1() {
let handler = handler_without_remote();
let mock = MockGitTrait::default();
@ -618,6 +618,71 @@ mod lib_tests {
}
}
mod get_git_url {
use crate::{
git::{GitOutput, MockGitTrait},
GitView, error::{AppError, ErrorType},
};
fn handler<'a>() -> GitView<'a> {
GitView::new(None, None, None, false, false)
}
#[test]
fn is_valid_remote() {
let handler = handler();
let expected_remote = "origin";
let mut mock = MockGitTrait::default();
mock.expect_is_valid_remote()
.returning(|_| Ok(GitOutput::Ok("https://github.com/sgoudham/git-view".into())));
let actual_remote = handler.get_git_url(expected_remote, &mock);
assert!(actual_remote.is_ok());
assert_eq!(
actual_remote.unwrap(),
"https://github.com/sgoudham/git-view"
)
}
#[test]
fn is_not_valid_remote() {
let handler = handler();
let expected_remote = "origin";
let mut mock = MockGitTrait::default();
mock.expect_is_valid_remote()
.returning(|_| Ok(GitOutput::Ok("origin".into())));
let actual_remote = handler.get_git_url(expected_remote, &mock);
assert!(actual_remote.is_err());
assert_eq!(
actual_remote.unwrap_err().error_str,
"Looks like your git remote isn't set for 'origin'"
);
}
#[test]
fn command_failed() {
let handler = handler();
let expected_remote = "origin";
let mut mock = MockGitTrait::default();
mock.expect_is_valid_remote()
.returning(|_| Err(AppError::new(ErrorType::CommandFailed, "error".into())));
let actual_remote = handler.get_git_url(expected_remote, &mock);
assert!(actual_remote.is_err());
assert_eq!(
actual_remote.unwrap_err().error_str,
"error"
);
}
}
mod parse_git_url {
use crate::{error::AppError, lib_tests::instantiate_handler};
use test_case::test_case;

Loading…
Cancel
Save