aboutsummaryrefslogtreecommitdiff
path: root/spec/spec_helper_acceptance.rb
diff options
context:
space:
mode:
authorEnis Inan <enis.inan@puppet.com>2018-12-13 02:10:54 -0800
committerEnis Inan <enis.inan@puppet.com>2019-01-09 08:48:17 -0800
commite76bd24dcb33ab71440633303124ea99d59b7783 (patch)
tree6cb604dc4476a28dc5c031181067bd07263d446d /spec/spec_helper_acceptance.rb
parenta6fe97eada00c6a78fd0036c3893bd8a8208846a (diff)
downloadpuppet-cron_core-e76bd24dcb33ab71440633303124ea99d59b7783.tar.gz
puppet-cron_core-e76bd24dcb33ab71440633303124ea99d59b7783.tar.bz2
(maint) Add more crontab provider tests
This commit adds the following tests to the cron resource: * A test to ensure that the crontab provider writes the crontab file of a new user * A test to ensure that the crontab provider fails to write the crontab file of a nonexistent user * A test to ensure that the crontab provider writes an originally unauthorized user's crontab file _if_ Puppet authorizes them in the middle of the run These tests are part of the crontab provider's specifications and should have been added before.
Diffstat (limited to 'spec/spec_helper_acceptance.rb')
-rw-r--r--spec/spec_helper_acceptance.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index e4f0182..57c5b21 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -4,6 +4,34 @@ require 'beaker/puppet_install_helper'
$LOAD_PATH << File.join(__dir__, 'acceptance/lib')
+# TODO: This should be added to Beaker
+def assert_matching_arrays(expected, actual, message = '')
+ assert_equal(expected.sort, actual.sort, message)
+end
+
+# TODO: Remove the wrappers to user_present
+# and user_absent if Beaker::Host's user_present
+# and user_absent functions are fixed to work with
+# Arista (EOS).
+
+def user_present(host, username)
+ case host['platform']
+ when %r{eos}
+ on(host, "useradd #{username}")
+ else
+ host.user_present(username)
+ end
+end
+
+def user_absent(host, username)
+ case host['platform']
+ when %r{eos}
+ on(host, "userdel #{username}", acceptable_exit_codes: [0, 1])
+ else
+ host.user_absent(username)
+ end
+end
+
def beaker_opts
{ debug: true, trace: true, expect_failures: true, acceptable_exit_codes: (0...256) }
# { expect_failures: true, acceptable_exit_codes: (0...256) }
@@ -29,6 +57,43 @@ def setup(agent, o = {})
package {'cron': name=> $cron, ensure=>present, }))
end
+# Returns all of the lines that correspond to crontab entries
+# on the agent. For simplicity, these are any lines that do
+# not begin with '#'.
+def crontab_entries_of(host, username)
+ crontab_contents = run_cron_on(host, :list, username).stdout.strip
+ crontab_contents.lines.map(&:chomp).reject { |line| line =~ %r{^#} }
+end
+
+def resource_manifest(resource, title, params = {})
+ params_str = params.map { |param, value|
+ # This is not quite correct for all parameter values,
+ # but it is good enough for most purposes.
+ value_str = value.to_s
+ value_str = "\"#{value_str}\"" if value.is_a?(String)
+
+ " #{param} => #{value_str}"
+ }.join(",\n")
+
+ <<-MANIFEST
+ #{resource} { '#{title}':
+ #{params_str}
+}
+ MANIFEST
+end
+
+def file_manifest(path, params = {})
+ resource_manifest('file', path, params)
+end
+
+def cron_manifest(entry_name, params = {})
+ resource_manifest('cron', entry_name, params)
+end
+
+def user_manifest(username, params = {})
+ resource_manifest('user', username, params)
+end
+
RSpec.configure do |c|
c.before :suite do
unless ENV['BEAKER_provision'] == 'no'