Module: check_mk
Branch: master
Commit: 4e6f12b186f43a6af2feaab660005d86f5842c24
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4e6f12b186f43a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 22 14:07:23 2016 +0200
Moved some checks from git post receive hooks to tests
---
tests/agents/windows/test_precompiled_age.py | 58 ++++++++++++++++++++++++++
tests/checkman/test_manpages.py | 49 ++++++++++++++++++++++
2 files changed, 107 insertions(+)
diff --git a/tests/agents/windows/test_precompiled_age.py
b/tests/agents/windows/test_precompiled_age.py
new file mode 100644
index 0000000..a5d19a3
--- /dev/null
+++ b/tests/agents/windows/test_precompiled_age.py
@@ -0,0 +1,58 @@
+#!/usr/bin/python
+# encoding: utf-8
+
+import os
+import glob
+from testlib import cmk_path
+
+precompiled_files = [
+ 'check_mk_agent.exe',
+ 'check_mk_agent-64.exe',
+ 'check_mk_agent.unversioned.exe',
+ 'check_mk_agent-64.unversioned.exe',
+ 'install_agent-64.exe',
+ 'install_agent.exe',
+ 'check_mk_agent.msi',
+]
+
+
+def test_precompiled_files_present():
+ for filename in precompiled_files:
+ path = "%s/agents/windows/%s" % (cmk_path(), filename)
+ assert os.path.exists(path)
+
+
+def test_precompiled_file_ages():
+ newest_source_file, newest_source_time = find_newest_source_file()
+
+ for filename in precompiled_files:
+ path = "%s/agents/windows/%s" % (cmk_path(), filename)
+ commit_time = last_commit_time(path)
+ assert newest_source_time > commit_time, \
+ "%s is newer than source code file %s" % (path,
newest_source_file)
+
+
+def find_newest_source_file():
+ newest_path, newest_commit_time = None, 0
+
+ for dirpath, dirnames, filenames in os.walk("%s/agents/windows" %
cmk_path()):
+ for filename in filenames:
+ if not filename.endswith(".cc") and not
filename.endswith(".h"):
+ continue
+
+ path = "%s/%s" % (dirpath, filename)
+ commit_time = last_commit_time(path)
+ if commit_time > newest_commit_time:
+ newest_path, newest_commit_time = path, commit_time
+
+ assert newest_path != None
+ assert newest_commit_time != 0
+
+ return newest_path, newest_commit_time
+
+
+def last_commit_time(path):
+ lines = os.popen('unset GIT_DIR ; cd %s ; '
+ 'git log -n 1 --date=raw -- %s' % (os.path.dirname(path),
path)).readlines()
+ timestamp = int(lines[2].split()[1])
+ return timestamp
diff --git a/tests/checkman/test_manpages.py b/tests/checkman/test_manpages.py
new file mode 100644
index 0000000..8522abc
--- /dev/null
+++ b/tests/checkman/test_manpages.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+# encoding: utf-8
+
+import os
+import sys
+from testlib import cmk_path
+
+
+def test_manpage_files():
+ os.chdir(cmk_path())
+
+ checkend_manpages = 0
+ for f in os.listdir("%s/checkman" % cmk_path()):
+ if f[0] == ".":
+ continue
+ _check_manpage(f)
+ checkend_manpages += 1
+
+ assert checkend_manpages > 0
+
+
+def _check_manpage(name):
+ found_catalog = False
+ for line in open("%s/checkman/%s" % (cmk_path(), name)):
+ if line.startswith("catalog: "):
+ found_catalog = True
+
+ assert found_catalog, "Did not find \"catalog:\" header in manpage
\"%s\"" % name
+
+
+def test_manpage_list():
+ result = os.popen("cd %s ; ./check_mk --list-man 2>&1" %
cmk_path()).read()
+ assert result != ""
+ assert not "ERROR" in result, "Manpage list broken \"./check_mk
--list-man\": %s\"" % result
+ assert type(eval(result)) == dict
+
+
+def test_missing_manpage():
+ missing = []
+
+ checks = 0
+ for line in os.popen('cd %s ; ./check_mk --list-checks' %
cmk_path()).readlines():
+ checks += 1
+ line = line.strip()
+ check_name = line.split(" ", 1)[0]
+ assert '(no man page present)' not in line, "Manpage missing:
%s" % check_name
+
+ if checks == 0:
+ raise Exception("\"./check_mk --list-checks\" Did not output a
checks")