augeas/augeas-0.7.2-05-21d39d66.patch
2010-06-30 01:31:11 +00:00

99 lines
3.2 KiB
Diff

From 21d39d66b9c2d827cbede4ace1fe0fc0b637992b Mon Sep 17 00:00:00 2001
From: David Lutterkort <lutter@redhat.com>
Date: Tue, 29 Jun 2010 15:01:03 -0700
Subject: [PATCH 5/9] * src/test-load.c (testLoadSave): work off a writable /etc/hosts
This addresses a FIXME that could lead to use not detecting incorrect behavior
---
tests/test-load.c | 53 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/tests/test-load.c b/tests/test-load.c
index e4dd38a..a8107a1 100644
--- a/tests/test-load.c
+++ b/tests/test-load.c
@@ -32,7 +32,8 @@
#define CuAssertRetSuccess(tc, n) CuAssertTrue(tc, (n) == 0)
static const char *abs_top_srcdir;
-static char *root;
+static const char *abs_top_builddir;
+static char *root = NULL;
static char *loadpath;
#define die(msg) \
@@ -41,6 +42,36 @@ static char *loadpath;
exit(EXIT_FAILURE); \
} while(0)
+static struct augeas *setup_writable_hosts(CuTest *tc) {
+ char *etcdir, *build_root;
+ struct augeas *aug = NULL;
+ int r;
+
+ if (asprintf(&build_root, "%s/build/test-load/%s",
+ abs_top_builddir, tc->name) < 0) {
+ CuFail(tc, "failed to set build_root");
+ }
+
+ if (asprintf(&etcdir, "%s/etc", build_root) < 0)
+ CuFail(tc, "asprintf etcdir failed");
+
+ run(tc, "test -d %s && chmod -R u+w %s || :", build_root, build_root);
+ run(tc, "rm -rf %s", build_root);
+ run(tc, "mkdir -p %s", etcdir);
+ run(tc, "cp -pr %s/etc/hosts %s", root, etcdir);
+ run(tc, "chmod -R u+w %s", build_root);
+
+ aug = aug_init(build_root, loadpath, AUG_NO_MODL_AUTOLOAD);
+ CuAssertPtrNotNull(tc, aug);
+
+ r = aug_set(aug, "/augeas/load/Hosts/lens", "Hosts.lns");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_set(aug, "/augeas/load/Hosts/incl", "/etc/hosts");
+ CuAssertRetSuccess(tc, r);
+
+ return aug;
+}
static void testDefault(CuTest *tc) {
augeas *aug = NULL;
@@ -162,21 +193,7 @@ static void testLoadSave(CuTest *tc) {
augeas *aug = NULL;
int r;
- /* FIXME: This test behaves properly during distcheck, since srcdir
- * is writeprotected, making an incorrect attempt to write
- * /etc/hosts.augnew fail; during normal 'make check' the test will
- * succeed.
- * To address this, we should copy the files fro, tests/root into
- * another directory and 'chmod a-w /etc' in that root
- */
- aug = aug_init(root, loadpath, AUG_NO_MODL_AUTOLOAD|AUG_SAVE_NOOP);
- CuAssertPtrNotNull(tc, aug);
-
- r = aug_set(aug, "/augeas/load/Hosts/lens", "Hosts.lns");
- CuAssertRetSuccess(tc, r);
-
- r = aug_set(aug, "/augeas/load/Hosts/incl", "/etc/hosts");
- CuAssertRetSuccess(tc, r);
+ aug = setup_writable_hosts(tc);
r = aug_load(aug);
CuAssertRetSuccess(tc, r);
@@ -262,6 +279,10 @@ int main(void) {
if (abs_top_srcdir == NULL)
die("env var abs_top_srcdir must be set");
+ abs_top_builddir = getenv("abs_top_builddir");
+ if (abs_top_builddir == NULL)
+ die("env var abs_top_builddir must be set");
+
if (asprintf(&root, "%s/tests/root", abs_top_srcdir) < 0) {
die("failed to set root");
}
--
1.6.6.1