Permalink
Browse files

(maint) update cron whitespace strip acceptance test

Since f5d2367 leading and trailing whitespace was stripped from the
cron command to ensure writing cron entries is idempotent. This made the
cron `should_not_rewrite_with_trailing_whitespace.rb` acceptance test
meaningless. This commit updates the acceptance test to confirm the fix
for #656 and updates the test name to reflect the expected behavior.
  • Loading branch information...
1 parent 91fa7f1 commit 8ccb4fa7859c7d972add38164efe583f5cad5be3 @adrienthebo adrienthebo committed Mar 28, 2013
View
25 acceptance/tests/resource/cron/should_not_rewrite_with_trailing_whitespace.rb
@@ -1,25 +0,0 @@
-test_name "should not rewrite if the job has trailing whitespace"
-confine :except, :platform => 'windows'
-
-require 'puppet/acceptance/common_utils'
-extend Puppet::Acceptance::CronUtils
-
-agents.each do |host|
- step "ensure the user exist via puppet"
- setup host
-
- step "apply the resource on the host using puppet resource"
- on(host, puppet_resource("cron", "crontest", "user=tstuser", "command='date > /dev/null '", "ensure=present")) do
- assert_match(/created/, stdout, "Did not create crontab for tstuser on #{host}")
- end
-
- step "verify that crontab -l contains what you expected"
- run_cron_on(host, :list, 'tstuser') do
- assert_match(/\* \* \* \* \* date > .dev.null /, stdout, "Incorrect crontab for tstuser on #{host}")
- end
-
- step "apply the resource again on the host using puppet resource and check nothing happened"
- on(host, puppet_resource("cron", "crontest", "user=tstuser", "command='date > /dev/null'", "ensure=present")) do
- assert_no_match(/ensure: created/, stdout, "Rewrote the line with trailing space in crontab for tstuser on #{host}")
- end
-end
View
34 acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace.rb
@@ -0,0 +1,34 @@
+test_name "(#656) leading and trailing whitespace in cron entries should should be stripped"
+confine :except, :platform => 'windows'
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+agents.each do |host|
+ step "create user account for testing cron entries"
+ setup host
+ teardown do
+ step "tear down user account for cron entries"
+ clean host
+ end
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command=' date > /dev/null '", "ensure=present")) do
+ assert_match(/created/, stdout, "Did not create crontab for tstuser on #{host}")
+ end
+
+ step "verify the added crontab entry has stripped whitespace"
+ run_cron_on(host, :list, 'tstuser') do
+ assert_match(/\* \* \* \* \* date > .dev.null/, stdout, "Incorrect crontab for tstuser on #{host}")
+ end
+
+ step "apply the resource with trailing whitespace and check nothing happened"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command='date > /dev/null '", "ensure=present")) do
+ assert_no_match(/ensure: created/, stdout, "Rewrote the line with trailing space in crontab for tstuser on #{host}")
+ end
+
+ step "apply the resource with leading whitespace and check nothing happened"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command=' date > /dev/null'", "ensure=present")) do
+ assert_no_match(/ensure: created/, stdout, "Rewrote the line with trailing space in crontab for tstuser on #{host}")
+ end
+end

0 comments on commit 8ccb4fa

Please sign in to comment.