summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-16 07:07:34 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-16 07:07:34 +0000
commit11d3d24b758c5df43bec1761ceae70d8cb012953 (patch)
tree3ebbacc9162e122c551abe2a59c36e0f013ff2c0 /test
parent036ba7a439f13c5eb110ee0d2663583ef31ee723 (diff)
downloadpuppet-11d3d24b758c5df43bec1761ceae70d8cb012953.tar.gz
puppet-11d3d24b758c5df43bec1761ceae70d8cb012953.tar.xz
puppet-11d3d24b758c5df43bec1761ceae70d8cb012953.zip
cron is working, but i want to write quite a few more test cases
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@677 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/types/tc_cron.rb131
1 files changed, 125 insertions, 6 deletions
diff --git a/test/types/tc_cron.rb b/test/types/tc_cron.rb
index d35d873f3..a33ee992d 100755
--- a/test/types/tc_cron.rb
+++ b/test/types/tc_cron.rb
@@ -23,6 +23,23 @@ class TestExec < TestPuppet
unless defined? @me
raise "Could not retrieve user name; 'id' did not work"
end
+ tab = Puppet::Type::Cron.crontype.read(@me)
+
+ if $? == 0
+ @currenttab = tab
+ else
+ @currenttab = nil
+ end
+
+ super
+ end
+
+ def teardown
+ if @currenttab
+ Puppet::Type::Cron.crontype.write(@me, @currenttab)
+ else
+ Puppet::Type::Cron.crontype.remove(@me)
+ end
super
end
@@ -32,18 +49,120 @@ class TestExec < TestPuppet
}
end
- def test_mkcron
+ def mkcron(name)
cron = nil
assert_nothing_raised {
cron = Puppet::Type::Cron.create(
- :command => "date > %s/crontest" % tmpdir(),
- :name => "testcron",
- :user => @me
+ :command => "date > %s/crontest%s" % [tmpdir(), name],
+ :name => name,
+ :user => @me,
+ :minute => rand(59),
+ :month => "1",
+ :monthday => "1",
+ :hour => "1"
)
}
- comp = newcomp("crontest", cron)
+ return cron
+ end
+
+ def cyclecron(cron)
+ name = cron.name
+ comp = newcomp(name, cron)
+
+ trans = assert_events(comp, [:cron_created], name)
+ cron.retrieve
+ assert(cron.insync?)
+ trans = assert_events(comp, [], name)
+ cron[:command] = :notfound
+ trans = assert_events(comp, [:cron_deleted], name)
+ end
+
+ def test_mkcronwithnotab
+ Puppet::Type::Cron.crontype.remove(@me)
+
+ cron = mkcron("crontest")
+ cyclecron(cron)
+ end
+
+ def test_mkcronwithtab
+ Puppet::Type::Cron.crontype.remove(@me)
+ Puppet::Type::Cron.crontype.write(@me,
+"1 1 1 1 * date > %s/crontesting\n" % testdir()
+ )
+
+ cron = mkcron("crontest")
+ cyclecron(cron)
+ end
+
+ def test_makeandretrievecron
+ Puppet::Type::Cron.crontype.remove(@me)
+
+ name = "storeandretrieve"
+ cron = mkcron(name)
+ comp = newcomp(name, cron)
+ trans = assert_events(comp, [:cron_created], name)
+
+ cron = nil
+
+ Puppet::Type::Cron.clear
+ Puppet::Type::Cron.retrieve(@me)
+
+ assert(cron = Puppet::Type::Cron[name], "Could not retrieve named cron")
+ assert_instance_of(Puppet::Type::Cron, cron)
+ end
+
+ def test_arguments
+ values = {
+ :monthday => {
+ :valid => [ 1, 13, ],
+ :invalid => [ -1, 0, 32 ]
+ },
+ :weekday => {
+ :valid => [ 0, 3, 6, "tue", "wed", "Wed", "MOnday", "SaTurday" ],
+ :invalid => [ -1, 7, "tues", "teusday", "thurs" ]
+ },
+ :hour => {
+ :valid => [ 0, 21, 23 ],
+ :invalid => [ -1, 24 ]
+ },
+ :minute => {
+ :valid => [ 0, 34, 59 ],
+ :invalid => [ -1, 60 ]
+ },
+ :month => {
+ :valid => [ 1, 11, 12, "mar", "March", "apr", "October", "DeCeMbEr" ],
+ :invalid => [ 0, 13, "marc", "sept" ]
+ }
+ }
+
+ cron = mkcron("valtesting")
+ values.each { |param, hash|
+ hash.each { |type, values|
+ values.each { |value|
+ case type
+ when :valid:
+ assert_nothing_raised {
+ cron[param] = value
+ }
+
+ if value.is_a?(Integer)
+ assert_equal(value, cron[param],
+ "Cron value was not set correctly")
+ end
+ when :invalid:
+ assert_raise(Puppet::Error, "%s is incorrectly a valid %s" %
+ [value, param]) {
+ cron[param] = value
+ }
+ end
- trans = assert_events(comp, [:cron_created], "crontest")
+ if value.is_a?(Integer)
+ value = value.to_s
+ redo
+ end
+ }
+ }
+ }
end
end