Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<no-test-jar>false</no-test-jar>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
<hpi.bundledArtifacts>ini4j</hpi.bundledArtifacts>
<hpi.strictBundledArtifacts>true</hpi.strictBundledArtifacts>
</properties>
Expand Down Expand Up @@ -133,20 +134,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.test</groupId>
<artifactId>docker-fixtures</artifactId>
<version>200.v22a_e8766731c</version>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.21.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/hudson/plugins/mercurial/CacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
import hudson.util.Secret;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.jvnet.hudson.test.Issue;

public class CacheTest {
class CacheTest {

@Test public void hashSource() throws Exception {
@Test
void hashSource() {
assertEquals("5439A9B4063BB8F4885037E71B5079E1913DB6CA-core-main", Cache.hashSource("http://hg.netbeans.org/core-main/", null, null));
assertEquals("5439A9B4063BB8F4885037E71B5079E1913DB6CA-core-main", Cache.hashSource("http://hg.netbeans.org/core-main", null, null));
assertEquals("5731708C5EEAF9F1320B57D5F6A21E85EA5ADF2D-project", Cache.hashSource("ssh://[email protected]/some/project/", null, null));
Expand All @@ -22,7 +25,8 @@ public class CacheTest {
}

@Issue("JENKINS-12544")
@Test public void hashSource2() throws Exception {
@Test
void hashSource2() {
assertEquals("DA7E6A4632009859A61A551999EE2109EBB69267-ronaldradial", Cache.hashSource("http://ronaldradial:8000/", null,null));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
package hudson.plugins.mercurial;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.FreeStyleProject;
import hudson.tools.ToolProperty;

public class CachingCustomDirSCMTest {
import static org.junit.jupiter.api.Assertions.assertTrue;

@Rule
public JenkinsRule j = new JenkinsRule();
@Rule
public MercurialRule m = new MercurialRule(j);
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

@WithJenkins
class CachingCustomDirSCMTest {

private JenkinsRule j;
private MercurialTestUtil m;

@TempDir
private File tmp;
private File repo;

private static final String CACHING_INSTALLATION = "caching-custom-dir";

@Before
public void setUp() throws Exception {
repo = tmp.getRoot();
@BeforeEach
void beforeEach(JenkinsRule rule) throws Exception {
j = rule;
m = new MercurialTestUtil(j);
repo = tmp;
j.jenkins
.getDescriptorByType(MercurialInstallation.DescriptorImpl.class)
.setInstallations(new MercurialInstallation(CACHING_INSTALLATION, "", "hg",
false, true, new File(tmp.newFolder(),"custom-cache-dir").getAbsolutePath().toString(), false, "",
Collections.<ToolProperty<?>> emptyList()));
false, true, new File(newFolder(tmp, "junit"),"custom-cache-dir").getAbsolutePath(), false, "",
Collections.emptyList()));
}

@Test
public void customCacheLocationFromSlave() throws Exception {
@Test
void customCacheLocationFromSlave() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
p.setScm(new MercurialSCM(CACHING_INSTALLATION, repo.getPath(), null, null,
null, null, false));
Expand All @@ -46,7 +50,16 @@ public void customCacheLocationFromSlave() throws Exception {
m.touchAndCommit(repo, "a");
String log = m.buildAndCheck(p, "a");
Pattern pattern = Pattern.compile("hg clone .*custom-cache-dir");
Assert.assertTrue(pattern.matcher(log).find());
assertTrue(pattern.matcher(log).find());
}

private static File newFolder(File root, String... subDirs) throws IOException {
String subFolder = String.join("/", subDirs);
File result = new File(root, subFolder);
if (!result.mkdirs()) {
throw new IOException("Couldn't create folders " + root);
}
return result;
}

}
15 changes: 7 additions & 8 deletions src/test/java/hudson/plugins/mercurial/CachingSCMTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package hudson.plugins.mercurial;

import hudson.tools.ToolProperty;

import java.util.Collections;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

public class CachingSCMTest extends SCMTestBase {
class CachingSCMTest extends SCMTestBase {

private static final String CACHING_INSTALLATION = "caching";

@Override @Before public void setUp() throws Exception {
super.setUp();
@BeforeEach
void beforeEach() {
j.jenkins
.getDescriptorByType(MercurialInstallation.DescriptorImpl.class)
.setInstallations(
new MercurialInstallation(CACHING_INSTALLATION, "",
"hg", false, true, false, Collections
.<ToolProperty<?>> emptyList()));
.emptyList()));
}

@Override protected String hgInstallation() {
@Override
protected String hgInstallation() {
return CACHING_INSTALLATION;
}

Expand Down
53 changes: 31 additions & 22 deletions src/test/java/hudson/plugins/mercurial/ChangeComparatorTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hudson.plugins.mercurial;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.jvnet.hudson.test.TestExtension;

import hudson.FilePath;
Expand All @@ -14,39 +16,40 @@
import hudson.util.StreamTaskListener;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import org.junit.Rule;

import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class ChangeComparatorTest {
@WithJenkins
class ChangeComparatorTest {

@Rule public JenkinsRule j = new JenkinsRule();
@Rule public MercurialRule m = new MercurialRule(j);
@Rule public TemporaryFolder tmp = new TemporaryFolder();
private JenkinsRule j;
private MercurialTestUtil m;

@TestExtension("triggersNewBuild")
static public class DummyComparator extends ChangeComparator {
public Change compare(MercurialSCM scm, Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository, AbstractProject<?,?> project)
throws IOException, InterruptedException {
return Change.SIGNIFICANT;
}
}

@Test public void triggersNewBuild() throws Exception {
@TempDir
private File tmp;

@BeforeEach
void beforeEach(JenkinsRule rule) {
j = rule;
m = new MercurialTestUtil(j);
}

@Test
void triggersNewBuild() throws Exception {
TaskListener listener = new StreamTaskListener(System.out, Charset.defaultCharset());
Launcher launcher = j.jenkins.createLauncher(listener);

FreeStyleProject project = j.createFreeStyleProject();

// TODO switch to MercurialContainer

Check warning on line 49 in src/test/java/hudson/plugins/mercurial/ChangeComparatorTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: switch to MercurialContainer
MercurialSCM scm = new MercurialSCM(null, tmp.getRoot().getPath(), null, null, null, null, false, null);
MercurialSCM scm = new MercurialSCM(null, tmp.getPath(), null, null, null, null, false, null);
project.setScm(scm);
File repo = tmp.getRoot();
File repo = tmp;

m.hg(repo, "init");
m.touchAndCommit(repo, "x");
Expand All @@ -57,10 +60,16 @@
new MercurialTagAction("tip","",null,null),
listener.getLogger(),
j.jenkins,
new FilePath(tmp.getRoot()),
new FilePath(tmp),
project);
assertEquals(PollingResult.Change.SIGNIFICANT, pr.change);

}
}

@TestExtension("triggersNewBuild")
public static class DummyComparator extends ChangeComparator {
public Change compare(MercurialSCM scm, Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository, AbstractProject<?,?> project) {
return Change.SIGNIFICANT;
}
}
}
69 changes: 40 additions & 29 deletions src/test/java/hudson/plugins/mercurial/ChangelogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,69 @@
import hudson.FilePath;
import hudson.model.FreeStyleProject;
import hudson.model.Slave;
import org.jenkinsci.test.acceptance.docker.DockerClassRule;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.jvnet.hudson.test.BuildWatcher;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.EnumSource;
import org.jvnet.hudson.test.For;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.BuildWatcherExtension;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

/**
* Unlike {@link FunctionalTest} we only care here about the Mercurial version.
*/
@Testcontainers(disabledWithoutDocker = true)
@For({MercurialChangeSet.class, MercurialChangeLogParser.class})
@RunWith(Parameterized.class)
public class ChangelogTest {
@ParameterizedClass
@EnumSource(MercurialContainer.Version.class)
@WithJenkins
class ChangelogTest {

@Rule public final JenkinsRule j = new JenkinsRule();
@Rule public final MercurialRule m = new MercurialRule(j);
@ClassRule public static final DockerClassRule<MercurialContainer> docker = new DockerClassRule<>(MercurialContainer.class);
@ClassRule public static final BuildWatcher buildWatcher = new BuildWatcher();
private JenkinsRule j;
private MercurialTestUtil m;
@Container
private static final MercurialContainer container = new MercurialContainer();
@SuppressWarnings("unused")
@RegisterExtension
private static final BuildWatcherExtension BUILD_WATCHER = new BuildWatcherExtension();

@Parameterized.Parameter(0) public MercurialContainer.Version mercurialVersion;

@Parameterized.Parameters public static Object[] data() {
return MercurialContainer.Version.values();
}
@Parameter(0)
private MercurialContainer.Version mercurialVersion;

private FilePath repo;
private Slave slave;
private Slave agent;
private MercurialInstallation inst;

@Before public void setUp() throws Exception {
MercurialContainer container = docker.create();
slave = container.createSlave(j);
inst = container.createInstallation(j, mercurialVersion, false, false, false, "", slave);
repo = slave.getRootPath().child("repo");
@BeforeEach
void beforeEach(JenkinsRule rule) throws Exception {
j = rule;
m = new MercurialTestUtil(j);

agent = container.createAgent(j);
inst = container.createInstallation(j, mercurialVersion, false, false, false, "", agent);
repo = agent.getRootPath().child("repo");
repo.mkdirs();
m.withNode(slave);
m.withNode(agent);
m.withInstallation(inst);
}

@Issue("JENKINS-55319")
@Test public void spacesInPaths() throws Exception {
@Test
void spacesInPaths() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
MercurialSCM scm = new MercurialSCM(repo.getRemote());
scm.setInstallation(inst.getName());
p.setScm(scm);
p.setAssignedNode(slave);
p.setAssignedNode(agent);
m.hg(repo, "init");
m.touchAndCommit(repo, "one", "two");
assertChangelog("", p);
Expand Down
Loading
Loading