Skip to content

Commit a63663e

Browse files
author
Vladimir Kotal
committed
add proper test for buildTagList()
1 parent fbbc190 commit a63663e

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/history/GitRepositoryTest.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
import java.util.HashSet;
3737
import java.util.List;
3838
import java.util.Set;
39+
import java.util.TreeSet;
3940

4041
import org.eclipse.jgit.api.Git;
42+
import org.eclipse.jgit.lib.ObjectId;
4143
import org.eclipse.jgit.lib.Ref;
44+
import org.eclipse.jgit.revwalk.RevCommit;
45+
import org.eclipse.jgit.revwalk.RevWalk;
4246
import org.eclipse.jgit.transport.URIish;
4347
import org.junit.After;
4448
import org.junit.AfterClass;
@@ -623,6 +627,46 @@ public void testBuildTagList() throws Exception {
623627
gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER);
624628
assertEquals(0, gitrepo.getTagList().size());
625629

626-
// TODO: add some tags (using JGit), rebuild tag list
630+
try (Git git = Git.open(root)) {
631+
// Tag the HEAD first.
632+
Ref ref = git.tag().setName("one").call();
633+
assertNotNull(ref);
634+
gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER);
635+
Set<TagEntry> tags = gitrepo.getTagList();
636+
assertEquals(1, tags.size());
637+
Date date = new Date((long) (1485438707) * 1000);
638+
TagEntry tagEntry = new GitTagEntry("84599b3cccb3eeb5aa9aec64771678d6526bcecb", date, "one");
639+
assertEquals(tagEntry, tags.toArray()[0]);
640+
641+
// Tag again so that single changeset has multiple tags.
642+
ref = git.tag().setName("two").call();
643+
assertNotNull(ref);
644+
gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER);
645+
tags = gitrepo.getTagList();
646+
assertEquals(1, tags.size());
647+
Set<TagEntry> expectedTags = new TreeSet<>();
648+
date = new Date((long) (1485438707) * 1000);
649+
tagEntry = new GitTagEntry("84599b3cccb3eeb5aa9aec64771678d6526bcecb", date, "one, two");
650+
expectedTags.add(tagEntry);
651+
assertEquals(expectedTags, tags);
652+
653+
// Tag specific changeset (not HEAD) and recheck.
654+
org.eclipse.jgit.lib.Repository repo = git.getRepository();
655+
RevCommit commit;
656+
ObjectId objectId = repo.resolve("b6413947a5");
657+
try (RevWalk walk = new RevWalk(repo)) {
658+
commit = walk.parseCommit(objectId);
659+
}
660+
assertNotNull(commit);
661+
ref = git.tag().setName("three").setObjectId(commit).call();
662+
assertNotNull(ref);
663+
gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER);
664+
tags = gitrepo.getTagList();
665+
assertEquals(2, tags.size());
666+
date = new Date((long) (1485263264) * 1000);
667+
tagEntry = new GitTagEntry("b6413947a59f481ddc0a05e0d181731233557f6e", date, "three");
668+
expectedTags.add(tagEntry);
669+
assertEquals(expectedTags, tags);
670+
}
627671
}
628672
}

0 commit comments

Comments
 (0)