-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add head name property in MercurialSCM #277
Open
long76
wants to merge
5
commits into
jenkinsci:master
Choose a base branch
from
long76:feature_head_name
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
786d785
MercurialSCM add headName property
long76 ab6487f
MercurialSCMBuilder fill headName
long76 299ae1c
add MercurialSCMBuilderTest for headName
long76 d168208
MercurialSCMBuilderTest use head from revision
long76 fc2218e
remove unnecessary DataBoundSetter for headName
long76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/test/java/hudson/plugins/mercurial/MercurialSCMBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package hudson.plugins.mercurial; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import hudson.FilePath; | ||
import hudson.tools.ToolProperty; | ||
import hudson.util.LogTaskListener; | ||
import hudson.util.StreamTaskListener; | ||
import jenkins.scm.api.SCMHead; | ||
import jenkins.scm.api.SCMHeadObserver; | ||
import jenkins.scm.api.SCMRevision; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class MercurialSCMBuilderTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
@Rule | ||
public MercurialRule m = new MercurialRule(j); | ||
@Rule | ||
public TemporaryFolder tmp = new TemporaryFolder(); | ||
|
||
private static LogTaskListener listener; | ||
private static MercurialSCMSource mercurialSCMSource; | ||
|
||
@Before | ||
public void prepareEnvironment() throws Exception { | ||
String instName = "caching"; | ||
MercurialInstallation installation = new MercurialInstallation(instName, "", "hg", false, true, null, false, null, | ||
Collections.<ToolProperty<?>>emptyList()); | ||
listener = new LogTaskListener(Logger.getLogger(MercurialSCMSourceTest.class.getName()), Level.INFO); | ||
j.jenkins.getDescriptorByType(MercurialInstallation.DescriptorImpl.class).setInstallations(installation); | ||
FilePath repo = new FilePath(tmp.getRoot()); | ||
installation.forNode(j.jenkins, StreamTaskListener.fromStdout()); | ||
m.hg(repo, "init"); | ||
repo.child("file").write("initial content", "UTF-8"); | ||
m.hg(repo, "commit", "--addremove", "--message=initial"); | ||
m.hg(repo, "tag", "version-1.0"); | ||
m.hg(repo, "branch", "my-branch"); | ||
repo.child("file2").write("content in branch", "UTF-8"); | ||
m.hg(repo, "commit", "--addremove", "--message=branch"); | ||
m.hg(repo, "tag", "version-1.1"); | ||
|
||
installation.forNode(j.jenkins, StreamTaskListener.fromStdout()); | ||
mercurialSCMSource = new MercurialSCMSource(null, instName, tmp.getRoot().toURI().toURL().toString(), null, null, null, null, null, true); | ||
} | ||
|
||
@Test | ||
public void headNameEquals() throws IOException, InterruptedException { | ||
Map<SCMHead, SCMRevision> result = mercurialSCMSource.fetch(null, SCMHeadObserver.collect(), null, null).result(); | ||
for (Map.Entry<SCMHead, SCMRevision> entry : result.entrySet()) { | ||
MercurialSCM mercurialSCM = new MercurialSCMBuilder(entry.getKey(), entry.getValue(), "", "") | ||
.build(); | ||
assertEquals(MercurialSCM.RevisionType.CHANGESET, mercurialSCM.getRevisionType()); | ||
assertEquals(entry.getValue().getHead().getName(), mercurialSCM.getHeadName()); | ||
assertEquals(entry.getKey().getName(), mercurialSCM.getHeadName()); | ||
} | ||
} | ||
|
||
@Test | ||
public void headNameDefault() throws IOException, InterruptedException { | ||
SCMRevision revision = mercurialSCMSource.fetch("version-1.0", listener, null); | ||
MercurialSCM mercurialSCM = new MercurialSCMBuilder(revision.getHead(), revision, "", "") | ||
.build(); | ||
assertEquals(MercurialSCM.RevisionType.CHANGESET, mercurialSCM.getRevisionType()); | ||
assertEquals("default", mercurialSCM.getHeadName()); | ||
assertEquals(revision.getHead().getName(), mercurialSCM.getHeadName()); | ||
} | ||
|
||
@Test | ||
public void headNameNonDefault() throws IOException, InterruptedException { | ||
SCMRevision revision = mercurialSCMSource.fetch("version-1.1", listener, null); | ||
MercurialSCM mercurialSCM = new MercurialSCMBuilder(revision.getHead(), revision, "", "") | ||
.build(); | ||
assertEquals(MercurialSCM.RevisionType.CHANGESET, mercurialSCM.getRevisionType()); | ||
assertEquals("my-branch", mercurialSCM.getHeadName()); | ||
assertEquals(revision.getHead().getName(), mercurialSCM.getHeadName()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is just asserting that a newly introduced method has an expected value. Fine so far as it goes, but does not demonstrate that the purported purpose of the change (to fix some behavior of
resolveScm
) is actually accomplished by doing that. Is some piece of code using reflection to look for a JavaBeans property namedheadName
? (I certainly hope not!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reflection here of course) just check all existing heads)
resolveScm
works correct just it returnMercurialSCM
where you can get onlyhash
of commit. in fact i dont know which test need for it but my tests confirm thatheadName
correct. maybe need other name of variable) but it's not breaking change like change value ofrevision
fromhash
tobranch name