Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kevin Lyda
chkcrontab
Commits
1f8af0dc
Commit
1f8af0dc
authored
Aug 10, 2016
by
Hanspeter Spalinger
Browse files
update tests to test for new options
parent
434a090a
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_check.py
View file @
1f8af0dc
...
@@ -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__'
:
...
...
tests/test_crontab.lookup
0 → 100644
View file @
1f8af0dc
# WARN 1 for questionable file name.
# WARN 1 for missing user
1 * * * * root Command
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment