Skip to content

Commit 8b65887

Browse files
committed
test(git2-ox): References tests
1 parent b3d8642 commit 8b65887

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

backend/git2-ox/tests/test_repository.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn test_iter_branches() {
235235

236236
let existing_branch_names = t
237237
.repo()
238-
.iter_branches(None)
238+
.iter_branches()
239239
.unwrap()
240240
.into_iter()
241241
.map(|b| b.name().to_string());
@@ -246,26 +246,65 @@ fn test_iter_branches() {
246246
HashSet::from_iter(existing_branch_names),
247247
expected_branch_names
248248
);
249+
}
250+
251+
#[test]
252+
fn test_iter_tags() {
253+
use std::collections::HashSet;
254+
255+
let t = common::TempRepository::try_init().unwrap();
256+
t.create_and_commit_random_file();
257+
let tag_names = ["foo", "bar", "baz"];
249258

250-
let no_branches: Vec<String> = t
259+
for tag_name in &tag_names {
260+
t.repo()
261+
.create_lightweight_tag(tag_name, "HEAD", false)
262+
.unwrap();
263+
}
264+
265+
let existing_tag_names = t
251266
.repo()
252-
.iter_branches(Some("no-such-branch"))
267+
.iter_tags()
253268
.unwrap()
254269
.into_iter()
255-
.map(|b| b.name().to_string())
256-
.collect();
257-
assert_eq!(no_branches.len(), 0);
270+
.map(|b| b.name().to_string());
271+
let expected_tag_names: HashSet<String> =
272+
HashSet::from_iter(tag_names.iter().map(|s| s.to_string()));
273+
assert_eq!(HashSet::from_iter(existing_tag_names), expected_tag_names);
274+
}
275+
276+
#[test]
277+
fn test_iter_references() {
278+
use std::collections::HashSet;
279+
280+
let t = common::TempRepository::try_init().unwrap();
281+
t.create_and_commit_random_file();
282+
let default_branch_name = t.repo().current_branch_name().unwrap();
283+
let tag_names = ["t-foo", "t-bar", "t-baz"];
284+
let branch_names = ["b-foo", "b-bar", "b-baz"];
285+
286+
for tag_name in &tag_names {
287+
t.repo()
288+
.create_lightweight_tag(tag_name, "HEAD", false)
289+
.unwrap();
290+
}
258291

259-
let filtered_branch_names = t
292+
for branch_name in &branch_names {
293+
t.repo().create_branch(branch_name, "HEAD", false).unwrap();
294+
}
295+
296+
let existing_ref_names = t
260297
.repo()
261-
.iter_branches(Some("ba"))
298+
.iter_references()
262299
.unwrap()
263300
.into_iter()
264301
.map(|b| b.name().to_string());
265-
let expected_branch_names: HashSet<String> =
266-
HashSet::from_iter(["bar", "baz"].iter().map(|s| s.to_string()));
267-
assert_eq!(
268-
HashSet::from_iter(filtered_branch_names),
269-
expected_branch_names
302+
let mut expected_ref_names: HashSet<String> = HashSet::from_iter(
303+
tag_names
304+
.iter()
305+
.chain(branch_names.iter())
306+
.map(|s| s.to_string()),
270307
);
308+
expected_ref_names.insert(default_branch_name);
309+
assert_eq!(HashSet::from_iter(existing_ref_names), expected_ref_names);
271310
}

0 commit comments

Comments
 (0)