|
| 1 | +package git |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestReachableFromAny(t *testing.T) { |
| 8 | + repo, err := OpenRepository("testdata/TestGitRepository.git") |
| 9 | + checkFatal(t, err) |
| 10 | + defer repo.Free() |
| 11 | + |
| 12 | + for name, tc := range map[string]struct { |
| 13 | + reachable bool |
| 14 | + commit string |
| 15 | + descendants []string |
| 16 | + }{ |
| 17 | + "empty": { |
| 18 | + reachable: false, |
| 19 | + commit: "49322bb17d3acc9146f98c97d078513228bbf3c0", |
| 20 | + }, |
| 21 | + "same": { |
| 22 | + reachable: true, |
| 23 | + commit: "49322bb17d3acc9146f98c97d078513228bbf3c0", |
| 24 | + descendants: []string{"49322bb17d3acc9146f98c97d078513228bbf3c0"}, |
| 25 | + }, |
| 26 | + "unreachable": { |
| 27 | + reachable: false, |
| 28 | + commit: "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", |
| 29 | + descendants: []string{"58be4659bb571194ed4562d04b359d26216f526e"}, |
| 30 | + }, |
| 31 | + "unreachable-reverse": { |
| 32 | + reachable: false, |
| 33 | + commit: "58be4659bb571194ed4562d04b359d26216f526e", |
| 34 | + descendants: []string{"ac7e7e44c1885efb472ad54a78327d66bfc4ecef"}, |
| 35 | + }, |
| 36 | + "root": { |
| 37 | + reachable: false, |
| 38 | + commit: "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", |
| 39 | + descendants: []string{ |
| 40 | + "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", |
| 41 | + "d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864", |
| 42 | + "f73b95671f326616d66b2afb3bdfcdbbce110b44", |
| 43 | + "d0114ab8ac326bab30e3a657a0397578c5a1af88", |
| 44 | + }, |
| 45 | + }, |
| 46 | + "head": { |
| 47 | + reachable: false, |
| 48 | + commit: "49322bb17d3acc9146f98c97d078513228bbf3c0", |
| 49 | + descendants: []string{ |
| 50 | + "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", |
| 51 | + "d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864", |
| 52 | + "f73b95671f326616d66b2afb3bdfcdbbce110b44", |
| 53 | + "d0114ab8ac326bab30e3a657a0397578c5a1af88", |
| 54 | + }, |
| 55 | + }, |
| 56 | + } { |
| 57 | + tc := tc |
| 58 | + t.Run(name, func(t *testing.T) { |
| 59 | + commit, err := NewOid(tc.commit) |
| 60 | + checkFatal(t, err) |
| 61 | + |
| 62 | + descendants := make([]*Oid, len(tc.descendants)) |
| 63 | + for i, o := range tc.descendants { |
| 64 | + descendants[i], err = NewOid(o) |
| 65 | + checkFatal(t, err) |
| 66 | + } |
| 67 | + reachable, err := repo.ReachableFromAny(commit, descendants) |
| 68 | + checkFatal(t, err) |
| 69 | + |
| 70 | + if reachable != tc.reachable { |
| 71 | + t.Errorf("ReachableFromAny(%s, %v) = %v, wanted %v", tc.commit, tc.descendants, reachable, tc.reachable) |
| 72 | + } |
| 73 | + }) |
| 74 | + } |
| 75 | +} |
0 commit comments