Merge pull request #1373 from gitbutlerapp/Virtual-branch-2

make clippy check test code
This commit is contained in:
Nikita Galaiko 2023-10-13 16:12:10 +02:00 committed by GitHub
commit 884ca537f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 111 additions and 141 deletions

View File

@ -79,5 +79,5 @@ jobs:
- uses: ./.github/actions/init-env-rust
- uses: ./.github/actions/init-env-node
- run: pnpm build
- run: cargo clippy --all-features
- run: cargo clippy --all-features --tests
- run: cargo test --locked

View File

@ -86,7 +86,7 @@ mod tests {
let mut rows = stmt.query([]).unwrap();
let row = rows.next().unwrap().unwrap();
let id: i32 = row.get(0).unwrap();
assert_eq!(id, 1);
assert_eq!(id, 1_i32);
Ok(())
})
.unwrap();

View File

@ -30,7 +30,7 @@ pub fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
#[test]
fn test_dedup() {
vec![
for (existing, new, expected) in [
(vec!["foo", "foo 2"], "foo", "foo 1"),
(vec!["foo", "foo 1", "foo 2"], "foo", "foo 3"),
(vec!["foo", "foo 1", "foo 2"], "foo 1", "foo 1 1"),
@ -38,10 +38,7 @@ fn test_dedup() {
(vec!["foo", "foo 1", "foo 2"], "foo 3", "foo 3"),
(vec!["foo 2"], "foo", "foo"),
(vec!["foo", "foo 1", "foo 2", "foo 4"], "foo", "foo 3"),
]
.iter()
.enumerate()
.for_each(|(i, (existing, new, expected))| {
assert_eq!(dedup(existing, new), expected.to_string(), "test {}", i + 1);
});
] {
assert_eq!(dedup(&existing, new), expected.to_string());
}
}

View File

@ -342,10 +342,10 @@ mod tests {
#[test]
fn test_unicode() {
let latest = reader::Content::UTF8("🌚".to_string());
let current = reader::Content::UTF8("🌝".to_string());
let latest = reader::Content::UTF8("\u{1f31a}".to_string());
let current = reader::Content::UTF8("\u{1f31d}".to_string());
let mut document = Document::new(Some(&latest), vec![]).unwrap();
document.update(Some(&current)).unwrap();
assert_eq!(document.to_string(), "🌝");
assert_eq!(document.to_string(), "\u{1f31d}");
}
}

View File

@ -330,7 +330,7 @@ mod tests {
fn test_directory_reader_is_dir() -> Result<()> {
let dir = test_utils::temp_dir();
let reader = DirReader::open(dir.clone());
std::fs::create_dir(dir.join("dir"))?;
std::fs::create_dir_all(dir.join("dir"))?;
std::fs::write(dir.join("dir/test.txt"), "test")?;
assert!(reader.is_dir(path::Path::new(".")));
assert!(reader.is_dir(path::Path::new("dir")));
@ -346,7 +346,7 @@ mod tests {
let file_path = path::Path::new("test.txt");
std::fs::write(dir.join(file_path), "test")?;
let reader = DirReader::open(dir.to_path_buf());
let reader = DirReader::open(dir.clone());
assert_eq!(reader.read(file_path)?, Content::UTF8("test".to_string()));
Ok(())
@ -356,7 +356,7 @@ mod tests {
fn test_commit_reader_is_dir() -> Result<()> {
let repository = test_utils::test_repository();
std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?;
std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?;
std::fs::write(
repository.path().parent().unwrap().join("dir/test.txt"),
"test",
@ -392,10 +392,10 @@ mod tests {
let dir = test_utils::temp_dir();
std::fs::write(dir.join("test1.txt"), "test")?;
std::fs::create_dir(dir.join("dir"))?;
std::fs::create_dir_all(dir.join("dir"))?;
std::fs::write(dir.join("dir").join("test.txt"), "test")?;
let reader = DirReader::open(dir.to_path_buf());
let reader = DirReader::open(dir.clone());
let files = reader.list_files(path::Path::new("dir"))?;
assert_eq!(files.len(), 1);
assert!(files.contains(&path::Path::new("test.txt").to_path_buf()));
@ -408,10 +408,10 @@ mod tests {
let dir = test_utils::temp_dir();
std::fs::write(dir.join("test.txt"), "test")?;
std::fs::create_dir(dir.join("dir"))?;
std::fs::create_dir_all(dir.join("dir"))?;
std::fs::write(dir.join("dir").join("test.txt"), "test")?;
let reader = DirReader::open(dir.to_path_buf());
let reader = DirReader::open(dir.clone());
let files = reader.list_files(path::Path::new(""))?;
assert_eq!(files.len(), 2);
assert!(files.contains(&path::Path::new("test.txt").to_path_buf()));
@ -428,7 +428,7 @@ mod tests {
repository.path().parent().unwrap().join("test1.txt"),
"test",
)?;
std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?;
std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?;
std::fs::write(
repository
.path()
@ -456,7 +456,7 @@ mod tests {
let repository = test_utils::test_repository();
std::fs::write(repository.path().parent().unwrap().join("test.txt"), "test")?;
std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?;
std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?;
std::fs::write(
repository
.path()
@ -486,7 +486,7 @@ mod tests {
std::fs::write(dir.join("test.txt"), "test")?;
let reader = DirReader::open(dir.to_path_buf());
let reader = DirReader::open(dir.clone());
assert!(reader.exists(path::Path::new("test.txt")));
assert!(!reader.exists(path::Path::new("test2.txt")));
@ -512,29 +512,25 @@ mod tests {
#[test]
fn test_from_bytes() {
vec![
for (bytes, expected) in [
("test".as_bytes(), Content::UTF8("test".to_string())),
(&[0, 159, 146, 150, 159, 146, 150], Content::Binary),
]
.into_iter()
.for_each(|(bytes, expected)| {
] {
assert_eq!(Content::from(bytes), expected);
});
}
}
#[test]
fn test_serialize_content() {
vec![
for (content, expected) in [
(
Content::UTF8("test".to_string()),
r#"{"type":"utf8","value":"test"}"#,
),
(Content::Binary, r#"{"type":"binary"}"#),
(Content::Large, r#"{"type":"large"}"#),
]
.into_iter()
.for_each(|(content, expected)| {
] {
assert_eq!(serde_json::to_string(&content).unwrap(), expected);
});
}
}
}

View File

@ -35,17 +35,18 @@ fn test_sorted_by_timestamp() -> Result<()> {
let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap();
let write_result = searcher.index_session(&gb_repository, &session.unwrap());
assert!(write_result.is_ok());
searcher
.index_session(&gb_repository, &session.unwrap())
.unwrap();
let search_result = searcher.search(&super::Query {
project_id: gb_repository.get_project_id().to_string(),
q: "hello".to_string(),
limit: 10,
offset: None,
});
assert!(search_result.is_ok());
let search_result = search_result.unwrap();
let search_result = searcher
.search(&super::Query {
project_id: gb_repository.get_project_id().to_string(),
q: "hello".to_string(),
limit: 10,
offset: None,
})
.unwrap();
assert_eq!(search_result.total, 2);
assert_eq!(search_result.page[0].index, 1);
assert_eq!(search_result.page[1].index, 0);
@ -166,8 +167,7 @@ fn search_by_full_match() -> Result<()> {
let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap();
let write_result = searcher.index_session(&gb_repository, &session);
assert!(write_result.is_ok());
searcher.index_session(&gb_repository, &session).unwrap();
let result = searcher.search(&super::Query {
project_id: gb_repository.get_project_id().to_string(),
@ -208,8 +208,7 @@ fn search_by_diff() -> Result<()> {
let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap();
let write_result = searcher.index_session(&gb_repository, &session);
assert!(write_result.is_ok());
searcher.index_session(&gb_repository, &session)?;
let result = searcher.search(&super::Query {
project_id: gb_repository.get_project_id().to_string(),

View File

@ -135,8 +135,7 @@ pub fn temp_dir() -> path::PathBuf {
pub fn empty_bare_repository() -> git::Repository {
let path = temp_dir();
let repository = git::Repository::init_bare(path).expect("failed to init repository");
repository
git::Repository::init_bare(path).expect("failed to init repository")
}
pub fn test_repository() -> git::Repository {

View File

@ -184,7 +184,7 @@ mod tests {
#[test]
fn parse_ownership_no_ranges() {
assert!("foo/bar.rs".parse::<FileOwnership>().is_err());
"foo/bar.rs".parse::<FileOwnership>().unwrap_err();
}
#[test]

View File

@ -144,7 +144,7 @@ mod tests {
#[test]
fn parse_invalid() {
assert!("3-2".parse::<Hunk>().is_err());
"3-2".parse::<Hunk>().unwrap_err();
}
#[test]
@ -165,7 +165,7 @@ mod tests {
#[test]
fn parse_invalid_2() {
assert!("3-2".parse::<Hunk>().is_err());
"3-2".parse::<Hunk>().unwrap_err();
}
#[test]
@ -178,7 +178,7 @@ mod tests {
#[test]
fn test_eq() {
vec![
for (a, b, expected) in vec![
(
"1-2".parse::<Hunk>().unwrap(),
"1-2".parse::<Hunk>().unwrap(),
@ -219,10 +219,8 @@ mod tests {
"2-3-bcd".parse::<Hunk>().unwrap(),
false,
),
]
.iter()
.for_each(|(a, b, expected)| {
assert_eq!(a == b, *expected, "comapring {} and {}", a, b);
});
] {
assert_eq!(a == b, expected, "comapring {} and {}", a, b);
}
}
}

View File

@ -223,7 +223,7 @@ mod tests {
#[test]
fn test_equal() {
vec![
for (a, b, expected) in vec![
(
"src/main.rs:100-200".parse::<Ownership>().unwrap(),
"src/main.rs:100-200".parse::<Ownership>().unwrap(),
@ -254,10 +254,8 @@ mod tests {
.unwrap(),
false,
),
]
.into_iter()
.for_each(|(a, b, expected)| {
] {
assert_eq!(a == b, expected, "{:#?} == {:#?}", a, b);
});
}
}
}

View File

@ -54,7 +54,7 @@ mod tests {
Branch {
id: BranchId::generate(),
name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)),
notes: "".to_string(),
notes: String::new(),
applied: true,
order: TEST_INDEX.load(Ordering::Relaxed),
upstream: Some(

View File

@ -136,7 +136,7 @@ mod tests {
Branch {
id: BranchId::generate(),
name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)),
notes: "".to_string(),
notes: String::new(),
applied: true,
upstream: Some(
format!(
@ -227,7 +227,7 @@ mod tests {
);
writer.delete(&branch)?;
assert!(fs::read_dir(root).is_err());
fs::read_dir(root).unwrap_err();
Ok(())
}

View File

@ -63,7 +63,7 @@ mod tests {
branch::Branch {
id: BranchId::generate(),
name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)),
notes: "".to_string(),
notes: String::new(),
applied: true,
upstream: Some(
format!(

View File

@ -75,7 +75,6 @@ fn test_commit_on_branch_then_change_file_then_get_status() -> Result<()> {
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
let branch = &branches[0];
dbg!(&branch);
assert_eq!(branch.files.len(), 1);
assert_eq!(branch.commits.len(), 0);
@ -327,7 +326,7 @@ fn test_create_branch_with_ownership() -> Result<()> {
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -434,7 +433,7 @@ fn test_name_to_branch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch1_id.clone(),
id: branch1_id,
name: Some("branch1".to_string()),
order: Some(1),
..Default::default()
@ -444,18 +443,18 @@ fn test_name_to_branch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
name: Some("branch1".to_string()),
order: Some(0),
..Default::default()
},
);
assert!(result.is_err());
result.unwrap_err();
update_branch(
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
name: Some("branch2".to_string()),
order: Some(0),
..Default::default()
@ -501,7 +500,7 @@ fn test_hunk_expantion() -> Result<()> {
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -513,7 +512,7 @@ fn test_hunk_expantion() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch1_id.clone(),
id: branch1_id,
order: Some(1),
..Default::default()
},
@ -522,7 +521,7 @@ fn test_hunk_expantion() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
order: Some(0),
..Default::default()
},
@ -538,7 +537,7 @@ fn test_hunk_expantion() -> Result<()> {
get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status");
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -594,7 +593,7 @@ fn test_get_status_files_by_branch() -> Result<()> {
get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status");
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -754,7 +753,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> {
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 3);
@ -768,7 +767,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch3_id.clone(),
id: branch3_id,
ownership: Some("test.txt:1-5,11-15".parse()?),
..Default::default()
},
@ -779,7 +778,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> {
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 3);
@ -828,7 +827,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> {
get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status");
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -840,7 +839,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
ownership: Some("test.txt:1-5".parse()?),
..Default::default()
},
@ -851,7 +850,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> {
let files_by_branch_id = statuses
.iter()
.map(|(branch, files)| (branch.id.clone(), files))
.map(|(branch, files)| (branch.id, files))
.collect::<HashMap<_, _>>();
assert_eq!(files_by_branch_id.len(), 2);
@ -908,7 +907,6 @@ fn test_add_new_hunk_to_the_end() -> Result<()> {
let statuses =
get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status");
dbg!(&statuses);
assert!(statuses[0].1[0].hunks[0]
.id
.starts_with("12-17-b5850d4f66182e6630ed9683dbbc2f0b-"));
@ -1534,7 +1532,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch7_id.clone(),
id: branch7_id,
name: Some("Situation 7".to_string()),
ownership: Some("test.txt:1-5".parse()?),
..Default::default()
@ -1567,7 +1565,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch1_id.clone(),
id: branch1_id,
name: Some("Situation 1".to_string()),
ownership: Some("test.txt:1-5".parse()?),
..Default::default()
@ -1585,7 +1583,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
name: Some("Situation 2".to_string()),
ownership: Some("test.txt:1-5".parse()?),
..Default::default()
@ -1608,7 +1606,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
ownership: Some("test.txt:1-6".parse()?),
..Default::default()
},
@ -1628,7 +1626,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch3_id.clone(),
id: branch3_id,
name: Some("Situation 3".to_string()),
ownership: Some("test2.txt:1-5".parse()?),
..Default::default()
@ -1645,7 +1643,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch5_id.clone(),
id: branch5_id,
name: Some("Situation 5".to_string()),
ownership: Some("test3.txt:1-4".parse()?),
..Default::default()
@ -1668,7 +1666,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch5_id.clone(),
id: branch5_id,
ownership: Some("test3.txt:1-5".parse()?),
..Default::default()
},
@ -1683,7 +1681,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch4_id.clone(),
id: branch4_id,
name: Some("Situation 4".to_string()),
ownership: Some("test.txt:1-5".parse()?),
..Default::default()
@ -1699,7 +1697,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch6_id.clone(),
id: branch6_id,
name: Some("Situation 6".to_string()),
ownership: Some("test2.txt:1-5".parse()?),
..Default::default()
@ -1749,7 +1747,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
// 7. applied branch with commits but everything is upstream, delete it
// branch7 was integrated and deleted
let branch7 = branch_reader.read(&branch7_id);
assert!(branch7.is_err());
branch7.unwrap_err();
Ok(())
}
@ -1986,7 +1984,7 @@ fn test_apply_unapply_added_deleted_files() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
ownership: Some("test2.txt:0-0".parse()?),
..Default::default()
},
@ -1995,7 +1993,7 @@ fn test_apply_unapply_added_deleted_files() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch3_id.clone(),
id: branch3_id,
ownership: Some("test3.txt:1-2".parse()?),
..Default::default()
},
@ -2071,7 +2069,7 @@ fn test_detect_mergeable_branch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
ownership: Some("test4.txt:1-3".parse()?),
..Default::default()
},
@ -2651,7 +2649,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch1_id.clone(),
id: branch1_id,
name: Some("integrated".to_string()),
ownership: Some("test.txt:1-2".parse()?),
..Default::default()
@ -2662,7 +2660,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch2_id.clone(),
id: branch2_id,
name: Some("not integrated".to_string()),
ownership: Some("test2.txt:1-2".parse()?),
..Default::default()
@ -2673,7 +2671,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> {
&gb_repository,
&project_repository,
branch::BranchUpdateRequest {
id: branch3_id.clone(),
id: branch3_id,
name: Some("not committed".to_string()),
ownership: Some("test3.txt:1-2".parse()?),
..Default::default()
@ -3197,12 +3195,8 @@ fn tree_to_file_list(repository: &git::Repository, tree: &git::Tree) -> Vec<Stri
let mut file_list = Vec::new();
tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| {
let path = entry.name().unwrap();
let entry = tree
.get_path(std::path::Path::new(path))
.unwrap_or_else(|_| panic!("failed to get tree entry for path {}", path));
let object = entry
.to_object(repository)
.unwrap_or_else(|_| panic!("failed to get object for tree entry {}", path));
let entry = tree.get_path(std::path::Path::new(path)).unwrap();
let object = entry.to_object(repository).unwrap();
if object.kind() == Some(git2::ObjectType::Blob) {
file_list.push(path.to_string());
}
@ -3219,12 +3213,8 @@ fn tree_to_entry_list(
let mut file_list = Vec::new();
tree.walk(git2::TreeWalkMode::PreOrder, |_root, entry| {
let path = entry.name().unwrap();
let entry = tree
.get_path(std::path::Path::new(path))
.unwrap_or_else(|_| panic!("failed to get tree entry for path {}", path));
let object = entry
.to_object(repository)
.unwrap_or_else(|_| panic!("failed to get object for tree entry {}", path));
let entry = tree.get_path(std::path::Path::new(path)).unwrap();
let object = entry.to_object(repository).unwrap();
let blob = object.as_blob().expect("failed to get blob");
// convert content to string
let octal_mode = format!("{:o}", entry.filemode());
@ -3583,7 +3573,7 @@ fn test_apply_out_of_date_conflicting_vbranch() -> Result<()> {
None,
None,
);
assert!(result.is_err());
result.unwrap_err();
// fix the conflict and commit it
std::fs::write(
@ -3633,7 +3623,7 @@ fn test_verify_branch_commits_to_integration() -> Result<()> {
set_test_target(&gb_repository, &project_repository)?;
assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok());
integration::verify_branch(&gb_repository, &project_repository).unwrap();
// write two commits
let file_path2 = std::path::Path::new("test2.txt");
@ -3646,7 +3636,7 @@ fn test_verify_branch_commits_to_integration() -> Result<()> {
test_utils::commit_all(&project_repository.git_repository);
// verify puts commits onto the virtual branch
assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok());
integration::verify_branch(&gb_repository, &project_repository).unwrap();
// one virtual branch with two commits was created
let virtual_branches = list_virtual_branches(&gb_repository, &project_repository)?;
@ -3669,7 +3659,7 @@ fn test_verify_branch_not_integration() -> Result<()> {
set_test_target(&gb_repository, &project_repository)?;
assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok());
integration::verify_branch(&gb_repository, &project_repository).unwrap();
project_repository
.git_repository
@ -3948,12 +3938,12 @@ fn test_force_push() {
)
.is_err());
assert!(push(
push(
&project_repository,
&gb_repository,
&branch_id,
true,
&keys::Key::from(suite.keys.get_or_create().unwrap()),
)
.is_ok());
.unwrap();
}

View File

@ -78,14 +78,13 @@ mod tests {
dispatcher.stop();
});
let mut count = 0;
let mut count = 0_i32;
while let Some(event) = rx.recv().await {
match event {
events::Event::Tick(_, _) => count += 1,
_ => panic!("unexpected event: {:?}", event),
if let events::Event::Tick(_, _) = event {
count += 1_i32;
}
}
assert!(count >= 4);
assert!(count >= 4_i32);
}
}

View File

@ -188,13 +188,13 @@ mod test {
description: None,
repository_id: "123".to_string(),
git_url: cloud.path().to_str().unwrap().to_string(),
created_at: 0.to_string(),
updated_at: 0.to_string(),
created_at: 0_i32.to_string(),
updated_at: 0_i32.to_string(),
sync: true,
};
suite.projects.update(&projects::UpdateRequest {
id: project.id.clone(),
id: project.id,
api: Some(api_project.clone()),
..Default::default()
})?;
@ -212,7 +212,7 @@ mod test {
}
#[test]
fn test_fetch_fail_no_sync() -> Result<()> {
fn test_fetch_fail_no_sync() {
let suite = Suite::default();
let Case { project, .. } = suite.new_case();
@ -226,7 +226,5 @@ mod test {
let res = listener.handle(&project.id, &SystemTime::now());
assert_eq!(&res.unwrap_err().to_string(), "sync disabled");
Ok(())
}
}

View File

@ -117,7 +117,7 @@ mod tests {
#[test]
fn test_should_flush() {
let now = time::SystemTime::now();
vec![
for (start, last, expected) in vec![
(now, now, false), // just created
(now - FIVE_MINUTES, now, false), // active
(
@ -132,9 +132,7 @@ mod tests {
), // not active
(now - ONE_HOUR, now, true), // almost too old
(now - ONE_HOUR - ONE_MILLISECOND, now, true), // too old
]
.into_iter()
.for_each(|(start, last, expected)| {
] {
let session = sessions::Session {
id: SessionId::generate(),
hash: None,
@ -146,7 +144,7 @@ mod tests {
},
};
assert_eq!(should_flush(&now, &session).unwrap(), expected);
});
}
}
}
@ -179,13 +177,13 @@ mod test_handler {
description: None,
repository_id: "123".to_string(),
git_url: cloud.path().to_str().unwrap().to_string(),
created_at: 0.to_string(),
updated_at: 0.to_string(),
created_at: 0_i32.to_string(),
updated_at: 0_i32.to_string(),
sync: true,
};
suite.projects.update(&projects::UpdateRequest {
id: project.id.clone(),
id: project.id,
api: Some(api_project.clone()),
..Default::default()
})?;
@ -206,7 +204,7 @@ mod test_handler {
}
#[test]
fn test_no_fetch_triggered() -> Result<()> {
fn test_no_fetch_triggered() {
let suite = Suite::default();
let Case { project, .. } = suite.new_case();
@ -221,7 +219,5 @@ mod test_handler {
assert!(!result
.iter()
.any(|ev| matches!(ev, events::Event::FetchGitbutlerData(_, _))));
Ok(())
}
}

View File

@ -212,7 +212,7 @@ mod tests {
let zipper_cache = tempdir().unwrap();
let zipper = Zipper::from(&zipper_cache.path().to_path_buf());
assert!(zipper.zip(file_path).is_err());
zipper.zip(file_path).unwrap_err();
}
#[test]