mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
work in progress
This commit is contained in:
@@ -32,7 +32,6 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.BranchCreatedEvent;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.PreReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.api.BranchRequest;
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.security.GPG;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -45,6 +46,9 @@ class GitRepositoryServiceProviderTest {
|
||||
@Mock
|
||||
private GitContext context;
|
||||
|
||||
@Mock
|
||||
private GPG gpg;
|
||||
|
||||
@Test
|
||||
void shouldCreatePushCommand() {
|
||||
GitRepositoryServiceProvider provider = createProvider();
|
||||
@@ -59,7 +63,7 @@ class GitRepositoryServiceProviderTest {
|
||||
}
|
||||
|
||||
private GitRepositoryServiceProvider createProvider() {
|
||||
return new GitRepositoryServiceProvider(createParentInjector(), context);
|
||||
return new GitRepositoryServiceProvider(createParentInjector(), context, gpg);
|
||||
}
|
||||
|
||||
private Injector createParentInjector() {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.lib.GpgSigner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.GitTestHelper;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.repository.api.TagDeleteRequest;
|
||||
import sonia.scm.repository.api.TagCreateRequest;
|
||||
import sonia.scm.security.GPG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GitTagCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Mock
|
||||
private GPG gpg;
|
||||
|
||||
@Before
|
||||
public void setSigner() {
|
||||
GpgSigner.setDefault(new GitTestHelper.SimpleGpgSigner());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateATag() throws IOException {
|
||||
createCommand().create(new TagCreateRequest("592d797cd36432e591416e8b2b98154f4f163411", "newtag"));
|
||||
Optional<Tag> tag = findTag(createContext(), "newtag");
|
||||
assertThat(tag).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteATag() throws IOException {
|
||||
final GitContext context = createContext();
|
||||
Optional<Tag> tag = findTag(context, "test-tag");
|
||||
assertThat(tag).isNotEmpty();
|
||||
|
||||
createCommand().delete(new TagDeleteRequest("test-tag"));
|
||||
|
||||
tag = findTag(context, "test-tag");
|
||||
assertThat(tag).isEmpty();
|
||||
}
|
||||
|
||||
private GitTagCommand createCommand() {
|
||||
return new GitTagCommand(createContext(), gpg);
|
||||
}
|
||||
|
||||
private List<Tag> readTags(GitContext context) throws IOException {
|
||||
return new GitTagsCommand(context, gpg).getTags();
|
||||
}
|
||||
|
||||
private Optional<Tag> findTag(GitContext context, String name) throws IOException {
|
||||
List<Tag> branches = readTags(context);
|
||||
return branches.stream().filter(b -> name.equals(b.getName())).findFirst();
|
||||
}
|
||||
}
|
||||
@@ -29,14 +29,22 @@ import com.github.sdorra.shiro.SubjectAware;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.security.GPG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.anyOf;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SubjectAware(configuration = "classpath:sonia/scm/configuration/shiro.ini", username = "admin", password = "secret")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GitTagsCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Rule
|
||||
@@ -48,24 +56,41 @@ public class GitTagsCommandTest extends AbstractGitCommandTestBase {
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
|
||||
@Mock
|
||||
GPG gpg;
|
||||
|
||||
@Test
|
||||
public void shouldGetDatesCorrectly() throws IOException {
|
||||
final GitContext gitContext = createContext();
|
||||
final GitTagsCommand tagsCommand = new GitTagsCommand(gitContext);
|
||||
final GitTagsCommand tagsCommand = new GitTagsCommand(gitContext, gpg);
|
||||
final List<Tag> tags = tagsCommand.getTags();
|
||||
assertThat(tags).hasSize(2);
|
||||
assertThat(tags).hasSize(3);
|
||||
|
||||
Tag annotatedTag = tags.get(0);
|
||||
assertThat(annotatedTag.getName()).isEqualTo("1.0.0");
|
||||
assertThat(annotatedTag.getDate()).contains(1598348105000L); // Annotated - Take tag date
|
||||
assertThat(annotatedTag.getRevision()).isEqualTo("fcd0ef1831e4002ac43ea539f4094334c79ea9ec");
|
||||
|
||||
Tag lightweightTag = tags.get(1);
|
||||
Tag lightweightTag = tags.get(2);
|
||||
assertThat(lightweightTag.getName()).isEqualTo("test-tag");
|
||||
assertThat(lightweightTag.getDate()).contains(1339416344000L); // Lightweight - Take commit date
|
||||
assertThat(lightweightTag.getRevision()).isEqualTo("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetSignatures() throws IOException {
|
||||
Mockito.when(gpg.findPublicKeyId(ArgumentMatchers.any())).thenReturn("2BA27721F113C005CC16F06BAE63EFBC49F140CF");
|
||||
|
||||
final GitContext gitContext = createContext();
|
||||
final GitTagsCommand tagsCommand = new GitTagsCommand(gitContext, gpg);
|
||||
final List<Tag> tags = tagsCommand.getTags();
|
||||
|
||||
assertThat(tags).hasSize(3);
|
||||
|
||||
Tag signedTag = tags.get(1);
|
||||
assertThat(signedTag.getSignatures()).isNotEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getZippedRepositoryResource() {
|
||||
return "sonia/scm/repository/spi/scm-git-spi-test-tags.zip";
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user