puppet 2.7.18 → 2.7.19

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (137) hide show
  1. data/CHANGELOG +82 -0
  2. data/CONTRIBUTING.md +114 -171
  3. data/README.md +8 -0
  4. data/README_DEVELOPER.md +38 -3
  5. data/Rakefile +19 -3
  6. data/conf/osx/createpackage.sh +3 -1
  7. data/conf/redhat/logrotate +1 -1
  8. data/conf/redhat/puppet.spec +35 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/application/agent.rb +2 -0
  11. data/lib/puppet/application/master.rb +2 -0
  12. data/lib/puppet/configurer.rb +2 -3
  13. data/lib/puppet/defaults.rb +6 -5
  14. data/lib/puppet/face/module/install.rb +2 -1
  15. data/lib/puppet/file_bucket/dipper.rb +1 -1
  16. data/lib/puppet/indirector/file_content.rb +2 -2
  17. data/lib/puppet/indirector/file_metadata.rb +2 -2
  18. data/lib/puppet/indirector/indirection.rb +3 -4
  19. data/lib/puppet/indirector/rest.rb +12 -6
  20. data/lib/puppet/interface/action_manager.rb +1 -2
  21. data/lib/puppet/module_tool/applications/unpacker.rb +22 -3
  22. data/lib/puppet/network/handler/fileserver.rb +2 -2
  23. data/lib/puppet/parser/ast/resource.rb +9 -2
  24. data/lib/puppet/parser/functions/fqdn_rand.rb +2 -1
  25. data/lib/puppet/parser/functions/md5.rb +2 -2
  26. data/lib/puppet/parser/functions/sha1.rb +2 -2
  27. data/lib/puppet/parser/functions/template.rb +0 -2
  28. data/lib/puppet/parser/type_loader.rb +1 -2
  29. data/lib/puppet/provider/augeas/augeas.rb +19 -1
  30. data/lib/puppet/provider/confine.rb +1 -1
  31. data/lib/puppet/provider/package/msi.rb +97 -51
  32. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +1 -0
  33. data/lib/puppet/provider/service/gentoo.rb +0 -2
  34. data/lib/puppet/provider/service/openrc.rb +69 -0
  35. data/lib/puppet/provider/service/windows.rb +6 -4
  36. data/lib/puppet/provider/user/aix.rb +8 -4
  37. data/lib/puppet/provider/user/useradd.rb +6 -0
  38. data/lib/puppet/rails/benchmark.rb +2 -2
  39. data/lib/puppet/reports/store.rb +9 -9
  40. data/lib/puppet/resource/catalog.rb +2 -1
  41. data/lib/puppet/resource/type_collection.rb +2 -1
  42. data/lib/puppet/ssl/base.rb +1 -2
  43. data/lib/puppet/ssl/certificate_authority/interface.rb +1 -0
  44. data/lib/puppet/test/test_helper.rb +2 -1
  45. data/lib/puppet/type.rb +1 -1
  46. data/lib/puppet/type/augeas.rb +1 -1
  47. data/lib/puppet/type/file.rb +4 -2
  48. data/lib/puppet/type/scheduled_task.rb +8 -10
  49. data/lib/puppet/type/tidy.rb +1 -1
  50. data/lib/puppet/util.rb +63 -25
  51. data/lib/puppet/util/autoload.rb +6 -4
  52. data/lib/puppet/util/checksums.rb +3 -8
  53. data/lib/puppet/util/diff.rb +2 -1
  54. data/lib/puppet/util/filetype.rb +1 -3
  55. data/lib/puppet/util/run_mode.rb +2 -1
  56. data/lib/puppet/util/suidmanager.rb +1 -1
  57. data/lib/puppet/util/windows.rb +1 -0
  58. data/lib/puppet/util/windows/file.rb +27 -0
  59. data/lib/puppet/util/windows/user.rb +1 -2
  60. data/man/man8/puppet-agent.8 +4 -0
  61. data/man/man8/puppet-master.8 +4 -0
  62. data/man/man8/puppetmasterd.8 +4 -0
  63. data/spec/fixtures/unit/provider/augeas/augeas/augeas/lenses/test.aug +13 -0
  64. data/spec/fixtures/unit/provider/augeas/augeas/etc/fstab +10 -0
  65. data/spec/fixtures/unit/provider/augeas/augeas/etc/hosts +6 -0
  66. data/spec/fixtures/unit/provider/augeas/augeas/etc/test +3 -0
  67. data/spec/fixtures/unit/provider/augeas/augeas/test.aug +13 -0
  68. data/spec/fixtures/unit/provider/service/openrc/rcservice_list +8 -0
  69. data/spec/fixtures/unit/provider/service/openrc/rcstatus +43 -0
  70. data/spec/integration/defaults_spec.rb +3 -3
  71. data/spec/integration/network/server/mongrel_spec.rb +8 -6
  72. data/spec/integration/parser/parser_spec.rb +1 -1
  73. data/spec/integration/type/file_spec.rb +49 -12
  74. data/spec/lib/puppet_spec/database.rb +5 -3
  75. data/spec/lib/puppet_spec/files.rb +2 -1
  76. data/spec/monkey_patches/alias_should_to_must.rb +15 -2
  77. data/spec/shared_behaviours/file_serving_model.rb +9 -6
  78. data/spec/shared_behaviours/path_parameters.rb +5 -5
  79. data/spec/shared_behaviours/things_that_declare_options.rb +5 -5
  80. data/spec/unit/application/facts_spec.rb +1 -1
  81. data/spec/unit/application_spec.rb +10 -8
  82. data/spec/unit/configurer_spec.rb +11 -2
  83. data/spec/unit/face/ca_spec.rb +15 -15
  84. data/spec/unit/face/help_spec.rb +5 -5
  85. data/spec/unit/face/module/install_spec.rb +13 -2
  86. data/spec/unit/face/node_spec.rb +7 -6
  87. data/spec/unit/indirector/certificate_request/ca_spec.rb +1 -1
  88. data/spec/unit/indirector/envelope_spec.rb +0 -13
  89. data/spec/unit/indirector/facts/inventory_service_spec.rb +1 -1
  90. data/spec/unit/indirector/queue_spec.rb +3 -3
  91. data/spec/unit/indirector/rest_spec.rb +31 -20
  92. data/spec/unit/indirector_spec.rb +5 -5
  93. data/spec/unit/interface/action_builder_spec.rb +3 -2
  94. data/spec/unit/interface/action_manager_spec.rb +1 -1
  95. data/spec/unit/interface/action_spec.rb +4 -3
  96. data/spec/unit/interface/face_collection_spec.rb +1 -1
  97. data/spec/unit/interface/option_spec.rb +13 -9
  98. data/spec/unit/interface_spec.rb +5 -5
  99. data/spec/unit/module_tool/applications/unpacker_spec.rb +61 -0
  100. data/spec/unit/network/handler/fileserver_spec.rb +3 -3
  101. data/spec/unit/other/transbucket_spec.rb +6 -9
  102. data/spec/unit/parser/ast/resource_spec.rb +27 -0
  103. data/spec/unit/parser/functions/create_resources_spec.rb +12 -12
  104. data/spec/unit/parser/lexer_spec.rb +5 -5
  105. data/spec/unit/provider/augeas/augeas_spec.rb +78 -0
  106. data/spec/unit/provider/nameservice/directoryservice_spec.rb +6 -6
  107. data/spec/unit/provider/package/freebsd_spec.rb +2 -2
  108. data/spec/unit/provider/package/msi_spec.rb +181 -114
  109. data/spec/unit/provider/package/openbsd_spec.rb +1 -0
  110. data/spec/unit/provider/package/pkgdmg_spec.rb +3 -3
  111. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +1 -1
  112. data/spec/unit/provider/service/openrc_spec.rb +209 -0
  113. data/spec/unit/provider/service/windows_spec.rb +57 -59
  114. data/spec/unit/provider/user/useradd_spec.rb +7 -0
  115. data/spec/unit/reports/store_spec.rb +13 -13
  116. data/spec/unit/resource/catalog_spec.rb +29 -24
  117. data/spec/unit/resource_spec.rb +13 -13
  118. data/spec/unit/simple_graph_spec.rb +12 -12
  119. data/spec/unit/ssl/certificate_authority/interface_spec.rb +3 -3
  120. data/spec/unit/ssl/certificate_authority_spec.rb +11 -10
  121. data/spec/unit/transaction_spec.rb +3 -3
  122. data/spec/unit/type/cron_spec.rb +171 -171
  123. data/spec/unit/type/exec_spec.rb +29 -27
  124. data/spec/unit/type/file_spec.rb +22 -13
  125. data/spec/unit/type/interface_spec.rb +1 -1
  126. data/spec/unit/type/scheduled_task_spec.rb +15 -14
  127. data/spec/unit/type/tidy_spec.rb +2 -2
  128. data/spec/unit/type/user_spec.rb +15 -15
  129. data/spec/unit/type/vlan_spec.rb +1 -1
  130. data/spec/unit/type_spec.rb +22 -25
  131. data/spec/unit/util/autoload_spec.rb +13 -7
  132. data/spec/unit/util/backups_spec.rb +36 -67
  133. data/spec/unit/util/storage_spec.rb +2 -9
  134. data/spec/unit/util/suidmanager_spec.rb +1 -1
  135. data/spec/unit/util_spec.rb +20 -28
  136. data/test/ral/manager/attributes.rb +1 -1
  137. metadata +1553 -1542
