]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add logger(1) error condition tests
authorSami Kerola <kerolasa@iki.fi>
Sun, 15 Mar 2015 12:46:30 +0000 (12:46 +0000)
committerSami Kerola <kerolasa@iki.fi>
Mon, 16 Mar 2015 23:25:10 +0000 (23:25 +0000)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests/expected/logger/errors [new file with mode: 0644]
tests/expected/logger/errors-id_with_space [new file with mode: 0644]
tests/expected/logger/errors-invalid_prio [new file with mode: 0644]
tests/expected/logger/errors-kern_priority [new file with mode: 0644]
tests/expected/logger/errors-kern_priority_numeric [new file with mode: 0644]
tests/expected/logger/errors-rfc5424_exceed_size [new file with mode: 0644]
tests/expected/logger/errors-rfc5424_msgid_with_space [new file with mode: 0644]
tests/expected/logger/errors-tag_with_space [new file with mode: 0644]
tests/ts/logger/errors [new file with mode: 0755]

diff --git a/tests/expected/logger/errors b/tests/expected/logger/errors
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/expected/logger/errors-id_with_space b/tests/expected/logger/errors-id_with_space
new file mode 100644 (file)
index 0000000..081efac
--- /dev/null
@@ -0,0 +1,2 @@
+test_logger: failed to parse id: 'A B'
+test_logger: failed to parse id: 'A B'
diff --git a/tests/expected/logger/errors-invalid_prio b/tests/expected/logger/errors-invalid_prio
new file mode 100644 (file)
index 0000000..cf79cf3
--- /dev/null
@@ -0,0 +1 @@
+test_logger: unknown priority name: 8
diff --git a/tests/expected/logger/errors-kern_priority b/tests/expected/logger/errors-kern_priority
new file mode 100644 (file)
index 0000000..6656db0
--- /dev/null
@@ -0,0 +1 @@
+<8>Feb 13 23:31:30 prio: message
diff --git a/tests/expected/logger/errors-kern_priority_numeric b/tests/expected/logger/errors-kern_priority_numeric
new file mode 100644 (file)
index 0000000..6656db0
--- /dev/null
@@ -0,0 +1 @@
+<8>Feb 13 23:31:30 prio: message
diff --git a/tests/expected/logger/errors-rfc5424_exceed_size b/tests/expected/logger/errors-rfc5424_exceed_size
new file mode 100644 (file)
index 0000000..91f69b6
--- /dev/null
@@ -0,0 +1 @@
+<13>1 2009-02-13T23:31:30.123456+00:00 test-hostname rfc5424_exceed_size - - [timeQuality tzKnown="1" isSynced="0"] abc
diff --git a/tests/expected/logger/errors-rfc5424_msgid_with_space b/tests/expected/logger/errors-rfc5424_msgid_with_space
new file mode 100644 (file)
index 0000000..273bc9b
--- /dev/null
@@ -0,0 +1 @@
+test_logger: --msgid cannot contain space
diff --git a/tests/expected/logger/errors-tag_with_space b/tests/expected/logger/errors-tag_with_space
new file mode 100644 (file)
index 0000000..9821d82
--- /dev/null
@@ -0,0 +1,2 @@
+<13>Feb 13 23:31:30 A B: tag_with_space
+<13>1 2009-02-13T23:31:30.123456+00:00 test-hostname A B - - [timeQuality tzKnown="1" isSynced="0"] tag_with_space_rfc5424
diff --git a/tests/ts/logger/errors b/tests/ts/logger/errors
new file mode 100755 (executable)
index 0000000..369ceb6
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2015 Sami Kerola <kerolasa@iki.fi>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="errors"
+
+. $TS_TOPDIR/functions.sh
+
+ts_init "$*"
+
+ts_check_test_command "$TS_HELPER_LOGGER"
+
+export TZ="GMT"
+export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
+export LOGGER_TEST_HOSTNAME="test-hostname"
+export LOGGER_TEST_GETPID="98765"
+
+ts_init_subtest "kern_priority"
+$TS_HELPER_LOGGER --no-act -s -t "prio" -p kern.emerg "message" > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "kern_priority_numeric"
+$TS_HELPER_LOGGER --no-act -s -t "prio" -p 0 "message" > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "invalid_prio"
+$TS_HELPER_LOGGER --no-act -s -t "prio" -p 8 "message" > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+# should truncate
+ts_init_subtest "rfc5424_exceed_size"
+$TS_HELPER_LOGGER --no-act -s -t "rfc5424_exceed_size" --rfc5424 --size 3 "abcd" > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "id_with_space"
+$TS_HELPER_LOGGER --no-act -s -t "id_with_space" --id="A B" "message" > "$TS_OUTPUT" 2>&1
+$TS_HELPER_LOGGER --no-act -s -t "rfc5424_id_with_space" --rfc5424 --id="A B" "message" >> "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+# should not fail
+ts_init_subtest "tag_with_space"
+$TS_HELPER_LOGGER --no-act -s -t "A B" "tag_with_space" > "$TS_OUTPUT" 2>&1
+$TS_HELPER_LOGGER --no-act -s -t "A B" --rfc5424 "tag_with_space_rfc5424" >> "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "rfc5424_msgid_with_space"
+$TS_HELPER_LOGGER --no-act -s -t "rfc5424_msgid_with_space" --rfc5424 --msgid="A B" "message" > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_finalize