[augeas-devel] [PATCH] /etc/ethers: new lens and test

Satoru SATOH satoru.satoh at gmail.com
Mon Oct 5 01:51:45 UTC 2009


The followings adds a new lens for /etc/ethers and associated test.

Signed-off-by: Satoru SATOH <satoru.satoh at gmail.com>

---
 lenses/ethers.aug            |   26 ++++++++++++++++++
 lenses/tests/test_ethers.aug |   61 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 lenses/ethers.aug
 create mode 100644 lenses/tests/test_ethers.aug

diff --git a/lenses/ethers.aug b/lenses/ethers.aug
new file mode 100644
index 0000000..dc6f1ac
--- /dev/null
+++ b/lenses/ethers.aug
@@ -0,0 +1,26 @@
+(* Parsing /etc/ethers *)
+
+module Ethers =
+  autoload xfm
+
+  let sep_tab = Util.del_ws_tab
+  let sep_spc = Util.del_ws_spc
+
+  let eol = del /[ \t]*\n/ "\n"
+  let indent = del /[ \t]*/ ""
+
+  let comment = Util.comment
+  let empty   = [ del /[ \t]*#?[ \t]*\n/ "\n" ]
+
+  let word = /[^# \n\t]+/
+  let address =
+    let chr = /[0-9a-fA-F][0-9a-fA-F]/ in
+      chr . ":" . chr . ":" . chr . ":" . chr . ":" . chr . ":" . chr
+
+  let record = [ seq "ether" . indent .
+                              [ label "ethaddr" . store  address ] . sep_tab .
+                              [ label "ip" . store word ] . eol ]
+
+  let lns = ( empty | comment | record ) *
+
+  let xfm = transform lns (incl "/etc/ethers")
diff --git a/lenses/tests/test_ethers.aug b/lenses/tests/test_ethers.aug
new file mode 100644
index 0000000..ca1ed39
--- /dev/null
+++ b/lenses/tests/test_ethers.aug
@@ -0,0 +1,61 @@
+(* Tests for the Ethers module *)
+
+module Test_ethers =
+
+(*
+  let empty_entries = "# see man ethers for syntax\n"
+
+  test Ethers.record get empty_entries =
+    { "#comment" = "see man ethers for syntax" }
+*)
+
+  let three_entries = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 foo.example.com
+54:52:00:01:00:03 bar
+"
+
+  test Ethers.lns get three_entries =
+   { "1" { "ethaddr" = "54:52:00:01:00:01" }
+         { "ip" = "192.168.1.1" } }
+   { "#comment" = "comment" }
+   { "2" { "ethaddr" = "54:52:00:01:00:02" }
+         { "ip" = "foo.example.com" } }
+   { "3" { "ethaddr" = "54:52:00:01:00:03" }
+         { "ip" = "bar" } }
+
+  (* Deleting the 'ip' node violates the schema *)
+  test Ethers.lns put three_entries after
+      rm "/1/ip"
+    = *
+
+  test Ethers.lns put three_entries after
+    set "/2/ip" "192.168.1.2" ;
+    set "/3/ip" "baz"
+  = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 192.168.1.2
+54:52:00:01:00:03 baz
+"
+
+  test Ethers.lns put three_entries after
+    rm "/3"
+  = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 foo.example.com
+"
+
+  (* Make sure blank and indented lines get through *)
+  test Ethers.lns get "54:52:00:01:00:01\tfoo  \n \n\n
+54:52:00:01:00:02 bar\n" =
+    { "1" { "ethaddr" = "54:52:00:01:00:01" }
+          { "ip" = "foo" } }
+    {} {} {}
+    { "2" { "ethaddr" = "54:52:00:01:00:02" }
+          { "ip" = "bar" } }
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
+
+
-- 
1.6.2.5




More information about the augeas-devel mailing list