mod commit { use crate::{commit, Commit}; #[test] fn should_return_sha() { let sha = commit::Sha::new("sha".to_string()); let message = commit::Message::new("message".to_string()); let commit = Commit::new(sha.clone(), message); assert_eq!(commit.sha(), &sha); } #[test] fn should_return_message() { let sha = commit::Sha::new("sha".to_string()); let message = commit::Message::new("message".to_string()); let commit = Commit::new(sha, message.clone()); 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()) ) ); } }