forked from kemitix/git-next
test: add more tests to forge crate
This commit is contained in:
parent
1010eaec64
commit
98839c8a00
4 changed files with 63 additions and 49 deletions
|
@ -17,19 +17,19 @@ pub enum Forge {
|
||||||
Github(git_next_forge_github::Github),
|
Github(git_next_forge_github::Github),
|
||||||
}
|
}
|
||||||
impl Forge {
|
impl Forge {
|
||||||
pub const fn new_mock() -> Self {
|
pub fn new(repo_details: git::RepoDetails, net: Network) -> Self {
|
||||||
Self::Mock(mock_forge::MockForge::new())
|
match repo_details.forge.forge_type() {
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
pub const fn new_forgejo(repo_details: git::RepoDetails, net: Network) -> Self {
|
git_next_config::ForgeType::ForgeJo => {
|
||||||
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
|
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
#[cfg(feature = "github")]
|
||||||
pub const fn new_github(repo_details: git::RepoDetails, net: Network) -> Self {
|
git_next_config::ForgeType::GitHub => {
|
||||||
Self::Github(github::Github::new(repo_details, net))
|
Self::Github(github::Github::new(repo_details, net))
|
||||||
}
|
}
|
||||||
|
git_next_config::ForgeType::MockForge => Self::Mock(mock_forge::MockForge::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl std::ops::Deref for Forge {
|
impl std::ops::Deref for Forge {
|
||||||
type Target = dyn git::ForgeLike;
|
type Target = dyn git::ForgeLike;
|
||||||
|
|
50
crates/forge/src/tests.rs
Normal file
50
crates/forge/src/tests.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
//
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use git_next_config as config;
|
||||||
|
use git_next_git::{self as git, RepoDetails};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_mock_name() {
|
||||||
|
let net = Network::new_mock();
|
||||||
|
let repo_details = given_repo_details(config::ForgeType::MockForge);
|
||||||
|
let forge = Forge::new(repo_details, net);
|
||||||
|
assert_eq!(forge.name(), "mock");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_forgejo_name() {
|
||||||
|
let net = Network::new_mock();
|
||||||
|
let repo_details = given_repo_details(config::ForgeType::ForgeJo);
|
||||||
|
let forge = Forge::new(repo_details, net);
|
||||||
|
assert_eq!(forge.name(), "forgejo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_github_name() {
|
||||||
|
let net = Network::new_mock();
|
||||||
|
let repo_details = given_repo_details(config::ForgeType::GitHub);
|
||||||
|
let forge = Forge::new(repo_details, net);
|
||||||
|
assert_eq!(forge.name(), "github");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn given_fs() -> kxio::fs::FileSystem {
|
||||||
|
kxio::fs::temp().unwrap_or_else(|e| {
|
||||||
|
eprintln!("{e}");
|
||||||
|
panic!("fs")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn given_repo_details(forge_type: config::ForgeType) -> RepoDetails {
|
||||||
|
let fs = given_fs();
|
||||||
|
git::common::repo_details(
|
||||||
|
1,
|
||||||
|
git::Generation::new(),
|
||||||
|
config::common::forge_details(1, forge_type),
|
||||||
|
Some(config::common::repo_config(
|
||||||
|
1,
|
||||||
|
config::RepoConfigSource::Repo,
|
||||||
|
)),
|
||||||
|
config::GitDir::new(fs.base()),
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
//
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use git_next_config as config;
|
|
||||||
use git_next_git as git;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_mock_name() {
|
|
||||||
let forge = Forge::new_mock();
|
|
||||||
assert_eq!(forge.name(), "mock");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_forgejo_name() {
|
|
||||||
let Ok(fs) = kxio::fs::temp() else {
|
|
||||||
panic!("fs")
|
|
||||||
};
|
|
||||||
let net = Network::new_mock();
|
|
||||||
let repo_details = git::common::repo_details(
|
|
||||||
1,
|
|
||||||
git::Generation::new(),
|
|
||||||
config::common::forge_details(1, config::ForgeType::MockForge),
|
|
||||||
Some(config::common::repo_config(
|
|
||||||
1,
|
|
||||||
config::RepoConfigSource::Repo,
|
|
||||||
)),
|
|
||||||
config::GitDir::new(fs.base()),
|
|
||||||
);
|
|
||||||
let forge = Forge::new_forgejo(repo_details, net);
|
|
||||||
assert_eq!(forge.name(), "forgejo");
|
|
||||||
}
|
|
|
@ -45,12 +45,7 @@ impl RepoActor {
|
||||||
net: Network,
|
net: Network,
|
||||||
repo: git::Repository,
|
repo: git::Repository,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let forge = match details.forge.forge_type() {
|
let forge = forge::Forge::new(details.clone(), net.clone());
|
||||||
#[cfg(feature = "forgejo")]
|
|
||||||
config::ForgeType::ForgeJo => forge::Forge::new_forgejo(details.clone(), net.clone()),
|
|
||||||
config::ForgeType::GitHub => forge::Forge::new_github(details.clone(), net.clone()),
|
|
||||||
config::ForgeType::MockForge => forge::Forge::new_mock(),
|
|
||||||
};
|
|
||||||
debug!(?forge, "new");
|
debug!(?forge, "new");
|
||||||
Self {
|
Self {
|
||||||
generation,
|
generation,
|
||||||
|
|
Loading…
Reference in a new issue