Hi,

ConfigTest at the moment relies on some config files to be in a fixed
filesystem path (/usr/share/rhn/unit-tests/conf). This can be
inconvenient because, among other things, writing to /usr requires root
access.

The attached patch proposes a self-contained solution where those files
are taken from either the classes directory or the jar file, copied in
/tmp and read from there.

As there are other possible solutions  I wanted to submit this for
review here before pushing it.

Thanks,
-- 
Silvio Moioli
SUSE LINUX Products GmbH
Maxfeldstraße 5, 90409 Nürnberg Germany
>From f027ba5978cb78f786d344d686172fd0756c835b Mon Sep 17 00:00:00 2001
From: Silvio Moioli <smoi...@suse.de>
Date: Mon, 30 Sep 2013 16:29:29 +0200
Subject: [PATCH] ConfigTest: do not rely on hardcoded paths, preexisting files

---
 .../redhat/rhn/common/conf/test/ConfigTest.java    | 25 +++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/common/conf/test/ConfigTest.java b/java/code/src/com/redhat/rhn/common/conf/test/ConfigTest.java
index 310964d..ab461a9 100644
--- a/java/code/src/com/redhat/rhn/common/conf/test/ConfigTest.java
+++ b/java/code/src/com/redhat/rhn/common/conf/test/ConfigTest.java
@@ -19,19 +19,38 @@ import com.redhat.rhn.common.conf.Config;
 import com.redhat.rhn.testing.RhnBaseTestCase;
 import com.redhat.rhn.testing.TestUtils;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.Properties;
 
+import org.apache.commons.io.FileUtils;
+
 public class ConfigTest extends RhnBaseTestCase {
     static final String TEST_KEY = "user";
     static final String TEST_VALUE = "newval";
-    static final String TEST_CONF_LOCATION = "/usr/share/rhn/unit-tests/conf";
     private Config c;
 
     public void setUp() throws Exception {
         c = new Config();
-        c.addPath(TEST_CONF_LOCATION + "/default");
-        c.addPath(TEST_CONF_LOCATION);
+
+        // create test config path
+        String confPath = "/tmp/" + TestUtils.randomString() + "/conf";
+        String defaultPath = confPath + "/default";
+        new File(defaultPath).mkdirs();
+
+        // copy test configuration files over
+        FileUtils.copyURLToFile(TestUtils.findTestData("conf/rhn.conf"), new File(confPath,
+                "rhn.conf"));
+        FileUtils.copyURLToFile(TestUtils.findTestData("conf/default/rhn_web.conf"),
+                new File(defaultPath, "rhn_web.conf"));
+        FileUtils.copyURLToFile(TestUtils.findTestData("conf/default/rhn_prefix.conf"),
+                new File(defaultPath, "rhn_prefix.conf"));
+        FileUtils.copyURLToFile(TestUtils
+                .findTestData("conf/default/bug154517.conf.rpmsave"),
+                new File(defaultPath, "bug154517.conf.rpmsave"));
+
+        c.addPath(confPath);
+        c.addPath(defaultPath);
         c.parseFiles();
     }
 
-- 
1.8.1.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to