Skip to content
Permalink
Browse files

Test for JENKINS-32258

  • Loading branch information...
MarkEWaite committed Jan 3, 2016
1 parent 3139a94 commit 3a8d219569652fbe0531f6ffefa441818acaca06
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
@@ -87,6 +87,12 @@
private static final String LOGGING_STARTED = "Logging started";

private static final String SRC_DIR = (new File(".")).getAbsolutePath();
private String revParseBranchName = null;

private void createRevParseBranch() throws GitException, InterruptedException {
revParseBranchName = "rev-parse-branch-" + UUID.randomUUID().toString();
w.git.checkout("origin/master", revParseBranchName);
}

/**
* One local workspace of a Git repository on a temporary directory
@@ -306,6 +312,7 @@ protected void setExpectedTimeouts(List<Integer> timeouts) {

@Override
protected void setUp() throws Exception {
revParseBranchName = null;
setTimeoutVisibleInCurrentTest(true);
expectedTimeouts = null;
Logger logger = Logger.getLogger(this.getClass().getPackage().getName() + "-" + logCount++);
@@ -351,6 +358,20 @@ public String localMirror() throws IOException, InterruptedException {
throw new IllegalStateException();
}

/* JENKINS-33258 detected many calls to git rev-parse. This checks
* those calls are not being made. The createRevParseBranch call
* creates a branch whose name is unknown to the tests. This
* checks that the branch name is not mentioned in a call to
* git rev-parse.
*/
private void checkRevParseCalls(String branchName) {
String messages = StringUtils.join(handler.getMessages(), ";");
// Linux uses rev-parse without quotes
assertFalse("git rev-parse called: " + messages, handler.containsMessageSubstring("rev-parse " + branchName));
// Windows quotes the rev-parse argument
assertFalse("git rev-parse called: " + messages, handler.containsMessageSubstring("rev-parse \"" + branchName));
}

private void checkTimeout() {
List<Integer> timeouts = handler.getTimeouts();
if (expectedTimeouts == null) {
@@ -380,6 +401,9 @@ protected void tearDown() throws Exception {
if (getTimeoutVisibleInCurrentTest()) {
checkTimeout();
}
if (revParseBranchName != null) {
checkRevParseCalls(revParseBranchName);
}
} finally {
handler.close();
}
@@ -458,6 +482,7 @@ public void test_clone() throws IOException, InterruptedException
{
int newTimeout = 7;
w.git.clone_().timeout(newTimeout).url(localMirror()).repositoryName("origin").execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
@@ -480,6 +505,7 @@ public void test_clone_repositoryName() throws IOException, InterruptedException
public void test_clone_shallow() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").shallow().execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
@@ -500,6 +526,7 @@ public void test_clone_shallow_with_depth() throws IOException, InterruptedExcep
public void test_clone_shared() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").shared().execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
@@ -510,6 +537,7 @@ public void test_clone_shared() throws IOException, InterruptedException
public void test_clone_reference() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").reference(localMirror()).execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");

0 comments on commit 3a8d219

Please sign in to comment.
You can’t perform that action at this time.