History

[commitgraph] Ditch pre-generated test repos.

Always generate test repos on demand instead. This saves some repo space and keeps us from having to worry about fixture scripts being out of sync with the generated fixtures. It also lets us use git to inspect repos instead of hardcoding expected commit data. On the flip side, tests take ~400ms instead of ~20ms.

Conor Davis committed 6 years ago

Commit 1ce84681 parent 724f39141 files · +197 −265Browse files

Showing the changes to git-commitgraph/tests/access (4 of 41 files). Show all

Unified · Split

4 files
  1. git-commitgraph/tests/access/octopus_merges.rs +26 −135
  2. git-commitgraph/tests/access/single_commit.rs +8 −20
  3. git-commitgraph/tests/access/single_parent.rs +10 −39
  4. git-commitgraph/tests/access/two_parents.rs +10 −59
git-commitgraph/tests/access/octopus_merges.rs+26−135
@@ -1,140 +1,31 @@
1−use crate::{fixture_path, hex_to_id};
2−use git_commitgraph::{Graph, GraphPosition};
3−
4−const ROOT: &[u8] = b"09e3185550fdb352031df65f0e81e74df3b9a556";
5−const ROOT_INDEX: GraphPosition = GraphPosition(0);
6−const COMMIT1: &[u8] = b"33316871b4ab988ea87ba60aaf0138ddb4fb0d21";
7−const COMMIT1_INDEX: GraphPosition = GraphPosition(2);
8−const COMMIT2: &[u8] = b"cbfe147d1826a0d2701f7c80dbe0e2cfba385b15";
9−const COMMIT2_INDEX: GraphPosition = GraphPosition(6);
10−const COMMIT3: &[u8] = b"9dab5d610702ceca4bd889a5ef2662cacfd53178";
11−const COMMIT3_INDEX: GraphPosition = GraphPosition(5);
12−const COMMIT4: &[u8] = b"2ec748404455c0b0451b186851a815da13918ebb";
13−const COMMIT4_INDEX: GraphPosition = GraphPosition(1);
14−const THREE_PARENTS: &[u8] = b"7070cd0b59cd46a0f0fa0c50ca9148390ae1e7c7";
15−const THREE_PARENTS_INDEX: GraphPosition = GraphPosition(4);
16−const FOUR_PARENTS: &[u8] = b"5ca46a72d91817add3a7218f3eaf8b2b6c1caa13";
17−const FOUR_PARENTS_INDEX: GraphPosition = GraphPosition(3);
1+use crate::{check_common, create_repo, inspect_refs};
2+use git_commitgraph::Graph;
183
194 #[test]
20−fn v1() -> Result<(), Box<dyn std::error::Error>> {
21− let root_id = hex_to_id(ROOT);
22− let commit1_id = hex_to_id(COMMIT1);
23− let commit2_id = hex_to_id(COMMIT2);
24− let commit3_id = hex_to_id(COMMIT3);
25− let commit4_id = hex_to_id(COMMIT4);
26− let three_parents_id = hex_to_id(THREE_PARENTS);
27− let four_parents_id = hex_to_id(FOUR_PARENTS);
28−
29− let cg = Graph::from_info_dir(fixture_path("v1/octopus_merges/info"))?;
30− assert_eq!(cg.num_commits(), 7);
31− assert_eq!(cg.id_at(ROOT_INDEX), root_id.to_borrowed());
32− assert_eq!(cg.id_at(COMMIT1_INDEX), commit1_id.to_borrowed());
33− assert_eq!(cg.id_at(COMMIT2_INDEX), commit2_id.to_borrowed());
34− assert_eq!(cg.id_at(COMMIT3_INDEX), commit3_id.to_borrowed());
35− assert_eq!(cg.id_at(COMMIT4_INDEX), commit4_id.to_borrowed());
36− assert_eq!(cg.id_at(THREE_PARENTS_INDEX), three_parents_id.to_borrowed());
37− assert_eq!(cg.id_at(FOUR_PARENTS_INDEX), four_parents_id.to_borrowed());
38− assert_eq!(
39− cg.iter_ids().collect::<Vec<_>>(),
40− vec![
41− root_id.to_borrowed(),
42− commit4_id.to_borrowed(),
43− commit1_id.to_borrowed(),
44− four_parents_id.to_borrowed(),
45− three_parents_id.to_borrowed(),
46− commit3_id.to_borrowed(),
47− commit2_id.to_borrowed(),
48− ]
49− );
50−
51− let root = cg.commit_at(ROOT_INDEX);
52− assert_eq!(root.generation(), 1);
53− assert_eq!(root.id(), root_id.to_borrowed());
54− assert_eq!(root.parent1()?, None);
55− assert_eq!(
56− root.root_tree_id(),
57− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
58− );
59− assert_eq!(root.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]);
60−
61− let commit1 = cg.commit_at(COMMIT1_INDEX);
62− assert_eq!(commit1.generation(), 2);
63− assert_eq!(commit1.id(), commit1_id.to_borrowed());
64− assert_eq!(commit1.parent1()?, Some(ROOT_INDEX));
65− assert_eq!(
66− commit1.root_tree_id(),
67− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
68− );
69− assert_eq!(
70− commit1.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
71− vec![ROOT_INDEX],
72− );
73−
74− let commit2 = cg.commit_at(COMMIT2_INDEX);
75− assert_eq!(commit2.generation(), 2);
76− assert_eq!(commit2.id(), commit2_id.to_borrowed());
77− assert_eq!(commit2.parent1()?, Some(ROOT_INDEX));
78− assert_eq!(
79− commit2.root_tree_id(),
80− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
81− );
82− assert_eq!(
83− commit2.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
84− vec![ROOT_INDEX],
85− );
86−
87− let commit3 = cg.commit_at(COMMIT3_INDEX);
88− assert_eq!(commit3.generation(), 2);
89− assert_eq!(commit3.id(), commit3_id.to_borrowed());
90− assert_eq!(commit3.parent1()?, Some(ROOT_INDEX));
91− assert_eq!(
92− commit3.root_tree_id(),
93− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
94− );
95− assert_eq!(
96− commit3.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
97− vec![ROOT_INDEX],
98− );
99−
100− let commit4 = cg.commit_at(COMMIT4_INDEX);
101− assert_eq!(commit4.generation(), 2);
102− assert_eq!(commit4.id(), commit4_id.to_borrowed());
103− assert_eq!(commit4.parent1()?, Some(ROOT_INDEX));
104− assert_eq!(
105− commit4.root_tree_id(),
106− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
107− );
108− assert_eq!(
109− commit4.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
110− vec![ROOT_INDEX],
111− );
112−
113− let three_parents = cg.commit_at(THREE_PARENTS_INDEX);
114− assert_eq!(three_parents.generation(), 3);
115− assert_eq!(three_parents.id(), three_parents_id.to_borrowed());
116− assert_eq!(three_parents.parent1()?, Some(COMMIT1_INDEX));
117− assert_eq!(
118− three_parents.root_tree_id(),
119− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
120− );
121− assert_eq!(
122− three_parents.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
123− vec![COMMIT1_INDEX, COMMIT2_INDEX, COMMIT3_INDEX],
124− );
125−
126− let four_parents = cg.commit_at(FOUR_PARENTS_INDEX);
127− assert_eq!(four_parents.generation(), 3);
128− assert_eq!(four_parents.id(), four_parents_id.to_borrowed());
129− assert_eq!(four_parents.parent1()?, Some(COMMIT2_INDEX));
130− assert_eq!(
131− four_parents.root_tree_id(),
132− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
133− );
134− assert_eq!(
135− four_parents.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
136− vec![COMMIT2_INDEX, COMMIT1_INDEX, COMMIT3_INDEX, COMMIT4_INDEX],
137− );
5+fn test() -> Result<(), Box<dyn std::error::Error>> {
6+ let repo_dir = create_repo("octopus_merges.sh");
7+ let refs = inspect_refs(
8+ repo_dir.path(),
9+ &[
10+ "root",
11+ "parent1",
12+ "parent2",
13+ "parent3",
14+ "parent4",
15+ "three_parents",
16+ "four_parents",
17+ ],
18+ );
19+ let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
20+ check_common(&cg, &refs);
21+
22+ assert_eq!(cg.commit_at(refs["root"].pos()).generation(), 1);
23+ assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 2);
24+ assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 2);
25+ assert_eq!(cg.commit_at(refs["parent3"].pos()).generation(), 2);
26+ assert_eq!(cg.commit_at(refs["parent4"].pos()).generation(), 2);
27+ assert_eq!(cg.commit_at(refs["three_parents"].pos()).generation(), 3);
28+ assert_eq!(cg.commit_at(refs["four_parents"].pos()).generation(), 3);
13829
13930 Ok(())
14031 }
git-commitgraph/tests/access/single_commit.rs+8−20
@@ -1,26 +1,14 @@
1−use crate::{fixture_path, hex_to_id};
2−use git_commitgraph::{Graph, GraphPosition};
3−
4−const COMMIT: &[u8] = b"771fa42310bb3d221f4cf82613a491b0957d2003";
1+use crate::{check_common, create_repo, inspect_refs};
2+use git_commitgraph::Graph;
53
64 #[test]
7−fn v1() -> Result<(), Box<dyn std::error::Error>> {
8− let commit_id = hex_to_id(COMMIT);
9−
10− let cg = Graph::from_info_dir(fixture_path("v1/single_commit/info"))?;
11− assert_eq!(cg.num_commits(), 1);
12− assert_eq!(cg.id_at(GraphPosition(0)), commit_id.to_borrowed());
13− assert_eq!(cg.iter_ids().collect::<Vec<_>>(), vec![commit_id.to_borrowed()]);
5+fn test() -> Result<(), Box<dyn std::error::Error>> {
6+ let repo_dir = create_repo("single_commit.sh");
7+ let refs = inspect_refs(repo_dir.path(), &["commit"]);
8+ let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
9+ check_common(&cg, &refs);
1410
15− let commit = cg.commit_at(GraphPosition(0));
16− assert_eq!(commit.generation(), 1);
17− assert_eq!(commit.id(), commit_id.to_borrowed());
18− assert_eq!(commit.parent1()?, None);
19− assert_eq!(
20− commit.root_tree_id(),
21− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
22− );
23− assert_eq!(commit.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]);
11+ assert_eq!(cg.commit_at(refs["commit"].pos()).generation(), 1);
2412
2513 Ok(())
2614 }
git-commitgraph/tests/access/single_parent.rs+10−39
@@ -1,44 +1,15 @@
1−use crate::{fixture_path, hex_to_id};
2−use git_commitgraph::{Graph, GraphPosition};
3−
4−const PARENT: &[u8] = b"ddbbe1220676705c5b7a6bb7047e0d63b58cfc28";
5−const CHILD: &[u8] = b"91bfe17bfdfef01c4c38e34e577b01a14a1ef2d4";
1+use crate::{check_common, create_repo, inspect_refs};
2+use git_commitgraph::Graph;
63
74 #[test]
8−fn v1() -> Result<(), Box<dyn std::error::Error>> {
9− let parent_id = hex_to_id(PARENT);
10− let child_id = hex_to_id(CHILD);
11−
12− let cg = Graph::from_info_dir(fixture_path("v1/single_parent/info"))?;
13− assert_eq!(cg.num_commits(), 2);
14− assert_eq!(cg.id_at(GraphPosition(0)), child_id.to_borrowed());
15− assert_eq!(
16− cg.iter_ids().collect::<Vec<_>>(),
17− vec![child_id.to_borrowed(), parent_id.to_borrowed()]
18− );
19−
20− let parent = cg.commit_at(GraphPosition(1));
21− assert_eq!(parent.generation(), 1);
22− assert_eq!(parent.id(), parent_id.to_borrowed());
23− assert_eq!(parent.parent1()?, None);
24− assert_eq!(
25− parent.root_tree_id(),
26− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
27− );
28− assert_eq!(parent.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]);
29−
30− let child = cg.commit_at(GraphPosition(0));
31− assert_eq!(child.generation(), 2);
32− assert_eq!(child.id(), child_id.to_borrowed());
33− assert_eq!(child.parent1()?, Some(GraphPosition(1)));
34− assert_eq!(
35− child.root_tree_id(),
36− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
37− );
38− assert_eq!(
39− child.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
40− vec![GraphPosition(1)]
41− );
5+fn test() -> Result<(), Box<dyn std::error::Error>> {
6+ let repo_dir = create_repo("single_parent.sh");
7+ let refs = inspect_refs(repo_dir.path(), &["parent", "child"]);
8+ let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
9+ check_common(&cg, &refs);
10+
11+ assert_eq!(cg.commit_at(refs["parent"].pos()).generation(), 1);
12+ assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
4213
4314 Ok(())
4415 }
git-commitgraph/tests/access/two_parents.rs+10−59
@@ -1,65 +1,16 @@
1−use crate::{fixture_path, hex_to_id};
2−use git_commitgraph::{Graph, GraphPosition};
3−
4−const PARENT1: &[u8] = b"7506a95b8062f0bee6ccdee717021a0c710a1959";
5−const PARENT1_INDEX: GraphPosition = GraphPosition(2);
6−const PARENT2: &[u8] = b"12ae061ac737392973e59d5df2103a72f1088e45";
7−const PARENT2_INDEX: GraphPosition = GraphPosition(0);
8−const MERGE: &[u8] = b"6a23d4bb5ef62fff1b57b898240bf5a9d5813800";
9−const MERGE_INDEX: GraphPosition = GraphPosition(1);
1+use crate::{check_common, create_repo, inspect_refs};
2+use git_commitgraph::Graph;
103
114 #[test]
12−fn v1() -> Result<(), Box<dyn std::error::Error>> {
13− let parent1_id = hex_to_id(PARENT1);
14− let parent2_id = hex_to_id(PARENT2);
15− let merge_id = hex_to_id(MERGE);
16−
17− let cg = Graph::from_info_dir(fixture_path("v1/two_parents/info"))?;
18− assert_eq!(cg.num_commits(), 3);
19− assert_eq!(cg.id_at(PARENT1_INDEX), parent1_id.to_borrowed());
20− assert_eq!(cg.id_at(PARENT2_INDEX), parent2_id.to_borrowed());
21− assert_eq!(cg.id_at(MERGE_INDEX), merge_id.to_borrowed());
22− assert_eq!(
23− cg.iter_ids().collect::<Vec<_>>(),
24− vec![
25− parent2_id.to_borrowed(),
26− merge_id.to_borrowed(),
27− parent1_id.to_borrowed()
28− ]
29− );
30−
31− let parent1 = cg.commit_at(PARENT1_INDEX);
32− assert_eq!(parent1.generation(), 1);
33− assert_eq!(parent1.id(), parent1_id.to_borrowed());
34− assert_eq!(parent1.parent1()?, None);
35− assert_eq!(
36− parent1.root_tree_id(),
37− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
38− );
39− assert_eq!(parent1.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]);
40−
41− let parent2 = cg.commit_at(PARENT2_INDEX);
42− assert_eq!(parent2.generation(), 1);
43− assert_eq!(parent2.id(), parent2_id.to_borrowed());
44− assert_eq!(parent2.parent1()?, None);
45− assert_eq!(
46− parent2.root_tree_id(),
47− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
48− );
49− assert_eq!(parent2.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]);
5+fn test() -> Result<(), Box<dyn std::error::Error>> {
6+ let repo_dir = create_repo("two_parents.sh");
7+ let refs = inspect_refs(repo_dir.path(), &["parent1", "parent2", "child"]);
8+ let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
9+ check_common(&cg, &refs);
5010
51− let merge = cg.commit_at(MERGE_INDEX);
52− assert_eq!(merge.generation(), 2);
53− assert_eq!(merge.id(), merge_id.to_borrowed());
54− assert_eq!(merge.parent1()?, Some(PARENT1_INDEX));
55− assert_eq!(
56− merge.root_tree_id(),
57− hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(),
58− );
59− assert_eq!(
60− merge.iter_parent_indices().collect::<Result<Vec<_>, _>>()?,
61− vec![PARENT1_INDEX, PARENT2_INDEX]
62− );
11+ assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 1);
12+ assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 1);
13+ assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
6314
6415 Ok(())
6516 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t