test(git): add more tests
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Has been cancelled
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Has been cancelled
This commit is contained in:
parent
5e5445f45d
commit
f4b8401bb1
3 changed files with 144 additions and 1 deletions
|
@ -8,7 +8,7 @@ pub enum Force {
|
|||
impl std::fmt::Display for Force {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::No => write!(f, "fast-foward"),
|
||||
Self::No => write!(f, "fast-forward"),
|
||||
Self::From(from) => write!(f, "force-if-from:{}", from),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//
|
||||
#![cfg(not(tarpaulin_include))]
|
||||
use std::{
|
||||
ops::Deref as _,
|
||||
sync::{atomic::AtomicBool, Arc, Mutex},
|
||||
|
|
|
@ -18,3 +18,145 @@ mod commit {
|
|||
assert_eq!(commit.message(), &message);
|
||||
}
|
||||
}
|
||||
mod generation {
|
||||
use crate::Generation;
|
||||
|
||||
#[test]
|
||||
fn should_increment() {
|
||||
let mut g = Generation::new();
|
||||
assert_eq!(g.to_string(), "0");
|
||||
|
||||
g.inc();
|
||||
|
||||
assert_eq!(g.to_string(), "1");
|
||||
}
|
||||
}
|
||||
mod gitref {
|
||||
use crate::{commit, Commit, GitRef};
|
||||
#[test]
|
||||
fn should_convert_from_commit() {
|
||||
let commit = Commit::new(
|
||||
commit::Sha::new("sha".to_string()),
|
||||
commit::Message::new("message".to_string()),
|
||||
);
|
||||
let gitref = GitRef::from(commit);
|
||||
|
||||
assert_eq!(gitref.to_string(), "sha");
|
||||
}
|
||||
}
|
||||
mod gitremote {
|
||||
use git_next_config::{Hostname, RepoPath};
|
||||
|
||||
use crate::GitRemote;
|
||||
|
||||
#[test]
|
||||
fn should_return_hostname() {
|
||||
let host = Hostname::new("localhost".to_string());
|
||||
let repo_path = RepoPath::new("kemitix/git-next".to_string());
|
||||
let gr = GitRemote::new(host.clone(), repo_path);
|
||||
|
||||
assert_eq!(gr.host(), &host);
|
||||
}
|
||||
#[test]
|
||||
fn should_return_repo_path() {
|
||||
let host = Hostname::new("localhost".to_string());
|
||||
let repo_path = RepoPath::new("kemitix/git-next".to_string());
|
||||
let gr = GitRemote::new(host, repo_path.clone());
|
||||
|
||||
assert_eq!(gr.repo_path(), &repo_path);
|
||||
}
|
||||
}
|
||||
mod push {
|
||||
use crate::{commit, Commit, GitRef};
|
||||
|
||||
use crate::push::Force;
|
||||
|
||||
#[test]
|
||||
fn force_no_should_display() {
|
||||
assert_eq!(Force::No.to_string(), "fast-forward")
|
||||
}
|
||||
#[test]
|
||||
fn force_from_should_display() {
|
||||
let commit = Commit::new(
|
||||
commit::Sha::new("sha".to_string()),
|
||||
commit::Message::new("message".to_string()),
|
||||
);
|
||||
assert_eq!(
|
||||
Force::From(GitRef::from(commit)).to_string(),
|
||||
"force-if-from:sha"
|
||||
)
|
||||
}
|
||||
}
|
||||
mod repo_details {
|
||||
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
|
||||
use git_next_config::{
|
||||
ForgeConfig, ForgeName, ForgeType, GitDir, Hostname, RepoAlias, RepoPath, ServerRepoConfig,
|
||||
};
|
||||
use secrecy::ExposeSecret;
|
||||
|
||||
use crate::{Generation, GitRemote, RepoDetails};
|
||||
|
||||
#[test]
|
||||
fn should_return_origin() {
|
||||
let rd = RepoDetails::new(
|
||||
Generation::new(),
|
||||
&RepoAlias::new("foo"),
|
||||
&ServerRepoConfig::new(
|
||||
"repo".to_string(),
|
||||
"branch".to_string(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
&ForgeName::new("default".to_string()),
|
||||
&ForgeConfig::new(
|
||||
ForgeType::MockForge,
|
||||
"host".to_string(),
|
||||
"user".to_string(),
|
||||
"token".to_string(),
|
||||
BTreeMap::new(),
|
||||
),
|
||||
GitDir::from(PathBuf::default().join("foo")),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
rd.origin().expose_secret(),
|
||||
"https://user:token@host/repo.git"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn should_return_git_remote() {
|
||||
let rd = RepoDetails::new(
|
||||
Generation::new(),
|
||||
&RepoAlias::new("foo"),
|
||||
&ServerRepoConfig::new(
|
||||
"user/repo".to_string(),
|
||||
"branch".to_string(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
&ForgeName::new("default".to_string()),
|
||||
&ForgeConfig::new(
|
||||
ForgeType::MockForge,
|
||||
"host".to_string(),
|
||||
"user".to_string(),
|
||||
"token".to_string(),
|
||||
BTreeMap::new(),
|
||||
),
|
||||
GitDir::from(PathBuf::default().join("foo")),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
rd.git_remote(),
|
||||
GitRemote::new(
|
||||
Hostname::new("host".to_string()),
|
||||
RepoPath::new("user/repo".to_string())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue