Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move tests from puppet-acceptance repo

  • Loading branch information...
commit db26326364103ed2f7fbd56d246d700cc2d9a0f9 1 parent bee1ef7
@djm68 djm68 authored
Showing with 2,045 additions and 0 deletions.
  1. +50 −0 acceptance/pending/ticket_3360_allow_duplicate_csr_with_option_set.rb
  2. 0  acceptance/pending/ticket_3360_reject_duplicate_csr_with_option_unset.rb
  3. +18 −0 acceptance/pending/ticket_4149_parseonly_should_not_fail.rb
  4. +24 −0 acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb
  5. +28 −0 acceptance/pending/ticket_5027_warn_on_dynamic_scope.rb
  6. +15 −0 acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb
  7. +38 −0 acceptance/pending/ticket_6928_puppet_master_parse_fails.rb
  8. +56 −0 acceptance/tests/apply/classes/parameterized_classes.rb
  9. +20 −0 acceptance/tests/apply/classes/should_allow_param_override.rb
  10. +29 −0 acceptance/tests/apply/classes/should_allow_param_undef_override.rb
  11. +11 −0 acceptance/tests/apply/classes/should_include_resources_from_class.rb
  12. +6 −0 acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb
  13. +15 −0 acceptance/tests/apply/conditionals/should_evaluate_else.rb
  14. +15 −0 acceptance/tests/apply/conditionals/should_evaluate_elsif.rb
  15. +12 −0 acceptance/tests/apply/conditionals/should_evaluate_empty.rb
  16. +12 −0 acceptance/tests/apply/conditionals/should_evaluate_false.rb
  17. +15 −0 acceptance/tests/apply/conditionals/should_evaluate_if.rb
  18. +13 −0 acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb
  19. +11 −0 acceptance/tests/apply/conditionals/should_evaluate_undef.rb
  20. +10 −0 acceptance/tests/apply/hashes/should_not_reassign.rb
  21. +22 −0 acceptance/tests/apply/virtual/should_realize.rb
  22. +36 −0 acceptance/tests/apply/virtual/should_realize_complex_query.rb
  23. +22 −0 acceptance/tests/apply/virtual/should_realize_many.rb
  24. +24 −0 acceptance/tests/apply/virtual/should_realize_query.rb
  25. +24 −0 acceptance/tests/apply/virtual/should_realize_query_array.rb
  26. +5 −0 acceptance/tests/doc/should_print_function_reference.rb
  27. +5 −0 acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb
  28. +22 −0 acceptance/tests/file_hello_world.rb
  29. +19 −0 acceptance/tests/jeff_append_to_array.rb
  30. +65 −0 acceptance/tests/key_compare_puppet_conf_configprint.rb
  31. +16 −0 acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb
  32. +15 −0 acceptance/tests/puppet_apply_basics.rb
  33. +5 −0 acceptance/tests/puppet_apply_should_show_a_notice.rb
  34. +4 −0 acceptance/tests/puppet_master_help_should_mention_puppet_master.rb
  35. +31 −0 acceptance/tests/resource/cron/should_create_cron.rb
  36. +40 −0 acceptance/tests/resource/cron/should_match_existing.rb
  37. +36 −0 acceptance/tests/resource/cron/should_remove_cron.rb
  38. +36 −0 acceptance/tests/resource/cron/should_remove_matching.rb
  39. +42 −0 acceptance/tests/resource/cron/should_update_existing.rb
  40. +34 −0 acceptance/tests/resource/exec/should_not_run_command_creates.rb
  41. +31 −0 acceptance/tests/resource/exec/should_run_command.rb
  42. +16 −0 acceptance/tests/resource/exec/should_set_path.rb
  43. +37 −0 acceptance/tests/resource/file/content_attribute.rb
  44. +15 −0 acceptance/tests/resource/file/should_create_directory.rb
  45. +15 −0 acceptance/tests/resource/file/should_create_empty.rb
  46. +27 −0 acceptance/tests/resource/file/should_create_symlink.rb
  47. +21 −0 acceptance/tests/resource/file/should_remove_dir.rb
  48. +12 −0 acceptance/tests/resource/file/should_remove_file.rb
  49. +100 −0 acceptance/tests/resource/file/source_attribtute.rb
  50. +20 −0 acceptance/tests/resource/group/should_create.rb
  51. +14 −0 acceptance/tests/resource/group/should_destroy.rb
  52. +23 −0 acceptance/tests/resource/group/should_modify_gid.rb
  53. +15 −0 acceptance/tests/resource/group/should_not_create_existing.rb
  54. +13 −0 acceptance/tests/resource/group/should_not_destoy_unexisting.rb
  55. +15 −0 acceptance/tests/resource/group/should_query.rb
  56. +30 −0 acceptance/tests/resource/group/should_query_all.rb
  57. +15 −0 acceptance/tests/resource/host/should_create.rb
  58. +16 −0 acceptance/tests/resource/host/should_create_aliases.rb
  59. +19 −0 acceptance/tests/resource/host/should_destroy.rb
  60. +19 −0 acceptance/tests/resource/host/should_modify_alias.rb
  61. +19 −0 acceptance/tests/resource/host/should_modify_ip.rb
  62. +17 −0 acceptance/tests/resource/host/should_not_create_existing.rb
  63. +15 −0 acceptance/tests/resource/host/should_query.rb
  64. +26 −0 acceptance/tests/resource/host/should_query_all.rb
  65. +21 −0 acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb
  66. +12 −0 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb
  67. +36 −0 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh
  68. +12 −0 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb
  69. +37 −0 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh
  70. +20 −0 acceptance/tests/resource/user/should_create.rb
  71. +30 −0 acceptance/tests/resource/user/should_create_with_gid.rb
  72. +19 −0 acceptance/tests/resource/user/should_destroy.rb
  73. +41 −0 acceptance/tests/resource/user/should_modify_gid.rb
  74. +6 −0 acceptance/tests/resource/user/should_not_create_existing.rb
  75. +11 −0 acceptance/tests/resource/user/should_not_destoy_unexisting.rb
  76. +15 −0 acceptance/tests/resource/user/should_query.rb
  77. +30 −0 acceptance/tests/resource/user/should_query_all.rb
  78. +7 −0 acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb
  79. +8 −0 acceptance/tests/ticket_3656_requiring_multiple_resources.rb
  80. +20 −0 acceptance/tests/ticket_4059_ralsh_can_change_settings.rb
  81. +5 −0 acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb
  82. +13 −0 acceptance/tests/ticket_4233_resource_with_a_newline.rb
  83. +17 −0 acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb
  84. +13 −0 acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb
  85. +21 −0 acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb
  86. +22 −0 acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb
  87. +21 −0 acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb
  88. +50 −0 acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb
  89. +43 −0 acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb
  90. +22 −0 acceptance/tests/ticket_6418_file_recursion_and_audit.rb
  91. +26 −0 acceptance/tests/ticket_6541_invalid_filebucket_files.rb
  92. +16 −0 acceptance/tests/ticket_6734_6256_5530_5503.rb
View
50 acceptance/pending/ticket_3360_allow_duplicate_csr_with_option_set.rb
@@ -0,0 +1,50 @@
+test_name "#3360: Allow duplicate CSR when allow_duplicate_certs is on"
+
+agent_hostnames = agents.map {|a| a.to_s}
+
+# Kill running Puppet Master -- should not be running at this point
+step "Master: kill running Puppet Master"
+on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill || echo \"Puppet Master not running\""
+
+step "Master: Start Puppet Master"
+on master, puppet_master("--allow_duplicate_certs --certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop")
+
+step "Generate a certificate request for the agent"
+on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}"
+
+step "Collect the original certs"
+on master, puppet_cert("--sign --all")
+original_certs = on master, puppet_cert("--list --all")
+
+old_certs = {}
+original_certs.stdout.each_line do |line|
+ if line =~ /^\+ (\S+) \((.+)\)$/
+ old_certs[$1] = $2
+ puts "old cert: #{$1} #{$2}"
+ end
+end
+
+step "Make another request with the same certname"
+on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}"
+
+step "Collect the new certs"
+
+on master, puppet_cert("--sign --all")
+new_cert_list = on master, puppet_cert("--list --all")
+
+new_certs = {}
+new_cert_list.stdout.each_line do |line|
+ if line =~ /^\+ (\S+) \((.+)\)$/
+ new_certs[$1] = $2
+ puts "new cert: #{$1} #{$2}"
+ end
+end
+
+step "Verify the certs have changed"
+# using the agent name as the key may cause errors;
+# agent name from cfg file is likely to have short name
+# where certs might be signed with long names.
+old_certs.each_key { |key|
+ next if key.include? master # skip the masters cert, only care about agents
+ fail_test("#{key} does not have a new signed certificate") if old_certs[key] == new_certs[key]
+}
View
0  acceptance/pending/ticket_3360_reject_duplicate_csr_with_option_unset.rb
No changes.
View
18 acceptance/pending/ticket_4149_parseonly_should_not_fail.rb
@@ -0,0 +1,18 @@
+test_name "#4149: parseonly should do the right thing"
+
+step "test with a manifest with syntax errors"
+manifest = 'class someclass { notify { "hello, world" } }'
+apply_manifest_on(agents, manifest, :parseonly => true, :acceptable_exit_codes => [1]) {
+ stdout =~ /Could not parse for .*: Syntax error/ or
+ fail_test("didn't get a reported systax error")
+}
+
+step "test with a manifest with correct syntax"
+apply_manifest_on agents,'class someclass { notify("hello, world") }', :parseonly => true
+
+# REVISIT: This tests the current behaviour, which is IMO not actually the
+# correct behaviour. On the other hand, if we change this we might
+# unexpectedly break things out in the wild, so better to be warned than to be
+# surprised by it. --daniel 2010-12-22
+step "test with a class with an invalid attribute"
+apply_manifest_on agents, 'file { "/tmp/whatever": fooble => 1 }', :parseonly => true
View
24 ...g/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb
@@ -0,0 +1,24 @@
+test_name "#4151: defined function should not return true for unrealized virtual resources"
+
+# Jeff McCune <jeff@puppetlabs.com>
+# 2010-07-06
+#
+# This script is expected to exit non-zero if ticket 4151 has not been
+# fixed.
+#
+# The expected behavior is for defined() to only return true if a virtual
+# resource has been realized.
+#
+# This test creates a virtual resource, does NOT realize it, then calls
+# the defined() function against it. If defined returns true, there will
+# be an error since Notify["goodbye"] will require a resource which has
+# not been realized.
+
+
+manifest1 = %q{
+ @notify { "hello": }
+ if (defined(Notify["hello"])) { $requires = [ Notify["hello"] ] }
+ notify { "goodbye": require => $requires }
+}
+
+apply_manifest_on(agents, manifest1)
View
28 acceptance/pending/ticket_5027_warn_on_dynamic_scope.rb
@@ -0,0 +1,28 @@
+test_name "#5027: Issue warnings when using dynamic scope"
+
+step "Apply dynamic scoping manifest on agents"
+apply_manifest_on agents, %q{
+ $foo = 'foo_value'
+
+ class a {
+ $bar = 'bar_value'
+
+ include b
+ }
+
+ class b inherits c {
+ notify { $baz: } # should not generate a warning -- inherited from class c
+ notify { $bar: } # should generate a warning -- uses dynamic scoping
+ notify { $foo: } # should not generate a warning -- comes from top scope
+ }
+
+ class c {
+ $baz = 'baz_value'
+ }
+
+ include a
+}
+
+step "Verify deprecation warning"
+fail_test "Deprecation warning not issued" unless
+ stdout.include? 'warning: Dynamic lookup of $bar will not be supported in future versions. Use a fully-qualified variable name or parameterized classes.'
View
15 acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb
@@ -0,0 +1,15 @@
+test_name "#6710: Relationship syntax should work with title arraysA"
+
+# Jeff McCune <jeff@puppetlabs.com>
+# 2011-03-14
+#
+# If bug 6710 is closed, then this manifests should apply cleanly.
+# There should be a many-to-many relationship established.
+#
+
+apply_manifest_on agents, %q{
+ notify { [ left_one, left_two ]: } -> notify { [ right_one, right_two ]: }
+ notify { left: } -> notify { right: }
+ notify { left_one_to_many: } -> notify { [ right_one_to_many_1, right_one_to_many_2 ]: }
+}
+
View
38 acceptance/pending/ticket_6928_puppet_master_parse_fails.rb
@@ -0,0 +1,38 @@
+test_name "#6928: Puppet --parseonly should return deprication message"
+
+# Create good and bad formatted manifests
+step "Master: create valid, invalid formatted manifests"
+create_remote_file(master, '/tmp/good.pp', %w{notify{good:}} )
+create_remote_file(master, '/tmp/bad.pp', 'notify{bad:')
+
+step "Master: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning"
+on master, puppet_master( %w{--parseonly /tmp/bad.pp} ), :acceptable_exit_codes => [ 1 ]
+ fail_test "Deprecation warning not issued for --parseonly" unless
+ stdout.include? '--parseonly has been removed. Please use \'puppet parser validate <manifest>\''
+
+step "Agents: create valid, invalid formatted manifests"
+agents.each do |host|
+ create_remote_file(host, '/tmp/good.pp', %w{notify{good:}} )
+ create_remote_file(host, '/tmp/bad.pp', 'notify{bad:')
+end
+
+step "Agents: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning"
+agents.each do |host|
+ on(host, "puppet --parseonly /tmp/bad.pp}", :acceptable_exit_codes => [ 1 ]) do
+ fail_test "Deprecation warning not issued for --parseonly" unless
+ stdout.include? '--parseonly has been removed. Please use \'puppet parser validate <manifest>\''
+ end
+end
+
+step "Test Face for ‘parser validate’ with good manifest -- should pass"
+agents.each do |host|
+ on(host, "puppet parser validate /tmp/good.pp", :acceptable_exit_codes => [ 0 ])
+end
+
+step "Test Face for ‘parser validate’ with bad manifest -- should fail"
+agents.each do |host|
+ on(host, "puppet parser validate /tmp/bad.pp", :acceptable_exit_codes => [ 1 ]) do
+ fail_test "Bad manifest detection failed" unless
+ stderr.include? 'Could not run: Could not parse for environment production'
+ end
+end
View
56 acceptance/tests/apply/classes/parameterized_classes.rb
@@ -0,0 +1,56 @@
+test_name "parametrized classes"
+
+########################################################################
+step "should allow param classes"
+manifest = %q{
+class x($y, $z) {
+ notice("${y}-${z}")
+}
+class {x: y => '1', z => '2'}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "inclusion after parameterization failed" unless stdout.include? "1-2"
+end
+
+########################################################################
+# REVISIT: This was ported from the old set of tests, but I think that
+# the desired behaviour has recently changed. --daniel 2010-12-23
+step "should allow param class post inclusion"
+manifest = %q{
+class x($y, $z) {
+ notice("${y}-${z}")
+}
+class {x: y => '1', z => '2'}
+include x
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "inclusion after parameterization failed" unless stdout.include? "1-2"
+end
+
+########################################################################
+step "should allow param classes defaults"
+manifest = %q{
+class x($y, $z='2') {
+ notice("${y}-${z}")
+}
+class {x: y => '1'}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "the default didn't apply as expected" unless stdout.include? "1-2"
+end
+
+########################################################################
+step "should allow param class defaults to be overriden"
+manifest = %q{
+class x($y, $z='2') {
+ notice("${y}-${z}")
+}
+class {x: y => '1', z => '3'}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "the override didn't happen as we expected" unless stdout.include? "1-3"
+end
View
20 acceptance/tests/apply/classes/should_allow_param_override.rb
@@ -0,0 +1,20 @@
+test_name "should allow param override"
+
+manifest = %q{
+class parent {
+ notify { 'msg':
+ message => parent,
+ }
+}
+class child inherits parent {
+ Notify['msg'] {message => 'child'}
+}
+include parent
+include child
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "parameter override didn't work" unless
+ stdout.include? "defined 'message' as 'child'"
+end
+
View
29 acceptance/tests/apply/classes/should_allow_param_undef_override.rb
@@ -0,0 +1,29 @@
+test_name "should allow overriding a parameter to undef in inheritence"
+
+out = "/tmp/class_undef_override_out-#{$$}"
+manifest = %Q{
+ class parent {
+ file { 'test':
+ path => '#{out}',
+ source => '/tmp/class_undef_override_test-#{$$}',
+ }
+ }
+ class child inherits parent {
+ File['test'] {
+ source => undef,
+ content => 'hello new world!',
+ }
+ }
+ include parent
+ include child
+}
+
+step "prepare the target file on all systems"
+on(agents, "echo 'hello world!' > #{out}")
+step "apply the manifest"
+apply_manifest_on(agents, manifest)
+step "verify the file content"
+on(agents, "cat #{out}") do
+ fail_test "the file was not touched" if stdout.include? "hello world!"
+ fail_test "the file was not updated" unless stdout.include? "hello new world"
+end
View
11 acceptance/tests/apply/classes/should_include_resources_from_class.rb
@@ -0,0 +1,11 @@
+test_name "resources declared in a class can be applied with include"
+manifest = %q{
+class x {
+ notify{'a':}
+}
+include x
+}
+apply_manifest_on(agents, manifest) do
+ fail_test "the resource did not apply" unless
+ stdout.include? "defined 'message' as 'a'"
+end
View
6 acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb
@@ -0,0 +1,6 @@
+test_name "resources declared in classes are not applied without include"
+manifest = %q{ class x { notify { 'test': message => 'never invoked' } } }
+apply_manifest_on(agents, manifest) do
+ fail_test "found the notify despite not including it" if
+ stdout.include? "never invoked"
+end
View
15 acceptance/tests/apply/conditionals/should_evaluate_else.rb
@@ -0,0 +1,15 @@
+test_name "else clause will be reached if no expressions match"
+manifest = %q{
+if( 1 == 2) {
+ notice('if')
+} elsif(2 == 3) {
+ notice('elsif')
+} else {
+ notice('else')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "the else clause did not evaluate" unless stdout.include? 'else'
+end
+
View
15 acceptance/tests/apply/conditionals/should_evaluate_elsif.rb
@@ -0,0 +1,15 @@
+test_name "should evaluate the elsif block in a conditional"
+manifest = %q{
+if( 1 == 3) {
+ notice('if')
+} elsif(2 == 2) {
+ notice('elsif')
+} else {
+ notice('else')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't evaluate elsif" unless stdout.include? 'elsif'
+end
+
View
12 acceptance/tests/apply/conditionals/should_evaluate_empty.rb
@@ -0,0 +1,12 @@
+test_name "ensure that undefined variables evaluate as false"
+manifest = %q{
+if $undef_var {
+} else {
+ notice('undef')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "did not evaluate as expected" unless stdout.include? 'undef'
+end
+
View
12 acceptance/tests/apply/conditionals/should_evaluate_false.rb
@@ -0,0 +1,12 @@
+test_name "test that false evaluates to false"
+manifest = %q{
+if false {
+} else {
+ notice('false')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't evaluate false correcly" unless stdout.include? 'false'
+end
+
View
15 acceptance/tests/apply/conditionals/should_evaluate_if.rb
@@ -0,0 +1,15 @@
+test_name = "should evaluate an if block correctly"
+manifest = %q{
+if( 1 == 1) {
+ notice('if')
+} elsif(2 == 2) {
+ notice('elsif')
+} else {
+ notice('else')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't evaluate correctly" unless stdout.include? 'if'
+end
+
View
13 acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb
@@ -0,0 +1,13 @@
+test_name "test that the string 'false' evaluates to true"
+manifest = %q{
+if 'false' {
+ notice('true')
+} else {
+ notice('false')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "string 'false' didn't evaluate as true" unless
+ stdout.include? 'true'
+end
View
11 acceptance/tests/apply/conditionals/should_evaluate_undef.rb
@@ -0,0 +1,11 @@
+test_name "empty string should evaluate as false"
+manifest = %q{
+if '' {
+} else {
+ notice('empty')
+}
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't evaluate as false" unless stdout.include? 'empty'
+end
View
10 acceptance/tests/apply/hashes/should_not_reassign.rb
@@ -0,0 +1,10 @@
+test_name "hash reassignment should fail"
+manifest = %q{
+$my_hash = {'one' => '1', 'two' => '2' }
+$my_hash['one']='1.5'
+}
+
+apply_manifest_on(agents, manifest, :acceptable_exit_codes => [1]) do
+ fail_test "didn't find the failure" unless
+ stderr.include? "Assigning to the hash 'my_hash' with an existing key 'one'"
+end
View
22 acceptance/tests/apply/virtual/should_realize.rb
@@ -0,0 +1,22 @@
+test_name "should realize"
+out = "/tmp/hosts-#{Time.new.to_i}"
+name = "test-#{Time.new.to_i}-host"
+
+manifest = %Q{
+ @host{'#{name}': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
+ realize(Host['#{name}'])
+}
+
+step "clean the system ready for testing"
+on agents, "rm -f #{out}"
+
+step "realize the resource on the hosts"
+apply_manifest_on agents, manifest
+
+step "verify the content of the file"
+on(agents, "cat #{out}") do
+ fail_test "missing host definition" unless stdout.include? name
+end
+
+step "final cleanup of the system"
+on agents, "rm -f #{out}"
View
36 acceptance/tests/apply/virtual/should_realize_complex_query.rb
@@ -0,0 +1,36 @@
+test_name "should realize with complex query"
+out = "/tmp/hosts-#{Time.new.to_i}"
+name = "test-#{Time.new.to_i}-host"
+
+manifest = %Q{
+ @host { '#{name}1':
+ ip => '127.0.0.2',
+ target => '#{out}',
+ host_aliases => ['one', 'two', 'three'],
+ ensure => present,
+ }
+ @host { '#{name}2':
+ ip => '127.0.0.3',
+ target => '#{out}',
+ host_aliases => 'two',
+ ensure => present,
+ }
+ Host<| host_aliases == 'two' and ip == '127.0.0.3' |>
+}
+
+step "clean up target system for test"
+on agents, "rm -f #{out}"
+
+step "run the manifest"
+apply_manifest_on agents, manifest
+
+step "verify the file output"
+on(agents, "cat #{out}") do
+ fail_test "second host not found in output" unless
+ stdout.include? "#{name}2"
+ fail_test "first host was found in output" if
+ stdout.include? "#{name}1"
+end
+
+step "clean up system after testing"
+on agents, "rm -f #{out}"
View
22 acceptance/tests/apply/virtual/should_realize_many.rb
@@ -0,0 +1,22 @@
+test_name "test that realize function takes a list"
+out = "/tmp/hosts-#{Time.new.to_i}"
+name = "test-#{Time.new.to_i}-host"
+
+manifest = %Q{
+ @host{'#{name}1': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
+ @host{'#{name}2': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
+ realize(Host['#{name}1'], Host['#{name}2'])
+}
+
+
+step "clean up target system for test"
+on agents, "rm -f #{out}"
+
+step "run the manifest"
+apply_manifest_on agents, manifest
+
+step "verify the file output"
+on(agents, "cat #{out}") do
+ fail_test "first host not found in output" unless stdout.include? "#{name}1"
+ fail_test "second host not found in output" unless stdout.include? "#{name}2"
+end
View
24 acceptance/tests/apply/virtual/should_realize_query.rb
@@ -0,0 +1,24 @@
+test_name "should realize query"
+out = "/tmp/hosts-#{Time.new.to_i}"
+name = "test-#{Time.new.to_i}-host"
+
+manifest = %Q{
+ @host { '#{name}':
+ ip => '127.0.0.2',
+ target => '#{out}',
+ host_aliases => 'alias',
+ ensure => present,
+ }
+ Host<| ip == '127.0.0.2' |>
+}
+
+step "clean up target system for test"
+on agents, "rm -f #{out}"
+
+step "run the manifest"
+apply_manifest_on agents, manifest
+
+step "verify the file output"
+on(agents, "cat #{out}") do
+ fail_test "host not found in output" unless stdout.include? name
+end
View
24 acceptance/tests/apply/virtual/should_realize_query_array.rb
@@ -0,0 +1,24 @@
+test_name "should realize query array"
+out = "/tmp/hosts-#{Time.new.to_i}"
+name = "test-#{Time.new.to_i}-host"
+
+manifest = %Q{
+ @host { '#{name}':
+ ip => '127.0.0.2',
+ target => '#{out}',
+ host_aliases => ['one', 'two', 'three'],
+ ensure => present,
+ }
+ Host<| host_aliases == 'two' |>
+}
+
+step "clean up target system for test"
+on agents, "rm -f #{out}"
+
+step "run the manifest"
+apply_manifest_on agents, manifest
+
+step "verify the file output"
+on(agents, "cat #{out}") do
+ fail_test "host not found in output" unless stdout.include? name
+end
View
5 acceptance/tests/doc/should_print_function_reference.rb
@@ -0,0 +1,5 @@
+test_name "verify we can print the function reference"
+on(agents, puppet_doc("-r", "function")) do
+ fail_test "didn't print function reference" unless
+ stdout.include? 'Function Reference'
+end
View
5 acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb
@@ -0,0 +1,5 @@
+test_name "verify we can print the function reference"
+on(agents, puppet_doc("-r", "type")) do
+ fail_test "didn't print type reference" unless
+ stdout.include? 'Type Reference'
+end
View
22 acceptance/tests/file_hello_world.rb
@@ -0,0 +1,22 @@
+# Verify that a trivial manifest can be run to completion.
+
+filename = "/tmp/hello-world.txt"
+content = "Hello, World"
+manifest = "file { '#{filename}': content => '#{content}' }"
+
+test_name "The challenging 'Hello, World' manifest"
+
+step "ensure we are clean before testing..."
+on agents, "rm -f #{filename}"
+
+step "run the manifest itself"
+apply_manifest_on(agents, manifest) do
+ fail_test "the expected notice of action was missing" unless
+ stdout.index 'File[/tmp/hello-world.txt]/ensure: defined content as'
+end
+
+step "verify the content of the generated files."
+on agents, "grep '#{content}' #{filename}"
+
+step "clean up after our test run."
+on agents, "rm -f #{filename}"
View
19 acceptance/tests/jeff_append_to_array.rb
@@ -0,0 +1,19 @@
+# Ported from the acceptance test suite.
+test_name "Jeff: Append to Array"
+
+manifest = %q{
+ class parent {
+ $arr1 = [ "parent array element" ]
+ }
+ class parent::child inherits parent {
+ $arr1 += [ "child array element" ]
+ notify { $arr1: }
+ }
+ include parent::child
+}
+
+apply_manifest_on(agents, manifest) do
+ stdout =~ /notice: parent array element/ or fail_test("parent missing")
+ stdout =~ /notice: child array element/ or fail_test("child missing")
+end
+
View
65 acceptance/tests/key_compare_puppet_conf_configprint.rb
@@ -0,0 +1,65 @@
+# Check for the existance of keys found in puppet.conf in
+# --configprint all output
+#
+# Checking against key=>val pairs will cause erroneous errors:
+#
+# classfile
+# Puppet.conf --configprint
+# $vardir/classes.txt /var/opt/lib/pe-puppet/classes.txt
+
+test_name "Validate keys found in puppet.conf vs.--configprint all"
+
+puppet_conf_h = Hash.new
+config_print_h = Hash.new
+
+# Run tests against Master first
+step "Master: get puppet.conf file contents"
+on master, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do
+ stdout.split("\n").select{ |v| v =~ /=/ }.each do |line|
+ k,v = line.split("=")
+ puppet_conf_h[k]=v
+ end
+end
+
+step "Master: get --configprint all output"
+on master, puppet_master("--configprint all | tr -d \" \"") do
+ stdout.split("\n").select{ |v| v =~ /=/ }.each do |line|
+ k,v = line.split("=")
+ config_print_h[k]=v
+ end
+end
+
+step "Master: compare puppet.conf to --configprint output"
+puppet_conf_h.each do |k,v|
+ puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}"
+ fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k)
+ # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] )
+end
+
+# Run test on Agents
+agents.each { |agent|
+ puppet_conf_h.clear
+ config_print_h.clear
+ step "Agent #{agent}: get puppet.conf file contents"
+ on agent, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do
+ stdout.split("\n").select{ |v| v =~ /=/ }.each do |line|
+ k,v = line.split("=")
+ puppet_conf_h[k]=v
+ end
+ end
+
+ step "Agent #{agent}: get --configprint all output"
+ on agent, puppet_agent("--configprint all | tr -d \" \"") do
+ stdout.split("\n").select{ |v| v =~ /=/ }.each do |line|
+ k,v = line.split("=")
+ config_print_h[k]=v
+ end
+ end
+
+ step "Agent #{agent}: compare puppet.conf to --configprint output"
+ puppet_conf_h.each do |k,v|
+ puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}"
+ fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k)
+ # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] )
+ end
+}
View
16 acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb
@@ -0,0 +1,16 @@
+test_name "puppet apply should create a file and report an MD5"
+
+file = "/tmp/hello.world.#{Time.new.to_i}.txt"
+manifest = "file{'#{file}': content => 'test'}"
+
+step "clean up #{file} for testing"
+on agents, "rm -f #{file}"
+
+step "run the manifest and verify MD5 was printed"
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't find the content MD5 on output" unless
+ stdout.include? "defined content as '{md5}098f6bcd4621d373cade4e832627b4f6'"
+end
+
+step "clean up #{file} after testing"
+on agents, "rm -f #{file}"
View
15 acceptance/tests/puppet_apply_basics.rb
@@ -0,0 +1,15 @@
+# Ported from a collection of small spec tests in acceptance.
+#
+# Unified into a single file because they are literally one-line tests!
+
+test_name "Trivial puppet tests"
+
+step "check that puppet apply displays notices"
+apply_manifest_on(agents, "notice 'Hello World'") do
+ stdout =~ /notice:.*Hello World/ or fail_test("missing notice!")
+end
+
+step "verify help displays something for puppet master"
+on master, puppet_master("--help") do
+ stdout =~ /puppet master/ or fail_test("improper help output")
+end
View
5 acceptance/tests/puppet_apply_should_show_a_notice.rb
@@ -0,0 +1,5 @@
+test_name "puppet apply should show a notice"
+apply_manifest_on(agents, "notice 'Hello World'") do
+ fail_test "the notice didn't show" unless
+ stdout =~ /notice: .*: Hello World/
+end
View
4 acceptance/tests/puppet_master_help_should_mention_puppet_master.rb
@@ -0,0 +1,4 @@
+test_name "puppet master help should mention puppet master"
+on master, puppet_master('--help') do
+ fail_test "puppet master wasn't mentioned" unless stdout.include? 'puppet master'
+end
View
31 acceptance/tests/resource/cron/should_create_cron.rb
@@ -0,0 +1,31 @@
+test_name "should create cron"
+
+tmpuser = "cron-test-#{Time.new.to_i}"
+tmpfile = "/tmp/cron-test-#{Time.new.to_i}"
+
+create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
+delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ apply_manifest_on host, create_user
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}",
+ "command=/bin/true", "ensure=present")) do
+ fail_test "didn't notice creation of the cron stuff" unless
+ stdout.include? 'created'
+ end
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ fail_test "didn't find the command as expected" unless
+ stdout.include? "* * * * * /bin/true"
+ end
+
+ step "remove the crontab file for that user"
+ on host, "crontab -r -u #{tmpuser}"
+
+ step "remove the user from the system"
+ apply_manifest_on host, delete_user
+end
View
40 acceptance/tests/resource/cron/should_match_existing.rb
@@ -0,0 +1,40 @@
+
+
+tmpuser = "cron-test-#{Time.new.to_i}"
+tmpfile = "/tmp/cron-test-#{Time.new.to_i}"
+
+create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
+delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ apply_manifest_on host, create_user
+
+ step "create the existing job by hand..."
+ on host, "echo '* * * * * /bin/true' | crontab -u #{tmpuser} -"
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}",
+ "command=/bin/true", "ensure=present")) do
+ # REVISIT: This is ported from the original test, which seems to me a
+ # weak test, but I don't want to improve it now. --daniel 2010-12-23
+ #
+ # This is a weak/fragile test. The output has changed
+ # causing this test to fail erronously. Changed to the correct
+ # output to match, but this code should be re-feactored.
+ fail_test "didn't see the output we expected..." unless
+ stdout.include? 'present'
+ end
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ fail_test "didn't find the command as expected" unless
+ stdout.include? "* * * * * /bin/true"
+ end
+
+ step "remove the crontab file for that user"
+ on host, "crontab -r -u #{tmpuser}"
+
+ step "remove the user from the system"
+ apply_manifest_on host, delete_user
+end
View
36 acceptance/tests/resource/cron/should_remove_cron.rb
@@ -0,0 +1,36 @@
+test_name "puppet should remove a crontab entry as expected"
+
+tmpuser = "cron-test-#{Time.new.to_i}"
+tmpfile = "/tmp/cron-test-#{Time.new.to_i}"
+
+create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
+delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ apply_manifest_on host, create_user
+
+ step "create the existing job by hand..."
+ on host, "printf '# Puppet Name: crontest\n* * * * * /bin/true\n' | crontab -u #{tmpuser} -"
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}",
+ "command=/bin/true", "ensure=absent")) do
+ # REVISIT: This is ported from the original test, which seems to me a
+ # weak test, but I don't want to improve it now. --daniel 2010-12-23
+ fail_test "didn't see the output we expected..." unless
+ stdout.include? 'removed'
+ end
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ fail_test "didn't found the command we tried to remove" if
+ stdout.include? "/bin/true"
+ end
+
+ step "remove the crontab file for that user"
+ on host, "crontab -r -u #{tmpuser}"
+
+ step "remove the user from the system"
+ apply_manifest_on host, delete_user
+end
View
36 acceptance/tests/resource/cron/should_remove_matching.rb
@@ -0,0 +1,36 @@
+test_name "puppet should remove a crontab entry based on command matching"
+
+tmpuser = "cron-test-#{Time.new.to_i}"
+tmpfile = "/tmp/cron-test-#{Time.new.to_i}"
+
+cron = '# Puppet Name: crontest\n* * * * * /bin/true\n1 1 1 1 1 /bin/true\n'
+
+create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
+delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ apply_manifest_on host, create_user
+
+ step "create the existing job by hand..."
+ on host, "printf '#{cron}' | crontab -u #{tmpuser} -"
+
+ step "apply the resource change on the host"
+ on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}",
+ "command=/bin/true", "ensure=absent")) do
+ fail_test "didn't see the output we expected..." unless
+ stdout.include? 'removed'
+ end
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ count = stdout.scan("/bin/true").length
+ fail_test "found /bin/true the wrong number of times (#{count})" unless count == 1
+ end
+
+ step "remove the crontab file for that user"
+ on host, "crontab -r -u #{tmpuser}"
+
+ step "remove the user from the system"
+ apply_manifest_on host, delete_user
+end
View
42 acceptance/tests/resource/cron/should_update_existing.rb
@@ -0,0 +1,42 @@
+test_name "puppet should update existing crontab entry"
+
+tmpuser = "cron-test-#{Time.new.to_i}"
+tmpfile = "/tmp/cron-test-#{Time.new.to_i}"
+
+cron = '# Puppet Name: crontest\n* * * * * /bin/true\n'
+
+create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
+delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ apply_manifest_on host, create_user
+
+ step "create the existing job by hand..."
+ on host, "printf '#{cron}' | crontab -u #{tmpuser} -"
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ fail_test "didn't find the content in the crontab" unless
+ stdout.include? '* * * * * /bin/true'
+ end
+
+ step "apply the resource change on the host"
+ on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}",
+ "command=/bin/true", "ensure=present", "hour='0-6'")) do
+ fail_test "didn't update the time as expected" unless
+ stdout.include? "defined 'hour' as '0-6'"
+ end
+
+ step "verify that crontab -l contains what you expected"
+ on host, "crontab -l -u #{tmpuser}" do
+ fail_test "didn't find the content in the crontab" unless
+ stdout.include? '* 0-6 * * * /bin/true'
+ end
+
+ step "remove the crontab file for that user"
+ on host, "crontab -r -u #{tmpuser}"
+
+ step "remove the user from the system"
+ apply_manifest_on host, delete_user
+end
View
34 acceptance/tests/resource/exec/should_not_run_command_creates.rb
@@ -0,0 +1,34 @@
+test_name "should not run command creates"
+
+touch = "/tmp/touched-#{Time.new.to_i}"
+donottouch = "/tmp/not-touched-#{Time.new.to_i}"
+
+manifest = %Q{
+ exec { "test#{Time.new.to_i}": command => '/bin/touch #{donottouch}', creates => "#{touch}"}
+}
+
+step "prepare the agents for the test"
+on agents, "touch #{touch} ; rm -f #{donottouch}"
+
+step "test using puppet apply"
+apply_manifest_on(agents, manifest) do
+ fail_test "looks like the thing executed, which it shouldn't" if
+ stdout.include? 'executed successfully'
+end
+
+step "verify the file didn't get created"
+on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1]
+
+step "prepare the agents for the second part of the test"
+on agents, "touch #{touch} ; rm -f #{donottouch}"
+
+step "test using puppet resource"
+on(agents, puppet_resource('exec', "test#{Time.new.to_i}",
+ "command='/bin/touch #{donottouch}'",
+ "creates='#{touch}'")) do
+ fail_test "looks like the thing executed, which it shouldn't" if
+ stdout.include? 'executed successfully'
+end
+
+step "verify the file didn't get created the second time"
+on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1]
View
31 acceptance/tests/resource/exec/should_run_command.rb
@@ -0,0 +1,31 @@
+test_name "tests that puppet correctly runs an exec."
+# original author: Dan Bode --daniel 2010-12-23
+
+$touch = "/tmp/test-exec-#{Time.new.to_i}"
+
+def before
+ step "file to be touched should not exist."
+ on agents, "rm -f #{$touch}"
+end
+
+def after
+ step "checking the output worked"
+ on agents, "test -f #{$touch}"
+
+ step "clean up the system"
+ on agents, "rm -f #{$touch}"
+end
+
+before
+apply_manifest_on(agents, "exec {'test': command=>'/bin/touch #{$touch}'}") do
+ fail_test "didn't seem to run the command" unless
+ stdout.include? 'executed successfully'
+end
+after
+
+before
+on(agents, puppet_resource('-d', 'exec', 'test', "command='/bin/touch #{$touch}'")) do
+ fail_test "didn't seem to run the command" unless
+ stdout.include? 'executed successfully'
+end
+after
View
16 acceptance/tests/resource/exec/should_set_path.rb
@@ -0,0 +1,16 @@
+test_name "the path statement should work to locate commands"
+
+file = "/tmp/touched-should-set-path-#{Time.new.to_i}"
+
+step "clean up the system for the test"
+on agents, "rm -f #{file}"
+
+step "invoke the exec resource with a path set"
+on(agents, puppet_resource('exec', 'test',
+ "command='touch #{file}'", 'path="/bin:/usr/bin"'))
+
+step "verify that the files were created"
+on agents, "test -f #{file}"
+
+step "clean up the system after testing"
+on agents, "rm -f #{file}"
View
37 acceptance/tests/resource/file/content_attribute.rb
@@ -0,0 +1,37 @@
+test_name "The content attribute"
+pass_test "Pass forced pending test failure investigation"
+
+step "Ensure the test environment is clean"
+on agents, 'rm -f /tmp/content_file_test.txt'
+
+step "When using raw content"
+
+manifest = "file { '/tmp/content_file_test.txt': content => 'This is the test file content', ensure => present }"
+apply_manifest_on agents, manifest
+
+on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the test file content"'
+
+step "Ensure the test environment is clean"
+on agents, 'rm -f /tmp/content_file_test.txt'
+
+step "When using a filebucket checksum from filebucket"
+
+on agents, "echo 'This is the checksum file contents' > /tmp/checksum_test_file.txt"
+on agents, "puppet filebucket backup --local /tmp/checksum_test_file.txt"
+
+get_remote_option(agents, 'filebucket', 'bucketdir') do |bucketdir|
+ manifest = %Q|
+ filebucket { 'local':
+ path => '#{bucketdir}',
+ }
+
+ file { '/tmp/content_file_test.txt':
+ content => '{md5}18571d3a04b2bb7ccfdbb2c44c72caa9',
+ ensure => present,
+ backup => local,
+ }
+ |
+ apply_manifest_on agents, manifest
+end
+
+on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the checksum file contents"'
View
15 acceptance/tests/resource/file/should_create_directory.rb
@@ -0,0 +1,15 @@
+test_name "should create directory"
+
+target = "/tmp/test-#{Time.new.to_i}"
+
+step "clean up the system before we begin"
+on agents, "rm -vrf #{target}"
+
+step "verify we can create a directory"
+on(agents, puppet_resource("file", target, 'ensure=directory'))
+
+step "verify the directory was created"
+on agents, "test -d #{target}"
+
+step "clean up after the test run"
+on agents, "rm -vrf #{target}"
View
15 acceptance/tests/resource/file/should_create_empty.rb
@@ -0,0 +1,15 @@
+test_name "should create empty file for 'present'"
+
+target = "/tmp/test-#{Time.new.to_i}"
+
+step "clean up the system before we begin"
+on agents, "rm -vrf #{target}"
+
+step "verify we can create an empty file"
+on(agents, puppet_resource("file", target, 'ensure=present'))
+
+step "verify the target was created"
+on agents, "test -f #{target} && ! test -s #{target}"
+
+step "clean up after the test run"
+on agents, "rm -vrf #{target}"
View
27 acceptance/tests/resource/file/should_create_symlink.rb
@@ -0,0 +1,27 @@
+test_name "should create symlink"
+
+message = 'hello world'
+target = "/tmp/test-#{Time.new.to_i}"
+source = "/tmp/test-#{Time.new.to_i}-source"
+
+step "clean up the system before we begin"
+on agents, "rm -vrf #{target}"
+on agents, "echo '#{message}' > #{source}"
+
+step "verify we can create a symlink"
+on(agents, puppet_resource("file", target, "ensure=#{source}"))
+
+step "verify the symlink was created"
+on agents, "test -L #{target} && test -f #{target}"
+on agents, "test -f #{source}"
+
+step "verify the content is identical on both sides"
+on(agents, "cat #{source}") do
+ fail_test "source missing content" unless stdout.include? message
+end
+on(agents, "cat #{target}") do
+ fail_test "target missing content" unless stdout.include? message
+end
+
+step "clean up after the test run"
+on agents, "rm -vrf #{target} #{source}"
View
21 acceptance/tests/resource/file/should_remove_dir.rb
@@ -0,0 +1,21 @@
+test_name "should remove directory, but force required"
+
+target = "/tmp/test-#{Time.new.to_i}"
+
+step "clean up the system before we begin"
+on agents, "test -e #{target} && rm -vrf #{target} ; mkdir -p #{target}"
+
+step "verify we can't remove a directory without 'force'"
+on(agents, puppet_resource("file", target, 'ensure=absent')) do
+ fail_test "didn't tell us that force was required" unless
+ stdout.include? "Not removing directory; use 'force' to override"
+end
+
+step "verify the directory still exists"
+on agents, "test -d #{target}"
+
+step "verify we can remove a directory with 'force'"
+on(agents, puppet_resource("file", target, 'ensure=absent', 'force=true'))
+
+step "verify that the directory is gone"
+on agents, "test -d #{target}", :acceptable_exit_codes => [1]
View
12 acceptance/tests/resource/file/should_remove_file.rb
@@ -0,0 +1,12 @@
+test_name "should remove file"
+
+target = "/tmp/test-#{Time.new.to_i}"
+
+step "clean up the system before we begin"
+on agents, "rm -vrf #{target} && touch #{target}"
+
+step "verify we can remove a file"
+on(agents, puppet_resource("file", target, 'ensure=absent'))
+
+step "verify that the file is gone"
+on agents, "test -e #{target}", :acceptable_exit_codes => [1]
View
100 acceptance/tests/resource/file/source_attribtute.rb
@@ -0,0 +1,100 @@
+test_name "The source attribute"
+
+step "Ensure the test environment is clean"
+on agents, 'rm -f /tmp/source_file_test.txt'
+
+# TODO: Add tests for puppet:// URIs with master/agent setups.
+step "when using a puppet:/// URI with a master/agent setup"
+step "when using a puppet://$server/ URI with a master/agent setup"
+
+step "when using a local file path"
+
+on agents, "echo 'Yay, this is the local file.' > /tmp/local_source_file_test.txt"
+
+manifest = "file { '/tmp/source_file_test.txt': source => '/tmp/local_source_file_test.txt', ensure => present }"
+
+apply_manifest_on agents, manifest
+
+on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the local file."'
+
+step "Ensure the test environment is clean"
+on agents, 'rm -f /tmp/source_file_test.txt'
+
+step "when using a puppet:/// URI with puppet apply"
+
+on agents, 'puppet agent --configprint modulepath' do
+ modulepath = stdout.split(':')[0]
+ modulepath = modulepath.chomp
+ on agents, "mkdir -p #{modulepath}/test_module/files"
+ on agents, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt"
+end
+
+on agents, %q{echo "file { '/tmp/source_file_test.txt': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }" > /tmp/source_test_manifest.pp}
+on agents, "puppet apply /tmp/source_test_manifest.pp"
+
+on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the puppet:/// file."'
+
+# Oops. We (Jesse & Jacob) ended up writing this before realizing that you
+# can't actually specify "source => 'http://...'". However, we're leaving it
+# here, since there have been feature requests to support doing this.
+# -- Mon, 07 Mar 2011 16:12:56 -0800
+#
+#step "Ensure the test environment is clean"
+#on agents, 'rm -f /tmp/source_file_test.txt'
+#
+#step "when using an http:// file path"
+#
+#File.open '/tmp/puppet-acceptance-webrick-script.rb', 'w' do |file|
+# file.puts %q{#!/usr/bin/env ruby
+#
+#require 'webrick'
+#
+#class Simple < WEBrick::HTTPServlet::AbstractServlet
+# def do_GET(request, response)
+# status, content_type, body = do_stuff_with(request)
+#
+# response.status = status
+# response['Content-Type'] = content_type
+# response.body = body
+# end
+#
+# def do_stuff_with(request)
+# return 200, "text/plain", "you got a page"
+# end
+#end
+#
+#class SimpleTwo < WEBrick::HTTPServlet::AbstractServlet
+# def do_GET(request, response)
+# status, content_type, body = do_stuff_with(request)
+#
+# response.status = status
+# response['Content-Type'] = content_type
+# response.body = body
+# end
+#
+# def do_stuff_with(request)
+# return 200, "text/plain", "you got a different page"
+# end
+#end
+#
+#server = WEBrick::HTTPServer.new :Port => 8081
+#trap "INT" do server.shutdown end
+#trap "TERM" do server.shutdown end
+#trap "QUIT" do server.shutdown end
+#
+#server.mount "/", SimpleTwo
+#server.mount "/foo.txt", Simple
+#server.start
+#}
+#end
+#
+#scp_to master, '/tmp/puppet-acceptance-webrick-script.rb', '/tmp'
+#on master, "chmod +x /tmp/puppet-acceptance-webrick-script.rb && /tmp/puppet-acceptance-webrick-script.rb &"
+#
+#manifest = "file { '/tmp/source_file_test.txt': source => 'http://#{master}:8081/foo.txt', ensure => present }"
+#
+#apply_manifest_on agents, manifest
+#
+#on agents, 'test "$(cat /tmp/source_file_test.txt)" = "you got a page"'
+#
+#on master, "killall puppet-acceptance-webrick-script.rb"
View
20 acceptance/tests/resource/group/should_create.rb
@@ -0,0 +1,20 @@
+test_name "should create group"
+
+name = "test-group-#{Time.new.to_i}"
+
+def cleanup(name)
+ step "remove group #{name} if it exists"
+ on agents, "if getent group #{name}; then groupdel #{name}; fi"
+end
+
+cleanup(name)
+
+step "create the group #{name} with the resource agent"
+on(agents, puppet_resource('group', name, 'ensure=present'))
+
+step "verify the group #{name} was created"
+on(agents, "getent group #{name}") do
+ fail_test "group information is not sensible" unless stdout =~ /^#{name}:x:[0-9]+:/
+end
+
+cleanup(name)
View
14 acceptance/tests/resource/group/should_destroy.rb
@@ -0,0 +1,14 @@
+test_name "should destroy a group"
+
+name = "test-group-#{Time.new.to_i}"
+
+step "ensure the group exists on the target system"
+on agents, "getent group #{name} || groupadd #{name}"
+
+step "use puppet to remove the group"
+on(agents, puppet_resource('group', name, 'ensure=absent'))
+
+step "verify that the group has been removed"
+# REVISIT: I /think/ that exit code 2 is standard across Linux, but I have no
+# idea what non-Linux platforms are going to return. --daniel 2010-12-24
+on agents, "getent group #{name}", :acceptable_exit_codes => [2]
View
23 acceptance/tests/resource/group/should_modify_gid.rb
@@ -0,0 +1,23 @@
+test_name "should modify gid of existing group"
+
+name = "test-group-#{Time.new.to_i}"
+gid = 12345
+
+step "ensure that the group exists with gid #{gid}"
+on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid}")) do
+ fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid}'/
+end
+
+step "ensure that we can modify the GID of the group to #{gid*2}"
+on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid*2}")) do
+ fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid*2}'/
+end
+
+step "verify that the GID changed"
+on(agents, "getent group #{name}") do
+ fail_test "gid is wrong through getent output" unless
+ stdout =~ /^#{name}:x:#{gid*2}:/
+end
+
+step "clean up the system after the test run"
+on(agents, puppet_resource('group', name, 'ensure=absent'))
View
15 acceptance/tests/resource/group/should_not_create_existing.rb
@@ -0,0 +1,15 @@
+test_name "group should not create existing group"
+
+name = "test-group-#{Time.new.to_i}"
+
+step "ensure the group exists on the target node"
+on(agents, puppet_resource('group', name, 'ensure=present'))
+
+step "verify that we don't try and create the existing group"
+on(agents, puppet_resource('group', name, 'ensure=present')) do
+ fail_test "looks like we created the group" if
+ stdout.include? '/Group[bozo]/ensure: created'
+end
+
+step "clean up the system after the test run"
+on(agents, puppet_resource('group', name, 'ensure=absent'))
View
13 acceptance/tests/resource/group/should_not_destoy_unexisting.rb
@@ -0,0 +1,13 @@
+test_name "should not destroy a group that doesn't exist"
+
+name = "test-group-#{Time.new.to_i}"
+
+step "verify the group does not already exist"
+on(agents, puppet_resource('group', name, 'ensure=absent'))
+
+step "verify that we don't remove the group when it doesn't exist"
+on(agents, puppet_resource('group', name, 'ensure=absent')) do
+ fail_test "it looks like we tried to remove the group" if
+ stdout.include? "notice: /Group[#{name}]/ensure: removed"
+end
+
View
15 acceptance/tests/resource/group/should_query.rb
@@ -0,0 +1,15 @@
+test_name "group should query"
+
+name = "test-group-#{Time.new.to_i}"
+
+step "ensure the group exists on the target systems"
+on agents, "getent group #{name} || groupadd #{name}"
+
+step "ensure that the resource agent sees the group"
+on(agents, puppet_resource('group', name)) do
+ fail_test "missing group identifier" unless stdout.include? "group { '#{name}':"
+ fail_test "missing present attributed" unless stdout.include? "ensure => 'present'"
+end
+
+step "clean up the system after the test"
+on(agents, puppet_resource('group', name, 'ensure=absent'))
View
30 acceptance/tests/resource/group/should_query_all.rb
@@ -0,0 +1,30 @@
+test_name "puppet resource should query all groups"
+
+agents.each do |host|
+ groups = {}
+
+ step "collect the list of groups on #{host} with getent group"
+ on(host, "getent group") do
+ stdout.each_line do |line| groups[line[/^[^:]+/]] = 'getent' end
+ end
+
+ step "collect the list of groups on #{host} with puppet resource"
+ on(host, puppet_resource('group')) do
+ stdout.each_line do |line|
+ match = line.match(/^group \{ '([^']+)'/)
+ if match then
+ name = match[1]
+
+ if groups.include? name then
+ groups.delete name
+ else
+ fail_test "group #{name} found by puppet, not getent"
+ end
+ end
+ end
+ end
+
+ groups.keys.each do |name|
+ fail_test "group #{name} found by getent, not puppet"
+ end
+end
View
15 acceptance/tests/resource/host/should_create.rb
@@ -0,0 +1,15 @@
+test_name "host should create"
+
+target = "/tmp/host-#{Time.new.to_i}"
+
+step "clean up for the test"
+on agents, "rm -vf #{target}"
+
+step "create the host record"
+on(agents, puppet_resource("host", "test", "ensure=present",
+ "ip=127.0.0.1", "target=#{target}"))
+
+step "verify that the record was created"
+on(agents, "cat #{target} ; rm -f #{target}") do
+ fail_test "record was not present" unless stdout =~ /^127\.0\.0\.1[[:space:]]+test/
+end
View
16 acceptance/tests/resource/host/should_create_aliases.rb
@@ -0,0 +1,16 @@
+test_name "host should create aliases"
+
+target = "/tmp/host-#{Time.new.to_i}"
+
+step "clean up the system for testing"
+on agents, "rm -vf #{target}"
+
+step "create the record"
+on(agents, puppet_resource('host', 'test', "ensure=present",
+ "ip=127.0.0.7", "target=#{target}", "host_aliases=alias"))
+
+step "verify that the aliases were added"
+on(agents, "cat #{target} ; rm -f #{target}") do
+ fail_test "alias was missing" unless
+ stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/
+end
View
19 acceptance/tests/resource/host/should_destroy.rb
@@ -0,0 +1,19 @@
+test_name "should be able to remove a host record"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+line = "127.0.0.7 test1"
+
+step "set up files for the test"
+on agents, "printf '#{line}\n' > #{file}"
+
+step "delete the resource from the file"
+on(agents, puppet_resource('host', 'test1', "target=#{file}",
+ 'ensure=absent', 'ip=127.0.0.7'))
+
+step "verify that the content was removed"
+on(agents, "cat #{file}; rm -f #{file}") do
+ fail_test "the content was still present" if stdout.include? line
+end
+
+step "clean up after the test"
+on agents, "rm -vf #{file}"
View
19 acceptance/tests/resource/host/should_modify_alias.rb
@@ -0,0 +1,19 @@
+test_name "should be able to modify a host alias"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+
+step "set up files for the test"
+on agents, "printf '127.0.0.8 test alias\n' > #{file}"
+
+step "modify the resource"
+on(agents, puppet_resource('host', 'test', "target=#{file}",
+ 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai'))
+
+step "verify that the content was updated"
+on(agents, "cat #{file}; rm -f #{file}") do
+ fail_test "the alias was not updated" unless
+ stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/
+end
+
+step "clean up after the test"
+on agents, "rm -vf #{file}"
View
19 acceptance/tests/resource/host/should_modify_ip.rb
@@ -0,0 +1,19 @@
+test_name "should be able to modify a host address"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+
+step "set up files for the test"
+on agents, "printf '127.0.0.9 test alias\n' > #{file}"
+
+step "modify the resource"
+on(agents, puppet_resource('host', 'test', "target=#{file}",
+ 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias'))
+
+step "verify that the content was updated"
+on(agents, "cat #{file}; rm -f #{file}") do
+ fail_test "the address was not updated" unless
+ stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/
+end
+
+step "clean up after the test"
+on agents, "rm -vf #{file}"
View
17 acceptance/tests/resource/host/should_not_create_existing.rb
@@ -0,0 +1,17 @@
+test_name "should not create host if it exists"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+
+step "set up the system for the test"
+on agents, "printf '127.0.0.2 test alias\n' > #{file}"
+
+step "tell puppet to ensure the host exists"
+on(agents, puppet_resource('host', 'test', "target=#{file}",
+ 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do
+ fail_test "darn, we created the host record" if
+ stdout.include? 'notice: /Host[test1]/ensure: created'
+end
+
+step "clean up after we created things"
+on agents, "rm -vf #{file}"
+
View
15 acceptance/tests/resource/host/should_query.rb
@@ -0,0 +1,15 @@
+test_name "should query hosts out of a hosts file"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+
+step "set up the system for the test"
+on agents, "printf '127.0.0.1 localhost.local localhost\n' > #{file}"
+
+step "fetch the list of hosts from puppet"
+on(agents, puppet_resource('host', 'localhost', "target=#{file}")) do
+ found = stdout.scan('present').length
+ fail_test "found #{found} hosts, not 1" if found != 1
+end
+
+step "clean up the system"
+on agents, "rm -vf #{file}"
View
26 acceptance/tests/resource/host/should_query_all.rb
@@ -0,0 +1,26 @@
+test_name "should query all hosts from hosts file"
+
+content = %q{127.0.0.1 test1 test1.local
+127.0.0.2 test2 test2.local
+127.0.0.3 test3 test3.local
+127.0.0.4 test4 test4.local
+}
+
+backup = "/tmp/hosts.backup-#{Time.new.to_i}"
+
+step "configure the system for testing (including file backups)"
+on agents, "cp /etc/hosts #{backup}"
+on agents, "cat > /etc/hosts", :stdin => content
+
+step "query all host records using puppet"
+on(agents, puppet_resource('host')) do
+ found = stdout.scan(/host \{ '([^']+)'/).flatten.sort
+ fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless
+ found == %w{test1 test2 test3 test4}
+
+ count = stdout.scan(/ensure\s+=>\s+'present'/).length
+ fail_test "found #{count} records, wanted 4" unless count == 4
+end
+
+step "clean up the system afterwards"
+on agents, "mv -vf #{backup} /etc/hosts"
View
21 acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb
@@ -0,0 +1,21 @@
+test_name "#4131: should not create host without IP attribute"
+
+file = "/tmp/hosts-#{Time.new.to_i}"
+
+step "configure the target system for the test"
+on agents, "rm -vrf #{file} ; touch #{file}"
+
+step "try to create the host, which should fail"
+# REVISIT: This step should properly need to handle the non-zero exit code,
+# and #5668 has been filed to record that. When it is fixed this test will
+# start to fail, and this comment will tell you why. --daniel 2010-12-24
+on(agents, puppet_resource('host', 'test', "target=#{file}",
+ "host_aliases=alias")) do
+ fail_test "puppet didn't complain about the missing attribute" unless
+ stdout.include? 'ip is a required attribute for hosts'
+end
+
+step "verify that the host was not added to the file"
+on(agents, "cat #{file} ; rm -f #{file}") do
+ fail_test "the host was apparently added to the file" if stdout.include? 'test'
+end
View
12 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb
@@ -0,0 +1,12 @@
+test_name "#4123: should list all running services on Redhat/CentOS"
+step "Validate services running agreement ralsh vs. OS service count"
+# This will remotely exec:
+# ticket_4123_should_list_all_running_redhat.sh
+
+hosts.each do |host|
+ unless host['platform'].include? 'centos' or host['platform'].include? 'redhat'
+ skip_test "Test not supported on this plaform"
+ else
+ run_script_on(host,'tests/acceptance/resource/service/ticket_4123_should_list_all_running_redhat.sh')
+ end
+end
View
36 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# A platform must be specified the only command line arg
+# This will facilitate expansion of this tests to include
+# the ability to test other OSes
+
+#if [ -z $1 ] ; then
+# echo "No platform specified"
+# exit 1
+#fi
+
+# redhat or centos only
+#if echo $1 | grep -e centos -e redhat
+ RALSH_FILE=/tmp/ralsh-running-list-$$
+ SERVICE_FILE=/tmp/service-running-list-$$
+
+ puppet resource service | egrep -B1 "ensure\s*=>\s*'running" | grep 'service {' | gawk -F"\'" '{print $2}' | sort > $RALSH_FILE
+
+ if [ -e $SERVICE_FILE ]; then
+ rm $SERVICE_FILE
+ fi
+ SERVICEDIR='/etc/init.d'
+ for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do
+ if env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" status; then
+ echo $SERVICE >> $SERVICE_FILE
+ fi
+ done
+
+ if diff $RALSH_FILE $SERVICE_FILE ; then
+ echo "Ralsh and system service count agree"
+ exit 0
+ else
+ echo "Ralsh and system service count NOT in agreement"
+ exit 1
+ fi
+#fi # end redhat/centos
View
12 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb
@@ -0,0 +1,12 @@
+test_name "#4124: should list all disabled services on Redhat/CentOS"
+step "Validate disabled services agreement ralsh vs. OS service count"
+# This will remotely exec:
+# ticket_4124_should_list_all_disabled.sh
+
+hosts.each do |host|
+ unless host['platform'].include? 'centos' or host['platform'].include? 'redhat'
+ skip_test "Test not supported on this plaform"
+ else
+ run_script_on(host,'tests/acceptance/resource/service/ticket_4124_should_list_all_disabled.sh')
+ end
+end
View
37 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# A platform must be specified the only command line arg
+# This will facilitate expansion of this tests to include
+# the ability to test other OSes
+
+#if [ -z $1 ] ; then
+# echo "No platform specified"
+# exit 1
+#fi
+
+# redhat or centos only
+#if echo $1 | grep -e centos -e redhat
+ RALSH_FILE=/tmp/ralsh-disabled-list-$$
+ SERVICE_FILE=/tmp/service-disabled-list-$$
+
+ # collect all service namevars
+ puppet resource service | egrep -B2 "enable\s*=>\s*'false" | grep "service {" | awk -F"'" '{print $2}' | sort > $RALSH_FILE
+
+ if [ -e $SERVICE_FILE ]; then
+ rm $SERVICE_FILE
+ fi
+ SERVICEDIR='/etc/init.d'
+ for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do
+ if ! chkconfig $SERVICE; then
+ echo $SERVICE >> $SERVICE_FILE
+ fi
+ done
+
+ if diff $RALSH_FILE $SERVICE_FILE ; then
+ echo "Ralsh and system service count agree"
+ exit 0
+ else
+ echo "Ralsh and system service count NOT in agreement"
+ exit 1
+ fi
+#fi # end redhat/centos
View
20 acceptance/tests/resource/user/should_create.rb
@@ -0,0 +1,20 @@
+test_name "should create a user, and the default matching group"
+# REVISIT: This is a direct port of the original test, but it contains a
+# non-portable assumption that "user private groups" are used by default by
+# everything that we target. --daniel 2010-12-24
+
+name = "test-user-#{Time.new.to_i}"
+
+step "ensure that the user and group #{name} do not exist"
+on agents, "if getent passwd #{name}; then userdel #{name}; fi"
+on agents, "if getent group #{name}; then groupdel #{name}; fi"
+
+step "ask puppet to create the user"
+on(agents, puppet_resource('user', name, 'ensure=present'))
+
+step "verify that the user and group now exist"
+on agents, "getent passwd #{name} && getent group #{name}"
+
+step "ensure that the user and group #{name} do not exist"
+on agents, "if getent passwd #{name}; then userdel #{name}; fi"
+on agents, "if getent group #{name}; then groupdel #{name}; fi"
View
30 acceptance/tests/resource/user/should_create_with_gid.rb
@@ -0,0 +1,30 @@
+test_name "verifies that puppet resource creates a user and assigns the correct group"
+
+user = "test-user-#{Time.new.to_i}"
+group = "test-user-#{Time.new.to_i}-group"
+
+agents.each do |host|
+ step "user should not exist"
+ on host, "if getent passwd #{user}; then userdel #{user}; fi"
+
+ step "group should exist"
+ on host, "if ! getent group #{group}; then groupadd #{group}; fi"
+
+ step "create user with group"
+ on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group}"))
+
+ step "verify the group exists and find the gid"
+ on(host, "getent group #{group}") do
+ gid = stdout.split(':')[2]
+
+ step "verify that the user has that as their gid"
+ on(host, "getent passwd #{user}") do
+ got = stdout.split(':')[3]
+ fail_test "wanted gid #{gid} but found #{got}" unless gid == got
+ end
+ end
+
+ step "clean up after the test is done"
+ on(host, puppet_resource('user', user, 'ensure=absent'))
+ on(host, puppet_resource('group', group, 'ensure=absent'))
+end
View
19 acceptance/tests/resource/user/should_destroy.rb
@@ -0,0 +1,19 @@
+test_name "verify that puppet resource correctly destroys users"
+
+user = "test-user-#{Time.new.to_i}"
+group = user
+
+step "ensure that the user and associated group exist"
+on(agents, puppet_resource('group', group, 'ensure=present'))
+on(agents, puppet_resource('user', user, 'ensure=present', "gid=#{group}"))
+
+step "try and delete the user"
+on(agents, puppet_resource('user', user, 'ensure=absent'))
+
+step "verify that the user is no longer present"
+on(agents, "getent passwd #{user}", :acceptable_exit_codes => [2]) do
+ fail_test "found the user in the output" if stdout.include? "#{user}:"
+end
+
+step "remove the group as well..."
+on(agents, puppet_resource('group', group, 'ensure=absent'))
View
41 acceptance/tests/resource/user/should_modify_gid.rb
@@ -0,0 +1,41 @@
+test_name "verify that we can modify the gid"
+
+user = "test-user-#{Time.new.to_i}"
+group1 = "#{user}-old"
+group2 = "#{user}-new"
+
+agents.each do |host|
+ step "ensure that the groups both exist"
+ on(host, puppet_resource('group', group1, 'ensure=present'))
+ on(host, puppet_resource('group', group2, 'ensure=present'))
+
+ step "ensure the user exists and has the old group"
+ on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group1}"))
+
+ step "verify that the user has the correct gid"
+ on(host, "getent group #{group1}") do
+ gid = stdout.split(':')[2]
+ on(host, "getent passwd #{user}") do
+ got = stdout.split(':')[3]
+ fail_test "didn't have the expected old GID, but #{got}" unless got == gid
+ end
+ end
+
+ step "modify the GID of the user"
+ on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group2}"))
+
+
+ step "verify that the user has the updated gid"
+ on(host, "getent group #{group2}") do
+ gid = stdout.split(':')[2]
+ on(host, "getent passwd #{user}") do
+ got = stdout.split(':')[3]
+ fail_test "didn't have the expected old GID, but #{got}" unless got == gid
+ end
+ end
+
+ step "ensure that we remove the things we made"
+ on(host, puppet_resource('user', user, 'ensure=absent'))
+ on(host, puppet_resource('group', group1, 'ensure=absent'))
+ on(host, puppet_resource('group', group2, 'ensure=absent'))
+end
View
6 acceptance/tests/resource/user/should_not_create_existing.rb
@@ -0,0 +1,6 @@
+test_name "tests that user resource will not add users that already exist."
+
+step "verify that we don't try to create a user account that already exists"
+on(agents, puppet_resource('user', 'root', 'ensure=present')) do
+ fail_test "tried to create 'root' user" if stdout.include? 'created'
+end
View
11 acceptance/tests/resource/user/should_not_destoy_unexisting.rb
@@ -0,0 +1,11 @@
+test_name "ensure that puppet does not report removing a user that does not exist"
+
+name = "test-user-#{Time.new.to_i}"
+
+step "verify that user #{name} does not exist"
+on agents, "getent passwd #{name}", :acceptable_exit_codes => [2]
+
+step "ensure absent doesn't try and do anything"
+on(agents, puppet_resource('user', name, 'ensure=absent')) do
+ fail_test "tried to remove the user, apparently" if stdout.include? 'removed'
+end
View
15 acceptance/tests/resource/user/should_query.rb
@@ -0,0 +1,15 @@
+test_name "test that we can query and find a user that exists."
+
+name = "test-user-#{Time.new.to_i}"
+
+step "ensure that our test user exists"
+on(agents, puppet_resource('user', name, 'ensure=present'))
+
+step "query for the resource and verify it was found"
+on(agents, puppet_resource('user', name)) do
+ fail_test "didn't find the user #{name}" unless stdout.include? 'present'
+end
+
+step "clean up the user and group we added"
+on(agents, puppet_resource('user', name, 'ensure=absent'))
+on(agents, puppet_resource('group', name, 'ensure=absent'))
View
30 acceptance/tests/resource/user/should_query_all.rb
@@ -0,0 +1,30 @@
+test_name "ensure that puppet queries the correct number of users"
+
+agents.each do |host|
+ users = []
+
+ step "collect the list of known users via getent"
+ on(host, "getent passwd") do
+ stdout.each_line do |line|
+ users << line.split(':')[0]
+ end
+ end
+
+ step "collect the list of known users via puppet"
+ on(host, puppet_resource('user')) do
+ stdout.each_line do |line|
+ name = ( line.match(/^user \{ '([^']+)'/) or next )[1]
+
+ # OK: Was this name found in the list of users?
+ if users.member? name then
+ users.delete name
+ else
+ fail_test "user #{name} found by puppet, not by getent"
+ end
+ end
+ end
+
+ if users.length > 0 then
+ fail_test "#{users.length} users found with getent, not puppet: #{users.join(', ')}"
+ end
+end
View
7 acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb
@@ -0,0 +1,7 @@
+test_name "#3172: puppet kick with hostnames on the command line"
+step "verify that we trigger our host"
+
+target = 'working.example.org'
+on(agents, puppet_kick(target), :acceptable_exit_codes => [3]) {
+ fail_test "didn't trigger #{target}" unless stdout.include? "Triggering #{target}"
+}
View
8 acceptance/tests/ticket_3656_requiring_multiple_resources.rb
@@ -0,0 +1,8 @@
+test_name "#3656: requiring multiple resources"
+apply_manifest_on agents, %q{
+ notify { 'foo': }
+ notify { 'bar': }
+ notify { 'baz':
+ require => [Notify['foo'], Notify['bar']],
+ }
+}
View
20 acceptance/tests/ticket_4059_ralsh_can_change_settings.rb
@@ -0,0 +1,20 @@
+test_name "#4059: ralsh can change settings"
+
+target = "/tmp/hosts-#4059"
+content = "host example.com ensure=present ip=127.0.0.1 target=#{target}"
+
+step "cleanup the target file"
+on agents, "rm -f #{target}"
+
+step "run the resource agent"
+on(agents, puppet_resource(content)) do
+ stdout.index('Host[example.com]/ensure: created') or
+ fail_test("missing notice about host record creation")
+end
+on(agents, "cat #{target}") do
+ stdout =~ /^127\.0\.0\.1\s+example\.com/ or
+ fail_test("missing host record in #{target}")
+end
+
+step "cleanup at the end of the test"
+on agents, "rm -f #{target}"
View
5 acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb
@@ -0,0 +1,5 @@
+test_name "#4110: puppet apply should not create a user that already exists"
+
+apply_manifest_on(agents, "user { 'root': ensure => 'present' }") do
+ fail_test("we tried to create root on this host") if stdout =~ /created/
+end
View
13 acceptance/tests/ticket_4233_resource_with_a_newline.rb
@@ -0,0 +1,13 @@
+test_name "#4233: resource with a newline"
+
+# 2010-07-22 Jeff McCune <jeff@puppetlabs.com>
+# AffectedVersion: 2.6.0rc3
+# FixedVersion: 2.6.0
+
+# JJM We expect 2.6.0rc3 to return an error
+# and 2.6.0 final to not return an error line.
+# Look for the line in the output and fail the test
+# if we find it.
+apply_manifest_on(agents, 'exec { \'/bin/echo -e "\nHello World\n"\': }') do
+ stdout =~ /err:/ and fail_test("error report in output, sorry")
+end
View
17 acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb
@@ -0,0 +1,17 @@
+test_name "Bug #4285: ArgumentError: Cannot alias File[mytitle] to [nil]"
+
+manifest = %q{
+ file { "file1":
+ name => '/tmp/file1',
+ source => "/tmp/",
+ }
+
+ file { "file2":
+ name => '/tmp/file2',
+ source => "/tmp/",
+ }
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "found the bug report output" if stdout =~ /Cannot alias/
+end
View
13 ...ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb
@@ -0,0 +1,13 @@
+test_name "Bug #4287: undefined method 'evaluate_match' when function call used in an 'if' statement"
+
+manifest = %q{
+ $foo='abc'
+ if $foo != regsubst($foo,'abc','def') {
+ notify { 'No issue here...': }
+ }
+}
+
+apply_manifest_on(agents, manifest) do
+ fail_test "didn't get the expected notice" unless
+ stdout.include? 'notice: No issue here...'
+end
View
21 acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb
@@ -0,0 +1,21 @@
+# 2010-08-02 Nan Liu
+#
+# http://projects.puppetlabs.com/issues/4289
+#
+# NL: Facter should return OS version instead of kernel version for OEL
+# test script only applicable to OEL, provided based on ticked info, not verified.
+
+test_name "#4289: facter should recognize OEL operatingsystemrelease"
+
+# REVISIT: We don't actually have support for this yet - we need a "not
+# applicable" option, I guess, that can be based on detected stuff, which is
+# cleaner than this is... --daniel 2010-12-22
+agents.each do |host|
+ step "determine the operating system of #{host}"
+ on host, facter("operatingsystem")
+ if stdout =~ /oel/i then
+ step "test operatingsystemrelease fact on OEL host #{host}"
+ on host, facter("operatingsystemrelease")
+ stdout =~ /^\d\.\d$/ or fail_test "operatingsystemrelease not as expected"
+ end
+end
View
22 acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb
@@ -0,0 +1,22 @@
+# 2010-07-22 Jeff McCune <jeff@puppetlabs.com>
+#
+# AffectedVersion: 2.6.0rc4
+# FixedVersion: 2.6.0
+#
+# Description: using a defined type in the class it's declared in
+# causes an error.
+
+manifest = <<PP
+class foo {
+ define do_notify($msg) {
+ notify { "Message for $name: $msg": }
+ }
<