From 1f8af0dca33bcef7a59b1d3f3f384c8819f329c6 Mon Sep 17 00:00:00 2001
From: Hanspeter Spalinger <hanspeter@spahan.ch>
Date: Wed, 10 Aug 2016 11:16:40 +0200
Subject: [PATCH] update tests to test for new options

---
 tests/test_check.py       | 34 +++++++++++++++++++++++++---------
 tests/test_crontab.lookup |  3 +++
 2 files changed, 28 insertions(+), 9 deletions(-)
 create mode 100644 tests/test_crontab.lookup

diff --git a/tests/test_check.py b/tests/test_check.py
index 57246d5..642f7fc 100755
--- a/tests/test_check.py
+++ b/tests/test_check.py
@@ -307,11 +307,10 @@ class CheckCrontabUnitTest(unittest.TestCase):
       exp_rc = 0
     return (exp_warn, exp_fail, exp_rc)
 
-  def CheckACrontab(self, crontab, whitelisted_users=None):
+  def CheckACrontab(self, arguments):
     log = check.LogCounter()
-    crontab_file = os.path.join(BASE_PATH, crontab)
-    (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(crontab_file)
-    self.assertEquals(check.check_crontab(crontab_file, log, whitelisted_users), exp_rc,
+    (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(arguments.crontab)
+    self.assertEquals(check.check_crontab(arguments, log), exp_rc,
                       'Failed to return %d for crontab errors.' % exp_rc)
     self.assertEquals(log.warn_count, exp_warn,
                       'Found %d warns not %d.' % (log.warn_count, exp_warn))
@@ -319,19 +318,36 @@ class CheckCrontabUnitTest(unittest.TestCase):
                       'Found %d errors not %d.' % (log.error_count, exp_fail))
 
   def testCheckBadCrontab(self):
-    self.CheckACrontab('test_crontab')
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab')
+    self.CheckACrontab(args)
 
   def testCheckWarnCrontab(self):
-    self.CheckACrontab('test_crontab.warn')
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab.warn')
+    self.CheckACrontab(args)
 
   def testCheckWarnWithDisablesCrontab(self):
-    self.CheckACrontab('test_crontab.no-warn')
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab.no-warn')
+    self.CheckACrontab(args)
 
   def testCheckBadWithDisablesCrontab(self):
-    self.CheckACrontab('test_crontab.disable')
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab.disable')
+    self.CheckACrontab(args)
 
   def testCheckWarnWithWhitelistedUser(self):
-    self.CheckACrontab('test_crontab.whitelist', ['not_a_user'])
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab.whitelist')
+    args.whitelisted_users = ['not_a_user']
+    self.CheckACrontab(args)
+
+  def testCheckBadWithUserLookup(self):
+    args = type("", (), {})()
+    args.crontab = os.path.join(BASE_PATH, 'test_crontab.lookup')
+    args.check_passwd = False
+    self.CheckACrontab(args)
 
 
 if __name__ == '__main__':
diff --git a/tests/test_crontab.lookup b/tests/test_crontab.lookup
new file mode 100644
index 0000000..8463cd7
--- /dev/null
+++ b/tests/test_crontab.lookup
@@ -0,0 +1,3 @@
+# WARN 1 for questionable file name.
+# WARN 1 for missing user
+1 * * * * root Command
-- 
GitLab