Ensure LocalDiskRepositoryTestCase#setup fully uses MockSystemReader
FS#getFileStoreAttributes used the real userConfig and not the mocked one. This led to test errors when running tests with Bazel since it sandboxes tests which prevents they can write to ~/.gitconfig. Fix this by first preparing the MockedSystemReader and the mocked config before calling FS#getFileStoreAttributes. Also fix ConfigTest which broke due to this change since it inherits from LocalDiskRepositoryTestCase and calls its setup method which was changed here. We can no longer assert by comparing plain text since FS adds FileStoreAttributes to the mocked userConfig. Also the default options seen by this test changed since we now use a mocked config. Change-Id: I76bc7c94953fe979266147d3b309a68dda9d4dfe Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
12d03a97d8
commit
c28167e103
|
@ -128,11 +128,8 @@ public void setUp() throws Exception {
|
||||||
if (!tmp.delete() || !tmp.mkdir())
|
if (!tmp.delete() || !tmp.mkdir())
|
||||||
throw new IOException("Cannot create " + tmp);
|
throw new IOException("Cannot create " + tmp);
|
||||||
|
|
||||||
// measure timer resolution before the test to avoid time critical tests
|
|
||||||
// are affected by time needed for measurement
|
|
||||||
FS.getFileStoreAttributes(tmp.toPath().getParent());
|
|
||||||
|
|
||||||
mockSystemReader = new MockSystemReader();
|
mockSystemReader = new MockSystemReader();
|
||||||
|
SystemReader.setInstance(mockSystemReader);
|
||||||
mockSystemReader.userGitConfig = new FileBasedConfig(new File(tmp,
|
mockSystemReader.userGitConfig = new FileBasedConfig(new File(tmp,
|
||||||
"usergitconfig"), FS.DETECTED);
|
"usergitconfig"), FS.DETECTED);
|
||||||
// We have to set autoDetach to false for tests, because tests expect to be able
|
// We have to set autoDetach to false for tests, because tests expect to be able
|
||||||
|
@ -142,7 +139,12 @@ public void setUp() throws Exception {
|
||||||
null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
|
null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
|
||||||
mockSystemReader.userGitConfig.save();
|
mockSystemReader.userGitConfig.save();
|
||||||
ceilTestDirectories(getCeilings());
|
ceilTestDirectories(getCeilings());
|
||||||
SystemReader.setInstance(mockSystemReader);
|
|
||||||
|
// Measure timer resolution before the test to avoid time critical tests
|
||||||
|
// are affected by time needed for measurement.
|
||||||
|
// The MockSystemReader must be configured first since we need to use
|
||||||
|
// the same one here
|
||||||
|
FS.getFileStoreAttributes(tmp.toPath().getParent());
|
||||||
|
|
||||||
author = new PersonIdent("J. Author", "jauthor@example.com");
|
author = new PersonIdent("J. Author", "jauthor@example.com");
|
||||||
committer = new PersonIdent("J. Committer", "jcommitter@example.com");
|
committer = new PersonIdent("J. Committer", "jcommitter@example.com");
|
||||||
|
|
|
@ -43,14 +43,14 @@
|
||||||
package org.eclipse.jgit.pgm;
|
package org.eclipse.jgit.pgm;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
||||||
import org.eclipse.jgit.util.FS;
|
|
||||||
import org.eclipse.jgit.util.SystemReader;
|
import org.eclipse.jgit.util.SystemReader;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -65,6 +65,7 @@ public void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("boxing")
|
||||||
@Test
|
@Test
|
||||||
public void testListConfig() throws Exception {
|
public void testListConfig() throws Exception {
|
||||||
boolean isWindows = SystemReader.getInstance().getProperty("os.name")
|
boolean isWindows = SystemReader.getInstance().getProperty("os.name")
|
||||||
|
@ -73,19 +74,31 @@ public void testListConfig() throws Exception {
|
||||||
.equals("Mac OS X");
|
.equals("Mac OS X");
|
||||||
|
|
||||||
String[] output = execute("git config --list");
|
String[] output = execute("git config --list");
|
||||||
List<String> expect = new ArrayList<>();
|
|
||||||
expect.add("gc.autoDetach=false");
|
Map<String, String> options = parseOptions(output);
|
||||||
expect.add("core.filemode=" + !isWindows);
|
|
||||||
expect.add("core.logallrefupdates=true");
|
assertEquals(!isWindows, Boolean.valueOf(options.get("core.filemode")));
|
||||||
if (isMac)
|
assertTrue((Boolean.valueOf(options.get("core.logallrefupdates"))));
|
||||||
expect.add("core.precomposeunicode=true");
|
if (isMac) {
|
||||||
expect.add("core.repositoryformatversion=0");
|
assertTrue(
|
||||||
if (!FS.DETECTED.supportsSymlinks())
|
(Boolean.valueOf(options.get("core.precomposeunicode"))));
|
||||||
expect.add("core.symlinks=false");
|
}
|
||||||
expect.add(""); // ends with LF (last line empty)
|
assertEquals(Integer.valueOf(0),
|
||||||
assertEquals("expected default configuration",
|
Integer.valueOf(options.get("core.repositoryformatversion")));
|
||||||
Arrays.asList(expect.toArray()).toString(),
|
}
|
||||||
Arrays.asList(output).toString());
|
|
||||||
|
private Map<String, String> parseOptions(String[] output) {
|
||||||
|
Map<String, String> options = new HashMap<>();
|
||||||
|
Arrays.stream(output).forEachOrdered(s -> {
|
||||||
|
int p = s.indexOf('=');
|
||||||
|
if (p == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String key = s.substring(0, p);
|
||||||
|
String value = s.substring(p + 1);
|
||||||
|
options.put(key, value);
|
||||||
|
});
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue