Merge pull request #3347 from gitbutlerapp/separate-integration-tests-git

separate integration tests for 'git' crate
This commit is contained in:
Josh Junon 2024-04-04 14:00:35 +02:00 committed by GitHub
commit e7c8d5823a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 280 additions and 274 deletions

View File

@ -2,17 +2,21 @@
name = "gitbutler-git"
version = "0.0.0"
edition = "2021"
publish = false
[lib]
path = "src/lib.rs"
doctest = false
[[bin]]
name = "gitbutler-git-askpass"
path = "src/bin/askpass.rs"
test = false
[[bin]]
name = "gitbutler-git-setsid"
path = "src/bin/setsid.rs"
test = false
[features]
default = ["serde", "tokio"]
@ -22,7 +26,7 @@ tokio = ["dep:tokio"]
[dependencies]
thiserror.workspace = true
serde = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, features = ["process", "rt", "process", "time", "io-util", "net", "fs", "sync"]}
tokio = { workspace = true, optional = true, features = ["process", "rt", "process", "time", "io-util", "net", "fs", "sync"] }
rand = "0.8.5"
futures = "0.3.30"
sysinfo = "0.30.5"

View File

@ -120,283 +120,11 @@ mod tests {
use super::*;
#[test]
fn test_parse_source_dest() {
assert_eq!(
RefSpec::parse("refs/heads/*:refs/remotes/origin/*").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}
#[test]
fn test_parse_source_dest_force() {
assert_eq!(
RefSpec::parse("+refs/heads/*:refs/remotes/origin/*").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}
#[test]
fn test_parse_invalid_third_refspec() {
fn parse_invalid_third_refspec() {
assert_eq!(
RefSpec::parse("refs/heads/*:refs/remotes/origin/*:refs/remotes/upstream/*")
.unwrap_err(),
Error::UnexpectedChar(':', 34)
);
}
#[test]
fn test_parse_single_colon() {
assert_eq!(
RefSpec::parse(":").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
);
}
#[test]
fn test_parse_single_colon_force() {
assert_eq!(
RefSpec::parse("+:").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
);
}
#[test]
fn test_parse_empty() {
assert_eq!(
RefSpec::parse("").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
);
}
#[test]
fn test_parse_empty_force() {
assert_eq!(
RefSpec::parse("+").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
);
}
#[test]
fn test_parse_single() {
assert_eq!(
RefSpec::parse("refs/heads/*").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/heads/*".to_owned()),
}
);
}
#[test]
fn test_parse_delete() {
assert_eq!(
RefSpec::parse(":refs/heads/experimental").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: Some("refs/heads/experimental".to_owned()),
}
);
}
#[test]
fn test_parse_single_force() {
assert_eq!(
RefSpec::parse("+refs/heads/*").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/heads/*".to_owned()),
}
);
}
#[test]
fn test_parse_delete_force() {
assert_eq!(
RefSpec::parse("+:refs/heads/experimental").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: Some("refs/heads/experimental".to_owned()),
}
);
}
#[test]
fn test_parse_name() {
assert_eq!(
RefSpec::parse("master").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("master".to_owned()),
destination: Some("master".to_owned()),
}
);
}
#[test]
fn test_parse_name_force() {
assert_eq!(
RefSpec::parse("+master").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("master".to_owned()),
destination: Some("master".to_owned()),
}
);
}
#[test]
fn test_parse_source_only() {
assert_eq!(
RefSpec::parse("refs/heads/*:").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
);
}
#[test]
fn format_empty() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
.to_string(),
":".to_owned()
);
}
#[test]
fn format_empty_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
.to_string(),
"+:".to_owned()
);
}
#[test]
fn format_source_only() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
.to_string(),
"refs/heads/*:".to_owned()
);
}
#[test]
fn format_source_only_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
.to_string(),
"+refs/heads/*:".to_owned()
);
}
#[test]
fn format_source_dest() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
.to_string(),
"refs/heads/*:refs/remotes/origin/*".to_owned()
);
}
#[test]
fn format_source_dest_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
.to_string(),
"+refs/heads/*:refs/remotes/origin/*".to_owned()
);
}
#[test]
fn format_dest_only() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: None,
destination: Some("refs/heads/*".to_owned()),
}
.to_string(),
":refs/heads/*".to_owned()
);
}
#[test]
fn format_dest_only_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: None,
destination: Some("refs/heads/*".to_owned()),
}
.to_string(),
"+:refs/heads/*".to_owned()
);
}
#[test]
fn test_tuple() {
assert_eq!(
RefSpec::from(("refs/heads/*", "refs/remotes/origin/*")),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}
}

View File

@ -0,0 +1 @@
mod refspec;

View File

@ -0,0 +1,273 @@
use gitbutler_git::RefSpec;
#[test]
fn parse_source_dest() {
assert_eq!(
RefSpec::parse("refs/heads/*:refs/remotes/origin/*").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}
#[test]
fn parse_source_dest_force() {
assert_eq!(
RefSpec::parse("+refs/heads/*:refs/remotes/origin/*").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}
#[test]
fn parse_single_colon() {
assert_eq!(
RefSpec::parse(":").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
);
}
#[test]
fn parse_single_colon_force() {
assert_eq!(
RefSpec::parse("+:").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
);
}
#[test]
fn parse_empty() {
assert_eq!(
RefSpec::parse("").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
);
}
#[test]
fn parse_empty_force() {
assert_eq!(
RefSpec::parse("+").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
);
}
#[test]
fn parse_single() {
assert_eq!(
RefSpec::parse("refs/heads/*").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/heads/*".to_owned()),
}
);
}
#[test]
fn parse_delete() {
assert_eq!(
RefSpec::parse(":refs/heads/experimental").unwrap(),
RefSpec {
update_non_fastforward: false,
source: None,
destination: Some("refs/heads/experimental".to_owned()),
}
);
}
#[test]
fn parse_single_force() {
assert_eq!(
RefSpec::parse("+refs/heads/*").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/heads/*".to_owned()),
}
);
}
#[test]
fn parse_delete_force() {
assert_eq!(
RefSpec::parse("+:refs/heads/experimental").unwrap(),
RefSpec {
update_non_fastforward: true,
source: None,
destination: Some("refs/heads/experimental".to_owned()),
}
);
}
#[test]
fn parse_name() {
assert_eq!(
RefSpec::parse("master").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("master".to_owned()),
destination: Some("master".to_owned()),
}
);
}
#[test]
fn parse_name_force() {
assert_eq!(
RefSpec::parse("+master").unwrap(),
RefSpec {
update_non_fastforward: true,
source: Some("master".to_owned()),
destination: Some("master".to_owned()),
}
);
}
#[test]
fn parse_source_only() {
assert_eq!(
RefSpec::parse("refs/heads/*:").unwrap(),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
);
}
#[test]
fn format_empty() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: None,
destination: None,
}
.to_string(),
":".to_owned()
);
}
#[test]
fn format_empty_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: None,
destination: None,
}
.to_string(),
"+:".to_owned()
);
}
#[test]
fn format_source_only() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
.to_string(),
"refs/heads/*:".to_owned()
);
}
#[test]
fn format_source_only_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: None,
}
.to_string(),
"+refs/heads/*:".to_owned()
);
}
#[test]
fn format_source_dest() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
.to_string(),
"refs/heads/*:refs/remotes/origin/*".to_owned()
);
}
#[test]
fn format_source_dest_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
.to_string(),
"+refs/heads/*:refs/remotes/origin/*".to_owned()
);
}
#[test]
fn format_dest_only() {
assert_eq!(
RefSpec {
update_non_fastforward: false,
source: None,
destination: Some("refs/heads/*".to_owned()),
}
.to_string(),
":refs/heads/*".to_owned()
);
}
#[test]
fn format_dest_only_force() {
assert_eq!(
RefSpec {
update_non_fastforward: true,
source: None,
destination: Some("refs/heads/*".to_owned()),
}
.to_string(),
"+:refs/heads/*".to_owned()
);
}
#[test]
fn tuple() {
assert_eq!(
RefSpec::from(("refs/heads/*", "refs/remotes/origin/*")),
RefSpec {
update_non_fastforward: false,
source: Some("refs/heads/*".to_owned()),
destination: Some("refs/remotes/origin/*".to_owned()),
}
);
}