@@ -12,7 +12,7 @@ describe Puppet::Type.type(:vlan) do
12
12
  end
13
13
 
14
14
  it "should be applied on device" do
15
- Puppet::Type.type(:vlan).new(:name => "200").should be_appliable_to_device
15
+ Puppet::Type.type(:vlan).new(:name => "200").must be_appliable_to_device
16
16
  end
17
17
 
18
18
  it "should have an ensure property" do
@@ -13,17 +13,17 @@ describe Puppet::Type, :fails_on_windows => true do
13
13
  this.sort.should == [a, b, c]
14
14
  end
15
15
 
16
- a.should be < b
17
- a.should be < c
18
- b.should be > a
19
- b.should be < c
20
- c.should be > a
21
- c.should be > b
16
+ a.must be < b
17
+ a.must be < c
18
+ b.must be > a
19
+ b.must be < c
20
+ c.must be > a
21
+ c.must be > b
22
22
 
23
- [a, b, c].each {|x| a.should be <= x }
24
- [a, b, c].each {|x| c.should be >= x }
23
+ [a, b, c].each {|x| a.must be <= x }
24
+ [a, b, c].each {|x| c.must be >= x }
25
25
 
26
- b.should be_between(a, c)
26
+ b.must be_between(a, c)
27
27
  end
28
28
 
29
29
  it "should consider a parameter to be valid if it is a valid parameter" do
@@ -63,7 +63,7 @@ describe Puppet::Type, :fails_on_windows => true do
63
63
  end
64
64
 
65
65
  it "should have a method for setting default values for resources" do
66
- Puppet::Type.type(:mount).new(:name => "foo").should respond_to(:set_default)
66
+ Puppet::Type.type(:mount).new(:name => "foo").must respond_to(:set_default)
67
67
  end
68
68
 
69
69
  it "should do nothing for attributes that have no defaults and no specified value" do
@@ -71,7 +71,7 @@ describe Puppet::Type, :fails_on_windows => true do
71
71
  end
72
72
 
73
73
  it "should have a method for adding tags" do
74
- Puppet::Type.type(:mount).new(:name => "foo").should respond_to(:tags)
74
+ Puppet::Type.type(:mount).new(:name => "foo").must respond_to(:tags)
75
75
  end
76
76
 
77
77
  it "should use the tagging module" do
@@ -97,11 +97,11 @@ describe Puppet::Type, :fails_on_windows => true do
97
97
  end
98
98
 
99
99
  it "should have a method to know if the resource is exported" do
100
- Puppet::Type.type(:mount).new(:name => "foo").should respond_to(:exported?)
100
+ Puppet::Type.type(:mount).new(:name => "foo").must respond_to(:exported?)
101
101
  end
102
102
 
103
103
  it "should have a method to know if the resource is virtual" do
104
- Puppet::Type.type(:mount).new(:name => "foo").should respond_to(:virtual?)
104
+ Puppet::Type.type(:mount).new(:name => "foo").must respond_to(:virtual?)
105
105
  end
106
106
 
107
107
  it "should consider its version to be its catalog version" do
@@ -286,7 +286,7 @@ describe Puppet::Type, :fails_on_windows => true do
286
286
  describe "and passed a TransObject" do
287
287
  it "should fail" do
288
288
  trans = Puppet::TransObject.new("/foo", :mount)
289
- lambda { Puppet::Type.type(:mount).new(trans) }.should raise_error(Puppet::DevError)
289
+ expect { Puppet::Type.type(:mount).new(trans) }.to raise_error(Puppet::DevError)
290
290
  end
291
291
  end
292
292
 
@@ -362,7 +362,7 @@ describe Puppet::Type, :fails_on_windows => true do
362
362
  end
363
363
 
364
364
  it "should fail if any invalid attributes have been provided" do
365
- lambda { Puppet::Type.type(:mount).new(:title => "/foo", :nosuchattr => "whatever") }.should raise_error(Puppet::Error)
365
+ expect { Puppet::Type.type(:mount).new(:title => "/foo", :nosuchattr => "whatever") }.to raise_error(Puppet::Error)
366
366
  end
367
367
 
368
368
  it "should set its name to the resource's title if the resource does not have a :name or namevar parameter set" do
@@ -372,7 +372,7 @@ describe Puppet::Type, :fails_on_windows => true do
372
372
  end
373
373
 
374
374
  it "should fail if no title, name, or namevar are provided" do
375
- lambda { Puppet::Type.type(:file).new(:atboot => true) }.should raise_error(Puppet::Error)
375
+ expect { Puppet::Type.type(:file).new(:atboot => true) }.to raise_error(Puppet::Error)
376
376
  end
377
377
 
378
378
  it "should set the attributes in the order returned by the class's :allattrs method" do
@@ -485,7 +485,7 @@ describe Puppet::Type, :fails_on_windows => true do
485
485
  it "should fail if its provider is unsuitable" do
486
486
  @resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
487
487
  @resource.provider.class.expects(:suitable?).returns false
488
- lambda { @resource.retrieve_resource }.should raise_error(Puppet::Error)
488
+ expect { @resource.retrieve_resource }.to raise_error(Puppet::Error)
489
489
  end
490
490
 
491
491
  it "should return a Puppet::Resource instance with its type and title set appropriately" do
@@ -583,24 +583,21 @@ describe Puppet::Type, :fails_on_windows => true do
583
583
 
584
584
  it "should be suitable if its type doesn't use providers" do
585
585
  type.stubs(:paramclass).with(:provider).returns nil
586
-
587
- resource.should be_suitable
586
+ resource.must be_suitable
588
587
  end
589
588
 
590
589
  it "should be suitable if it has a provider which is suitable" do
591
- resource.should be_suitable
590
+ resource.must be_suitable
592
591
  end
593
592
 
594
593
  it "should not be suitable if it has a provider which is not suitable" do
595
594
  provider.class.stubs(:suitable?).returns false
596
-
597
595
  resource.should_not be_suitable
598
596
  end
599
597
 
600
598
  it "should be suitable if it does not have a provider and there is a default provider" do
601
599
  resource.stubs(:provider).returns nil
602
-
603
- resource.should be_suitable
600
+ resource.must be_suitable
604
601
  end
605
602
 
606
603
  it "should not be suitable if it doesn't have a provider and there is not default provider" do
@@ -626,7 +623,7 @@ describe Puppet::Type, :fails_on_windows => true do
626
623
  end
627
624
  end
628
625
 
629
- expect { fake_type.instances }.should_not raise_error
626
+ expect { fake_type.instances }.to_not raise_error
630
627
  end
631
628
  end
632
629
 
@@ -745,7 +742,7 @@ describe Puppet::Type.metaparamclass(:audit) do
745
742
  end
746
743
 
747
744
  it "should fail if asked to audit an invalid property" do
748
- lambda { @resource[:audit] = :foobar }.should raise_error(Puppet::Error)
745
+ expect { @resource[:audit] = :foobar }.to raise_error(Puppet::Error)
749
746
  end
750
747
 
751
748
  it "should create an attribute instance for each auditable property" do
@@ -101,23 +101,29 @@ describe Puppet::Util::Autoload do
101
101
  describe "when loading all files" do
102
102
  before do
103
103
  @autoload.stubs(:searchpath).returns %w{/a}
104
- Dir.stubs(:glob).returns "/path/to/file.rb"
105
-
106
- @autoload.class.stubs(:loaded?).returns(false)
104
+ @filename = rand(10000).to_s + ".rb"
105
+ Dir.stubs(:glob).returns(@filename)
107
106
  end
108
107
 
109
108
  [RuntimeError, LoadError, SyntaxError].each do |error|
110
- it "should die an if a #{error.to_s} exception is thrown", :'fails_on_ruby_1.9.2' => true do
109
+ it "dies if a #{error.to_s} exception is thrown", :'fails_on_ruby_1.9.2' => true do
111
110
  Kernel.expects(:require).raises error
112
111
 
113
- lambda { @autoload.loadall }.should raise_error(Puppet::Error)
112
+ expect { @autoload.loadall }.to raise_error(Puppet::Error)
114
113
  end
115
114
  end
116
115
 
117
- it "should require the full path to the file", :'fails_on_ruby_1.9.2' => true do
118
- Kernel.expects(:require).with("/path/to/file.rb")
116
+ it "requires the file", :'fails_on_ruby_1.9.2' => true do
117
+ Kernel.expects(:require).with(@filename)
119
118
 
120
119
  @autoload.loadall
121
120
  end
121
+
122
+ it "marks the file as required even if loading fails", :'fails_on_ruby_1.9.2' => true do
123
+ Dir.stubs(:glob).returns "/this/file/does/not/exist.rb"
124
+
125
+ expect { @autoload.loadall }.to raise_error(Puppet::Error)
126
+ expect { @autoload.loadall }.not_to raise_error
127
+ end
122
128
  end
123
129
  end
@@ -6,152 +6,121 @@ require 'puppet/util/backups'
6
6
  describe Puppet::Util::Backups do
7
7
  include PuppetSpec::Files
8
8
 
9
- before do
10
- FileTest.stubs(:exists?).returns true
11
- @nosuchfile = make_absolute('/no/such/file')
9
+ let(:bucket) { stub('bucket', :name => "foo") }
10
+ let!(:file) do
11
+ f = Puppet::Type.type(:file).new(:name => path, :backup => 'foo')
12
+ f.stubs(:bucket).returns(bucket)
13
+ f
12
14
  end
13
15
 
14
16
  describe "when backing up a file" do
17
+ let(:path) { make_absolute('/no/such/file') }
18
+
15
19
  it "should noop if the file does not exist" do
16
- FileTest.expects(:exists?).returns false
17
- file = Puppet::Type.type(:file).new(:name => @nosuchfile)
20
+ file = Puppet::Type.type(:file).new(:name => path)
21
+
18
22
  file.expects(:bucket).never
23
+ FileTest.expects(:exists?).with(path).returns false
19
24
 
20
25
  file.perform_backup
21
26
  end
22
27
 
23
28
  it "should succeed silently if self[:backup] is false" do
24
- file = Puppet::Type.type(:file).new(:name => @nosuchfile, :backup => false)
29
+ file = Puppet::Type.type(:file).new(:name => path, :backup => false)
30
+
25
31
  file.expects(:bucket).never
26
32
  FileTest.expects(:exists?).never
33
+
27
34
  file.perform_backup
28
35
  end
29
36
 
30
37
  it "a bucket should be used when provided" do
31
- path = make_absolute('/my/file')
32
-
33
38
  File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file'))
34
-
35
- file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo')
36
- bucket = stub('bucket', 'name' => 'foo')
37
- file.stubs(:bucket).returns bucket
38
-
39
39
  bucket.expects(:backup).with(path).returns("mysum")
40
+ FileTest.expects(:exists?).with(path).returns(true)
40
41
 
41
42
  file.perform_backup
42
43
  end
43
44
 
44
45
  it "should propagate any exceptions encountered when backing up to a filebucket" do
45
- path = make_absolute('/my/file')
46
-
47
46
  File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file'))
48
-
49
- file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo')
50
- bucket = stub('bucket', 'name' => 'foo')
51
- file.stubs(:bucket).returns bucket
52
-
53
47
  bucket.expects(:backup).raises ArgumentError
48
+ FileTest.expects(:exists?).with(path).returns(true)
54
49
 
55
50
  lambda { file.perform_backup }.should raise_error(ArgumentError)
56
51
  end
57
52
 
58
- describe "and no filebucket is configured" do
59
- it "should remove any local backup if one exists" do
60
- path = make_absolute('/my/file')
61
- FileTest.stubs(:exists?).returns true
62
-
63
- backup = path + ".foo"
53
+ describe "and local backup is configured" do
54
+ let(:ext) { 'foobkp' }
55
+ let(:backup) { path + '.' + ext }
56
+ let(:file) { Puppet::Type.type(:file).new(:name => path, :backup => '.'+ext) }
64
57
 
58
+ it "should remove any local backup if one exists" do
65
59
  File.expects(:lstat).with(backup).returns stub("stat", :ftype => "file")
66
60
  File.expects(:unlink).with(backup)
67
-
68
61
  FileUtils.stubs(:cp_r)
62
+ FileTest.expects(:exists?).with(path).returns(true)
69
63
 
70
- file = Puppet::Type.type(:file).new(:name => path, :backup => '.foo')
71
64
  file.perform_backup
72
65
  end
73
66
 
74
67
  it "should fail when the old backup can't be removed" do
75
- path = make_absolute('/my/file')
76
- FileTest.stubs(:exists?).returns true
77
-
78
- backup = path + ".foo"
79
-
80
68
  File.expects(:lstat).with(backup).returns stub("stat", :ftype => "file")
81
69
  File.expects(:unlink).raises ArgumentError
82
-
83
70
  FileUtils.expects(:cp_r).never
71
+ FileTest.expects(:exists?).with(path).returns(true)
84
72
 
85
- file = Puppet::Type.type(:file).new(:name => path, :backup => '.foo')
86
73
  lambda { file.perform_backup }.should raise_error(Puppet::Error)
87
74
  end
88
75
 
89
76
  it "should not try to remove backups that don't exist" do
90
- path = make_absolute('/my/file')
91
- FileTest.stubs(:exists?).returns true
92
-
93
- backup = path + ".foo"
94
-
95
77
  File.expects(:lstat).with(backup).raises(Errno::ENOENT)
96
78
  File.expects(:unlink).never
97
-
98
79
  FileUtils.stubs(:cp_r)
80
+ FileTest.expects(:exists?).with(path).returns(true)
99
81
 
100
- file = Puppet::Type.type(:file).new(:name => path, :backup => '.foo')
101
82
  file.perform_backup
102
83
  end
103
84
 
104
85
  it "a copy should be created in the local directory" do
105
- path = make_absolute('/my/file')
106
- FileTest.stubs(:exists?).with(path).returns true
86
+ FileUtils.expects(:cp_r).with(path, backup, :preserve => true)
87
+ FileTest.stubs(:exists?).with(path).returns(true)
107
88
 
108
- FileUtils.expects(:cp_r).with(path, path + ".foo", :preserve => true)
109
-
110
- file = Puppet::Type.type(:file).new(:name => path, :backup => '.foo')
111
89
  file.perform_backup.should be_true
112
90
  end
113
91
 
114
92
  it "should propagate exceptions if no backup can be created" do
115
- path = make_absolute('/my/file')
116
- FileTest.stubs(:exists?).with(path).returns true
117
-
118
93
  FileUtils.expects(:cp_r).raises ArgumentError
119
94
 
120
- file = Puppet::Type.type(:file).new(:name => path, :backup => '.foo')
95
+ FileTest.stubs(:exists?).with(path).returns(true)
121
96
  lambda { file.perform_backup }.should raise_error(Puppet::Error)
122
97
  end
123
98
  end
124
99
  end
125
100
 
126
101
  describe "when backing up a directory" do
127
- it "a bucket should work when provided" do
128
- path = make_absolute('/my/dir')
129
-
130
- File.stubs(:file?).returns true
131
- Find.expects(:find).with(path).yields(make_absolute("/my/dir/file"))
102
+ let(:path) { make_absolute('/my/dir') }
103
+ let(:filename) { File.join(path, 'file') }
132
104
 
133
- bucket = stub('bucket', :name => "eh")
134
- bucket.expects(:backup).with(make_absolute("/my/dir/file")).returns true
105
+ it "a bucket should work when provided" do
106
+ File.stubs(:file?).with(filename).returns true
107
+ Find.expects(:find).with(path).yields(filename)
135
108
 
136
- file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo')
137
- file.stubs(:bucket).returns bucket
109
+ bucket.expects(:backup).with(filename).returns true
138
110
 
139
111
  File.stubs(:stat).with(path).returns(stub('stat', :ftype => 'directory'))
140
112
 
113
+ FileTest.stubs(:exists?).with(path).returns(true)
114
+ FileTest.stubs(:exists?).with(filename).returns(true)
115
+
141
116
  file.perform_backup
142
117
  end
143
118
 
144
119
  it "should do nothing when recursing" do
145
- path = make_absolute('/my/dir')
146
-
147
- bucket = stub('bucket', :name => "eh")
148
- bucket.expects(:backup).never
149
-
150
120
  file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo', :recurse => true)
151
- file.stubs(:bucket).returns bucket
152
121
 
122
+ bucket.expects(:backup).never
153
123
  File.stubs(:stat).with(path).returns(stub('stat', :ftype => 'directory'))
154
-
155
124
  Find.expects(:find).never
156
125
 
157
126
  file.perform_backup
@@ -183,13 +183,12 @@ describe Puppet::Util::Storage do
183
183
 
184
184
  describe "when storing to the state file" do
185
185
  before(:each) do
186
- @state_file = Tempfile.new('storage_test')
186
+ @state_file = tmpfile('storage_test')
187
187
  @saved_statefile = Puppet[:statefile]
188
- Puppet[:statefile] = @state_file.path
188
+ Puppet[:statefile] = @state_file
189
189
  end
190
190
 
191
191
  it "should create the state file if it does not exist" do
192
- @state_file.close!()
193
192
  FileTest.exists?(Puppet[:statefile]).should be_false
194
193
  Puppet::Util::Storage.cache(:yayness)
195
194
 
@@ -198,7 +197,6 @@ describe Puppet::Util::Storage do
198
197
  end
199
198
 
200
199
  it "should raise an exception if the state file is not a regular file" do
201
- @state_file.close!()
202
200
  Dir.mkdir(Puppet[:statefile])
203
201
  Puppet::Util::Storage.cache(:yayness)
204
202
 
@@ -224,10 +222,5 @@ describe Puppet::Util::Storage do
224
222
  proc { Puppet::Util::Storage.load }.should_not raise_error
225
223
  Puppet::Util::Storage.state.should == {:yayness=>{}}
226
224
  end
227
-
228
- after(:each) do
229
- @state_file.close!()
230
- Puppet[:statefile] = @saved_statefile
231
- end
232
225
  end
233
226
  end
@@ -278,6 +278,6 @@ describe 'Puppet::Util::SUIDManager#groups=' do
278
278
  it "(#3419) should fail if an Errno::EINVAL is raised NOT on OS X" do
279
279
  Process.expects(:groups=).raises(Errno::EINVAL, 'blew up')
280
280
  subject.expects(:osx_maj_ver).returns(false)
281
- expect { subject.groups = ['list', 'of', 'groups'] }.should raise_error(Errno::EINVAL)
281
+ expect { subject.groups = ['list', 'of', 'groups'] }.to raise_error(Errno::EINVAL)
282
282
  end
283
283
  end
@@ -411,7 +411,7 @@ describe Puppet::Util do
411
411
  end
412
412
 
413
413
  it "should wait for the child process to exit" do
414
- Puppet::Util.stubs(:wait_for_output)
414
+ Puppet::Util.expects(:wait_for_output)
415
415
 
416
416
  Puppet::Util.execute('test command')
417
417
  end
@@ -456,6 +456,16 @@ describe Puppet::Util do
456
456
  File.should_not be_exist(path)
457
457
  end
458
458
 
459
+ it "should not raise an error if the file is open" do
460
+ stdout = Tempfile.new('test')
461
+ Tempfile.stubs(:new).returns(stdout)
462
+ file = File.new(stdout.path, 'r')
463
+
464
+ expect {
465
+ Puppet::Util.execute('test command')
466
+ }.to_not raise_error
467
+ end
468
+
459
469
  it "should raise an error if failonfail is true and the child failed" do
460
470
  stub_process_wait(1)
461
471
 
@@ -709,20 +719,12 @@ describe Puppet::Util do
709
719
  expect { subject.replace_file(target.path, 0600) }.to raise_error /block/
710
720
  end
711
721
 
712
- it "should replace a file when invoked" do
713
- # Check that our file has the expected content.
714
- File.read(target.path).should == "hello, world\n"
715
-
716
- # Replace the file.
717
- subject.replace_file(target.path, 0600) do |fh|
718
- fh.puts "I am the passenger..."
719
- end
720
-
721
- # ...and check the replacement was complete.
722
- File.read(target.path).should == "I am the passenger...\n"
723
- end
724
-
725
- [0555, 0600, 0660, 0700, 0770].each do |mode|
722
+ # When running with the same user and group sid, which is the default,
723
+ # Windows collapses the owner and group modes into a single ACE, resulting
724
+ # in set(0600) => get(0660) and so forth. --daniel 2012-03-30
725
+ modes = [0555, 0660, 0770]
726
+ modes += [0600, 0700] unless Puppet.features.microsoft_windows?
727
+ modes.each do |mode|
726
728
  it "should copy 0#{mode.to_s(8)} permissions from the target file by default" do
727
729
  set_mode(mode, target.path)
728
730
 
@@ -735,9 +737,9 @@ describe Puppet::Util do
735
737
  end
736
738
  end
737
739
 
738
- it "should copy the permissions of the source file before yielding" do
740
+ it "should copy the permissions of the source file before yielding on Unix", :if => !Puppet.features.microsoft_windows? do
739
741
  set_mode(0555, target.path)
740
- inode = File.stat(target.path).ino unless Puppet.features.microsoft_windows?
742
+ inode = File.stat(target.path).ino
741
743
 
742
744
  yielded = false
743
745
  subject.replace_file(target.path, 0600) do |fh|
@@ -746,9 +748,7 @@ describe Puppet::Util do
746
748
  end
747
749
  yielded.should be_true
748
750
 
749
- # We can't check inode on Windows
750
- File.stat(target.path).ino.should_not == inode unless Puppet.features.microsoft_windows?
751
-
751
+ File.stat(target.path).ino.should_not == inode
752
752
  get_mode(target.path).should == 0555
753
753
  end
754
754
 
@@ -789,13 +789,5 @@ describe Puppet::Util do
789
789
  File.read(target.path).should == "hello, world\n"
790
790
  end
791
791
  end
792
-
793
- describe "on Windows platforms" do
794
- it "should fail and complain" do
795
- Puppet.features.stubs(:microsoft_windows?).returns true
796
-
797
- expect { Puppet::Util.replace_file("C:/foo", 0644) {} }.to raise_error(Puppet::DevError, "replace_file is non-functional on Windows")
798
- end
799
- end
800
792
  end
801
793
  end