[augeas-devel] [PATCH 06/10] Tests for aug_text_store

lutter at redhat.com lutter at redhat.com
Tue May 22 00:44:33 UTC 2012


From: David Lutterkort <lutter at redhat.com>

---
 tests/run.tests  |   31 ++++++++++++++++++++++++++++++-
 tests/test-api.c |   43 ++++++++++++++++++++++++++++++++-----------
 2 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/tests/run.tests b/tests/run.tests
index bccb802..5e91917 100644
--- a/tests/run.tests
+++ b/tests/run.tests
@@ -33,7 +33,8 @@
 # OUT stream.
 #
 # The test is run against a tree initialized with AUG_NO_STDINC|AUG_NO_LOAD
-# and file system root /dev/null
+# and file system root /dev/null. The Hosts module is loaded
+
 
 #
 # Various corner cases
@@ -614,3 +615,31 @@ test quot_mix_sq -1 ECMDRUN
 
 test quot_mix_dq -1 ECMDRUN
   set /test "a"b'c"d'e"
+
+#
+# Tests for aug_text_store
+#
+test store_hosts 2
+ use Hosts
+  store Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+  print /text/t1
+prints
+  /text/t1
+  /text/t1/1
+  /text/t1/1/ipaddr = "192.168.0.1"
+  /text/t1/1/canonical = "rtr.example.com"
+  /text/t1/1/alias = "foo"
+
+test store_nolens -1 ENOLENS
+  store Nomodule.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+
+test store_epathx -1 EPATHX
+ use Hosts
+  store Hosts.lns [garbage] "192.168.0.1 rtr.example.com foo\n"
+
+test store_esyntax 2
+ use Hosts
+  store Hosts.lns /text/t1 "not a hosts file entry"
+  match /augeas/text/text/t1/error
+prints
+  /augeas/text/text/t1/error = parse_failed
diff --git a/tests/test-api.c b/tests/test-api.c
index a032ac0..7df7f11 100644
--- a/tests/test-api.c
+++ b/tests/test-api.c
@@ -457,8 +457,9 @@ static void testToXml(CuTest *tc) {
 
 static void testTextStore(CuTest *tc) {
     static const char *const hosts = "192.168.0.1 rtr.example.com router\n";
-    /* Not acceptable for Hosts.lns - missing \n */
+    /* Not acceptable for Hosts.lns - missing canonical and \n */
     static const char *const hosts_bad = "192.168.0.1";
+    const char *v;
 
     struct augeas *aug;
     int r;
@@ -466,25 +467,45 @@ static void testTextStore(CuTest *tc) {
     aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
     CuAssertPtrNotNull(tc, aug);
 
-    r = aug_text_store(aug, "Hosts.lns", "/text/t1", hosts, strlen(hosts));
+    r = aug_text_store(aug, "Hosts.lns", "/t1", hosts, strlen(hosts));
     CuAssertRetSuccess(tc, r);
 
-    r = aug_match(aug, "/text/t1/*", NULL);
+    r = aug_match(aug, "/t1/*", NULL);
     CuAssertIntEquals(tc, 1, r);
 
-    // FIXME: Test bad lens name
-    // FIXME: Test parse error
-    r = aug_text_store(aug, "Hosts.lns", "text/t3", hosts_bad,
+    /* Test bad lens name */
+    r = aug_text_store(aug, "Notthere.lns", "/t2", hosts, strlen(hosts));
+    CuAssertIntEquals(tc, -1, r);
+    CuAssertIntEquals(tc, AUG_ENOLENS, aug_error(aug));
+
+    r = aug_match(aug, "/t2", NULL);
+    CuAssertIntEquals(tc, 0, r);
+
+    /* Test parse error */
+    r = aug_text_store(aug, "Hosts.lns", "/t3", hosts_bad,
                        strlen(hosts_bad));
     CuAssertIntEquals(tc, -1, r);
-    r = aug_match(aug, "/text/t3", NULL);
-    CuAssertIntEquals(tc, 1, r);
 
-    aug_print(aug, stdout, "/augeas//error");
-    r = aug_match(aug, "/augeas/text/text/t3/error", NULL);
+    r = aug_match(aug, "/t3", NULL);
+    CuAssertIntEquals(tc, 0, r);
+
+    r = aug_get(aug, "/augeas/text/t3/error", &v);
     CuAssertIntEquals(tc, 1, r);
+    CuAssertStrEquals(tc, "parse_failed", v);
 
-    // FIXME: Test invalid PATH
+    r = aug_text_store(aug, "Hosts.lns", "/t3", hosts, strlen(hosts));
+    CuAssertRetSuccess(tc, r);
+
+    r = aug_match(aug, "/augeas/text/t3/error", NULL);
+    CuAssertIntEquals(tc, 0, r);
+
+    /* Test invalid PATH */
+    r = aug_text_store(aug, "Hosts.lns", "[garbage]", hosts, strlen(hosts));
+    CuAssertIntEquals(tc, -1, r);
+    CuAssertIntEquals(tc, AUG_EPATHX, aug_error(aug));
+
+    r = aug_match(aug, "/t2", NULL);
+    CuAssertIntEquals(tc, 0, r);
 }
 
 int main(void) {
-- 
1.7.7.6




More information about the augeas-devel mailing list