]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add test for linelog header option
authorNick Porter <nick@portercomputing.co.uk>
Fri, 11 Nov 2022 13:55:38 +0000 (13:55 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 22 Nov 2022 11:17:05 +0000 (11:17 +0000)
src/tests/modules/linelog/linelog.unlang
src/tests/modules/linelog/module.conf

index 1dfe9820558a31596625530b765003dfcb493821..417d8d3f9a603278ac1aa4a331e0648cac2eec73 100644 (file)
@@ -277,3 +277,61 @@ else {
 
 #  Remove the file
 &Tmp-String-0 := `/bin/sh -c "rm $ENV{MODULE_TEST_DIR}/test_d.log"`
+
+#  Remove old log files
+group {
+       &Tmp-String-0 := `/bin/sh -c "rm $ENV{MODULE_TEST_DIR}/test_e.log"`
+
+       actions {
+               fail = 1
+       }
+}
+if (fail) {
+       ok
+}
+
+# Set attribute used in header line
+&control.Tmp-String-1 := "%t"
+
+linelog_header
+
+&Tmp-String-0 := `/bin/sh -c "head -n1 $ENV{MODULE_TEST_DIR}/test_e.log"`
+
+if (&Tmp-String-0 == "Log started %{control.Tmp-String-1}") {
+       test_pass
+}
+else {
+       test_fail
+}
+
+&Tmp-String-0 := `/bin/sh -c "tail -n1 $ENV{MODULE_TEST_DIR}/test_e.log"`
+
+if (&Tmp-String-0 == 'bob,olobobob') {
+       test_pass
+}
+else {
+       test_fail
+}
+
+linelog_header
+
+&Tmp-String-0 := `/bin/sh -c "tail -n1 $ENV{MODULE_TEST_DIR}/test_e.log"`
+
+if (&Tmp-String-0 == 'bob,olobobob') {
+       test_pass
+}
+else {
+       test_fail
+}
+
+&Tmp-Integer-0 := `/bin/sh -c "cat $ENV{MODULE_TEST_DIR}/test_e.log | wc -l"`
+
+if (&Tmp-Integer-0 == 3) {
+       test_pass
+}
+else {
+       test_fail
+}
+
+#  Remove the file
+&Tmp-String-0 := `/bin/sh -c "rm $ENV{MODULE_TEST_DIR}/test_e.log"`
index 0d8f86c43ac9122d523ee50bdd5ee378a87a4cd4..b441d094335dd2fd15b22b708064186f1372d0e9 100644 (file)
@@ -68,6 +68,18 @@ linelog linelog_fmt {
        format = &User-Name
 }
 
+#  Used by linelog
+linelog linelog_header {
+       destination = file
+
+       file {
+               filename = $ENV{MODULE_TEST_DIR}/test_e.log
+       }
+
+       header = "Log started %{control.Tmp-String-1}"
+       format = "%{User-Name},%{User-Password}"
+}
+
 #  Used by linelog escapes
 linelog linelog_escapes {
        destination = file