summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2022-01-12 23:45:34 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-26 21:26:05 +0200
commit61d4e31349719778bce67fc9ec707cbb0a98def6 (patch)
treed104e8efbd33c670bead5fba57dd9acae56e3041
parentf3a3a2e8772222d89e4fbcf1dab43aa08935ea97 (diff)
downloadjgit-61d4e31349719778bce67fc9ec707cbb0a98def6.tar.gz
jgit-61d4e31349719778bce67fc9ec707cbb0a98def6.zip
[bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory
Move this test to another class and skip it when running tests with bazel since the bazel test runner does not allow to create files in the home directory. FS#userHome retrieves the home directory on the first call and caches it for subsequent calls to avoid overhead in case path translation is required (currently on cygwin). This prevents that the test can mock the home directory using MockSystemReader like SshTestHarness does. Change-Id: I6a22f37f4a19eb4b4935509eae508a23e56db7aa
-rw-r--r--org.eclipse.jgit.test/BUILD1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java60
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java25
3 files changed, 62 insertions, 24 deletions
diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD
index c9b5d37265..9e787fee71 100644
--- a/org.eclipse.jgit.test/BUILD
+++ b/org.eclipse.jgit.test/BUILD
@@ -42,6 +42,7 @@ DATA = [
EXCLUDED = [
PKG + "api/SecurityManagerTest.java",
PKG + "api/SecurityManagerMissingPermissionsTest.java",
+ PKG + "lib/CommitTemplateConfigTest.java",
]
tests(tests = glob(
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java
new file mode 100644
index 0000000000..6dbe30af2d
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2021 SAP SE and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/*
+ * This test was moved from ConfigTest to allow skipping it when running the
+ * test using bazel which doesn't allow tests to create files in the home
+ * directory
+ */
+public class CommitTemplateConfigTest {
+
+ @Rule
+ public TemporaryFolder tmp = new TemporaryFolder();
+
+ @Test
+ public void testCommitTemplatePathInHomeDirecory()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ File workTree = tmp.newFolder("dummy-worktree");
+ Repository repo = FileRepositoryBuilder.create(workTree);
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // proper evaluation of the ~/ directory
+ String homeDir = System.getProperty("user.home");
+ File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
+ ".tmp", new File(homeDir));
+ tempFileInHomeDirectory.deleteOnExit();
+ JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
+ String expectedTemplatePath = tempFileInHomeDirectory.getPath()
+ .replace(homeDir, "~");
+ config = ConfigTest
+ .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index fe3c1db502..1b03fb76cb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -1176,7 +1176,7 @@ public class ConfigTest {
assertEquals(exp, c.getLong("s", null, "a", 0L));
}
- private static Config parse(String content)
+ static Config parse(String content)
throws ConfigInvalidException {
return parse(content, null);
}
@@ -1515,29 +1515,6 @@ public class ConfigTest {
"utf-8", commitEncoding);
}
- @Test
- public void testCommitTemplatePathInHomeDirecory()
- throws ConfigInvalidException, IOException {
- Config config = new Config(null);
- File tempFile = tmp.newFile("testCommitTemplate-");
- String templateContent = "content of the template";
- JGitTestUtil.write(tempFile, templateContent);
- // proper evaluation of the ~/ directory
- String homeDir = System.getProperty("user.home");
- File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
- ".tmp", new File(homeDir));
- tempFileInHomeDirectory.deleteOnExit();
- JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
- String expectedTemplatePath = tempFileInHomeDirectory.getPath()
- .replace(homeDir, "~");
- config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
- String templatePath = config.get(CommitConfig.KEY)
- .getCommitTemplatePath();
- assertEquals(expectedTemplatePath, templatePath);
- assertEquals(templateContent,
- config.get(CommitConfig.KEY).getCommitTemplateContent());
- }
-
@Test(expected = ConfigInvalidException.class)
public void testCommitTemplateWithInvalidEncoding()
throws ConfigInvalidException, IOException {