Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for core.symlinks setting from init() and init_()
Refer to JENKINS-22376, JENKINS-21168, and JENKINS-22391 for details.
  • Loading branch information
MarkEWaite committed Mar 29, 2014
1 parent a74c252 commit 1ade04a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -36,7 +36,6 @@ To Do
=====

* Fix [bugs](https://issues.jenkins-ci.org/secure/IssueNavigator.jspa?mode=hide&reset=true&jqlQuery=project+%3D+JENKINS+AND+status+in+%28Open%2C+"In+Progress"%2C+Reopened%29+AND+component+%3D+git-client)
* Create tests to verify [symlink behavior](https://issues.jenkins-ci.org/browse/JENKINS-22391)
* Create infrastructure to detect [files opened during a unit test](https://issues.jenkins-ci.org/browse/JENKINS-19994) and left open at exit from test
* Create credential tests to verify various credentials scenarios
* Create submodule tests to verify submodule behaviors
Expand Down
37 changes: 35 additions & 2 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.gitclient;

import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.StringUtils;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -79,12 +80,25 @@ String cmd(String args) throws IOException, InterruptedException {
return launchCommand(args.split(" "));
}

String cmd(boolean ignoreError, String args) throws IOException, InterruptedException {
return launchCommand(ignoreError, args.split(" "));
}

String launchCommand(String... args) throws IOException, InterruptedException {
return launchCommand(false, args);
}

String launchCommand(boolean ignoreError, String... args) throws IOException, InterruptedException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int st = new Launcher.LocalLauncher(listener).launch().pwd(repo).cmds(args).
envs(env).stdout(out).join();
String s = out.toString();
assertEquals(s, 0, st); /* Reports full output of failing commands */
if (!ignoreError) {
if (s == null || s.isEmpty()) {
s = StringUtils.join(args, ' ');
}
assertEquals(s, 0, st); /* Reports full output of failing commands */
}
return s;
}

Expand Down Expand Up @@ -1295,16 +1309,34 @@ public void test_hasSubmodules() throws Exception {
assertFalse(w.git.hasGitModules());
}

/**
* core.symlinks is set to false by msysgit on Windows and by JGit
* 3.3.0 on all platforms. It is not set on Linux. Refer to
* JENKINS-21168, JENKINS-22376, and JENKINS-22391 for details.
*/
private void checkSymlinkSetting(WorkingArea area) throws IOException {
String expected = SystemUtils.IS_OS_WINDOWS || area.git instanceof JGitAPIImpl ? "false" : "";
String symlinkValue = null;
try {
symlinkValue = w.cmd(true, "git config core.symlinks").trim();
} catch (Exception e) {
symlinkValue = e.getMessage();
}
assertEquals(expected, symlinkValue);
}

public void test_init() throws Exception {
assertFalse(w.file(".git").exists());
w.git.init();
assertTrue(w.file(".git").exists());
checkSymlinkSetting(w);
}

public void test_init_() throws Exception {
assertFalse(w.file(".git").exists());
w.git.init_().workspace(w.repoPath()).execute();
assertTrue(w.file(".git").exists());
checkSymlinkSetting(w);
}

public void test_init_bare() throws Exception {
Expand All @@ -1313,14 +1345,15 @@ public void test_init_bare() throws Exception {
w.git.init_().workspace(w.repoPath()).bare(false).execute();
assertTrue(w.file(".git").exists());
assertFalse(w.file("refs").exists());

checkSymlinkSetting(w);

WorkingArea anotherRepo = new WorkingArea();
assertFalse(anotherRepo.file(".git").exists());
assertFalse(anotherRepo.file("refs").exists());
anotherRepo.git.init_().workspace(anotherRepo.repoPath()).bare(true).execute();
assertFalse(anotherRepo.file(".git").exists());
assertTrue(anotherRepo.file("refs").exists());
checkSymlinkSetting(w);
}

public void test_getSubmoduleUrl() throws Exception {
Expand Down

0 comments on commit 1ade04a

Please sign in to comment.