mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
fix git tag command unit test
This commit is contained in:
@@ -65,14 +65,12 @@ import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
public class GitTagCommand extends AbstractGitCommand implements TagCommand {
|
||||
private final GPG gpg;
|
||||
private final HookContextFactory hookContextFactory;
|
||||
private final ScmEventBus eventBus;
|
||||
|
||||
@Inject
|
||||
GitTagCommand(GitContext context, GPG gpg, HookContextFactory hookContextFactory, ScmEventBus eventBus) {
|
||||
GitTagCommand(GitContext context, HookContextFactory hookContextFactory, ScmEventBus eventBus) {
|
||||
super(context);
|
||||
this.gpg = gpg;
|
||||
this.hookContextFactory = hookContextFactory;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
@@ -114,20 +112,12 @@ public class GitTagCommand extends AbstractGitCommand implements TagCommand {
|
||||
User user = SecurityUtils.getSubject().getPrincipals().oneByType(User.class);
|
||||
PersonIdent taggerIdent = new PersonIdent(user.getDisplayName(), user.getMail());
|
||||
|
||||
// Ref ref =
|
||||
git.tag()
|
||||
.setObjectId(revObject)
|
||||
.setTagger(taggerIdent)
|
||||
.setName(name)
|
||||
.call();
|
||||
|
||||
// Uncomment lines once jgit added support for signing tags
|
||||
// try (RevWalk walk = new RevWalk(git.getRepository())) {
|
||||
// revObject = walk.parseTag(ref.getObjectId());
|
||||
// final Optional<Signature> tagSignature = GitUtil.getTagSignature(revObject, gpg, walk);
|
||||
// tagSignature.ifPresent(tag::addSignature);
|
||||
// }
|
||||
|
||||
eventBus.post(new PostReceiveRepositoryHookEvent(hookEvent));
|
||||
|
||||
return tag;
|
||||
|
||||
@@ -24,7 +24,12 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.util.ThreadContext;
|
||||
import org.eclipse.jgit.lib.GpgSigner;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -42,6 +47,7 @@ import sonia.scm.repository.api.HookContextFactory;
|
||||
import sonia.scm.repository.api.TagDeleteRequest;
|
||||
import sonia.scm.repository.api.TagCreateRequest;
|
||||
import sonia.scm.security.GPG;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -65,16 +71,34 @@ public class GitTagCommandTest extends AbstractGitCommandTestBase {
|
||||
@Mock
|
||||
private ScmEventBus eventBus;
|
||||
|
||||
private Subject subject;
|
||||
|
||||
@Before
|
||||
public void setSigner() {
|
||||
GpgSigner.setDefault(new GitTestHelper.SimpleGpgSigner());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void bindThreadContext() {
|
||||
SecurityUtils.setSecurityManager(new DefaultSecurityManager());
|
||||
subject = MockUtil.createUserSubject(SecurityUtils.getSecurityManager());
|
||||
ThreadContext.bind(subject);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindThreadContext() {
|
||||
ThreadContext.unbindSubject();
|
||||
ThreadContext.unbindSecurityManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateATag() throws IOException {
|
||||
createCommand().create(new TagCreateRequest("592d797cd36432e591416e8b2b98154f4f163411", "newtag"));
|
||||
Optional<Tag> tag = findTag(createContext(), "newtag");
|
||||
assertThat(tag).isNotEmpty();
|
||||
Optional<Tag> optionalTag = findTag(createContext(), "newtag");
|
||||
assertThat(optionalTag).isNotEmpty();
|
||||
final Tag tag = optionalTag.get();
|
||||
assertThat(tag.getName()).isEqualTo("newtag");
|
||||
assertThat(tag.getRevision()).isEqualTo("592d797cd36432e591416e8b2b98154f4f163411");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +150,7 @@ public class GitTagCommandTest extends AbstractGitCommandTestBase {
|
||||
}
|
||||
|
||||
private GitTagCommand createCommand() {
|
||||
return new GitTagCommand(createContext(), gpg, hookContextFactory, eventBus);
|
||||
return new GitTagCommand(createContext(), hookContextFactory, eventBus);
|
||||
}
|
||||
|
||||
private List<Tag> readTags(GitContext context) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user