Skip to content

Commit

Permalink
Add tests exploring JENKINS-6856 - token macro expansion
Browse files Browse the repository at this point in the history
BranchSpec does not seem to honor token macros. For example,
  $GIT_BRANCH matches as expected
  ${GIT_BRANCH} matches as expected
  ${GIT_BRANCH,fullName=False} does not match
  ${GIT_BRANCH,fullName=True} does not match

I expected either all of them to match as expected (token macro expansion
was being applied), or none of them to match (no variable expansion and
no token macro expansion).  As far as I can tell, variable expansion is
being applied, but token macro expansion is not being applied.
  • Loading branch information
MarkEWaite committed Oct 12, 2015
1 parent c84fc2c commit 91a1ffc
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/test/java/hudson/plugins/git/TestBranchSpec.java
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import static org.junit.Assert.*;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;


public class TestBranchSpec {
Expand Down Expand Up @@ -171,4 +172,60 @@ public void testUsesJavaPatternWithRepetition() {
assertFalse(m.matches("origin/release-201501011"));
assertFalse(m.matches("origin/release-20150101-something"));
}

private EnvVars createEnvMap(String key, String value) {
HashMap<String, String> envMap = new HashMap<String, String>();
envMap.put(key, value);
return new EnvVars(envMap);
}

/* BranchSpec does not seem to honor token macros. For example,
* $GIT_BRANCH matches as expected
* ${GIT_BRANCH} matches as expected
* ${GIT_BRANCH,fullName=False} does not match
* ${GIT_BRANCH,fullName=True} does not match
*/
@Test
@Issue("JENKINS-6856")
public void testUsesEnvValueWithBraces() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withBraces = new BranchSpec("${GIT_BRANCH}");
assertTrue(withBraces.matches("refs/heads/origin/master", env));
assertTrue(withBraces.matches("origin/master", env));
assertFalse(withBraces.matches("master", env));
}

@Test
@Issue("JENKINS-6856")
public void testUsesEnvValueWithoutBraces() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withoutBraces = new BranchSpec("$GIT_BRANCH");
assertTrue(withoutBraces.matches("refs/heads/origin/master", env));
assertTrue(withoutBraces.matches("origin/master", env));
assertFalse(withoutBraces.matches("master", env));
}

@Test
@Issue("JENKINS-6856")
public void testUsesEnvValueWithToken() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withToken = new BranchSpec("${GIT_BRANCH,fullName=True}");
assertFalse(withToken.matches("refs/heads/origin/master", env));
assertFalse(withToken.matches("origin/master", env));
assertFalse(withToken.matches("master", env));
}

@Test
@Issue("JENKINS-6856")
public void testUsesEnvValueWithTokenFalse() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withTokenFalse = new BranchSpec("${GIT_BRANCH,fullName=false}");
assertFalse(withTokenFalse.matches("refs/heads/origin/master", env));
assertFalse(withTokenFalse.matches("origin/master", env));
assertFalse(withTokenFalse.matches("master", env));
}
}

0 comments on commit 91a1ffc

Please sign in to comment.