Commit 1f8af0dc authored by Hanspeter Spalinger's avatar Hanspeter Spalinger
Browse files

update tests to test for new options

parent 434a090a
...@@ -307,11 +307,10 @@ class CheckCrontabUnitTest(unittest.TestCase): ...@@ -307,11 +307,10 @@ class CheckCrontabUnitTest(unittest.TestCase):
exp_rc = 0 exp_rc = 0
return (exp_warn, exp_fail, exp_rc) return (exp_warn, exp_fail, exp_rc)
def CheckACrontab(self, crontab, whitelisted_users=None): def CheckACrontab(self, arguments):
log = check.LogCounter() log = check.LogCounter()
crontab_file = os.path.join(BASE_PATH, crontab) (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(arguments.crontab)
(exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(crontab_file) self.assertEquals(check.check_crontab(arguments, log), exp_rc,
self.assertEquals(check.check_crontab(crontab_file, log, whitelisted_users), exp_rc,
'Failed to return %d for crontab errors.' % exp_rc) 'Failed to return %d for crontab errors.' % exp_rc)
self.assertEquals(log.warn_count, exp_warn, self.assertEquals(log.warn_count, exp_warn,
'Found %d warns not %d.' % (log.warn_count, exp_warn)) 'Found %d warns not %d.' % (log.warn_count, exp_warn))
...@@ -319,19 +318,36 @@ class CheckCrontabUnitTest(unittest.TestCase): ...@@ -319,19 +318,36 @@ class CheckCrontabUnitTest(unittest.TestCase):
'Found %d errors not %d.' % (log.error_count, exp_fail)) 'Found %d errors not %d.' % (log.error_count, exp_fail))
def testCheckBadCrontab(self): def testCheckBadCrontab(self):
self.CheckACrontab('test_crontab') args = type("", (), {})()
args.crontab = os.path.join(BASE_PATH, 'test_crontab')
self.CheckACrontab(args)
def testCheckWarnCrontab(self): 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): 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): 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): 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__': if __name__ == '__main__':
......
# WARN 1 for questionable file name.
# WARN 1 for missing user
1 * * * * root Command
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment