[Fuego] [PATCH] monit: Add test cases of command monit.

Yuan Chao yuanc.fnst at cn.fujitsu.com
Wed Jun 12 00:55:59 UTC 2019


This is a simple test to check the option hash/help/id/logfile/quit/syntax/version of command monit.

Signed-off-by: Yuan Chao <yuanc.fnst at cn.fujitsu.com>
---
 tests/Functional.monit/fuego_test.sh          | 17 +++++++++++++++++
 tests/Functional.monit/monit_test.sh          |  4 ++++
 tests/Functional.monit/parser.py              | 20 ++++++++++++++++++++
 tests/Functional.monit/spec.json              |  6 ++++++
 tests/Functional.monit/test.yaml              | 19 +++++++++++++++++++
 tests/Functional.monit/tests/monit_hash.sh    | 17 +++++++++++++++++
 tests/Functional.monit/tests/monit_help.sh    | 13 +++++++++++++
 tests/Functional.monit/tests/monit_id.sh      | 13 +++++++++++++
 tests/Functional.monit/tests/monit_logfile.sh | 19 +++++++++++++++++++
 tests/Functional.monit/tests/monit_quit.sh    | 20 ++++++++++++++++++++
 tests/Functional.monit/tests/monit_syntax.sh  | 13 +++++++++++++
 tests/Functional.monit/tests/monit_version.sh | 13 +++++++++++++
 12 files changed, 174 insertions(+)
 create mode 100644 tests/Functional.monit/fuego_test.sh
 create mode 100644 tests/Functional.monit/monit_test.sh
 create mode 100644 tests/Functional.monit/parser.py
 create mode 100644 tests/Functional.monit/spec.json
 create mode 100644 tests/Functional.monit/test.yaml
 create mode 100644 tests/Functional.monit/tests/monit_hash.sh
 create mode 100644 tests/Functional.monit/tests/monit_help.sh
 create mode 100644 tests/Functional.monit/tests/monit_id.sh
 create mode 100644 tests/Functional.monit/tests/monit_logfile.sh
 create mode 100644 tests/Functional.monit/tests/monit_quit.sh
 create mode 100644 tests/Functional.monit/tests/monit_syntax.sh
 create mode 100644 tests/Functional.monit/tests/monit_version.sh

diff --git a/tests/Functional.monit/fuego_test.sh b/tests/Functional.monit/fuego_test.sh
new file mode 100644
index 0000000..c9e3e40
--- /dev/null
+++ b/tests/Functional.monit/fuego_test.sh
@@ -0,0 +1,17 @@
+function test_pre_check {
+    assert_has_program monit
+}
+
+function test_deploy {
+    put $TEST_HOME/monit_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./monit_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/tests/Functional.monit/monit_test.sh b/tests/Functional.monit/monit_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/tests/Functional.monit/monit_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/tests/Functional.monit/parser.py b/tests/Functional.monit/parser.py
new file mode 100644
index 0000000..f25a608
--- /dev/null
+++ b/tests/Functional.monit/parser.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+import common as plib
+
+measurements = {}
+measurements = collections.OrderedDict()
+
+regex_string = '^ -> (.*): TEST-(.*)$'
+matches = plib.parse_log(regex_string)
+
+if matches:
+    for m in matches:
+        measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL'
+
+# split the output for each testcase
+plib.split_output_per_testcase(regex_string, measurements)
+
+sys.exit(plib.process(measurements))
diff --git a/tests/Functional.monit/spec.json b/tests/Functional.monit/spec.json
new file mode 100644
index 0000000..13ad82e
--- /dev/null
+++ b/tests/Functional.monit/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.monit",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.monit/test.yaml b/tests/Functional.monit/test.yaml
new file mode 100644
index 0000000..6681827
--- /dev/null
+++ b/tests/Functional.monit/test.yaml
@@ -0,0 +1,19 @@
+fuego_package_version: 1
+name: Functional.monit
+description: |
+        Monit a tool for managing and monitoring processes, files, directories and filesystems on a Unix system.
+        This is a simple test to check the option hash/help/id/logfile/quit/syntax/version of command monit.
+license: BSD-3-Clause
+author: Yuan Chao <yuanc.fnst at cn.fujitsu.com>
+maintainer: Wang Mingyu <wangmy at cn.fujitsu.com>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['monitor']
+data_files:
+ - monit_test.sh
+ - fuego_test.sh
+ - parser.py
+ - spec.json
+ - test.yaml
+ - tests
diff --git a/tests/Functional.monit/tests/monit_hash.sh b/tests/Functional.monit/tests/monit_hash.sh
new file mode 100644
index 0000000..2c4d450
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_hash.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if hash option can execute.
+#  1) Option: -H
+
+test="monit"
+
+test_file="test_monit.txt"
+touch $test_file
+
+if monit -H $test_file | grep "$test_file"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f $test_file
diff --git a/tests/Functional.monit/tests/monit_help.sh b/tests/Functional.monit/tests/monit_help.sh
new file mode 100644
index 0000000..4d7ca6a
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_help.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if help option can execute.
+#  1) Option: -h
+
+test="monit"
+
+if monit -h | grep "[uU]sage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.monit/tests/monit_id.sh b/tests/Functional.monit/tests/monit_id.sh
new file mode 100644
index 0000000..bf5f0a2
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_id.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if id option can execute.
+#  1) Option: --id
+
+test="monit"
+
+if monit --id | grep "Monit ID"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.monit/tests/monit_logfile.sh b/tests/Functional.monit/tests/monit_logfile.sh
new file mode 100644
index 0000000..15e86d2
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_logfile.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if logfile option can execute.
+#  1) Option: -l
+
+test="monit"
+
+test_file="monit.log"
+monit -l $test_file
+
+if cat $test_file | grep "started"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+monit quit
+sleep 3
+rm -f $test_file
diff --git a/tests/Functional.monit/tests/monit_quit.sh b/tests/Functional.monit/tests/monit_quit.sh
new file mode 100644
index 0000000..9bdf7e9
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_quit.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if quit option can execute.
+#  1) Option: quit
+
+test="monit"
+
+test_file="monit.log"
+monit -d 10 -l $test_file
+sleep 3
+monit quit
+sleep 3
+
+if cat $test_file | grep "stopped"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f $test_file
diff --git a/tests/Functional.monit/tests/monit_syntax.sh b/tests/Functional.monit/tests/monit_syntax.sh
new file mode 100644
index 0000000..68a6b4d
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_syntax.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if -t option can execute.
+#  1) Option: -t
+
+test="monit"
+
+if monit -t | grep "syntax"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.monit/tests/monit_version.sh b/tests/Functional.monit/tests/monit_version.sh
new file mode 100644
index 0000000..a27e6f4
--- /dev/null
+++ b/tests/Functional.monit/tests/monit_version.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command monit, and check if version option can execute.
+#  1) Option: -V
+
+test="monit"
+
+if monit -V | grep "version"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
-- 
1.8.3.1





More information about the Fuego mailing list