puppet 6.2.0-x86-mingw32 → 6.3.0-x86-mingw32

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +70 -0
  3. data/Gemfile.lock +7 -7
  4. data/lib/puppet/application.rb +1 -1
  5. data/lib/puppet/application/lookup.rb +1 -1
  6. data/lib/puppet/confine/boolean.rb +45 -0
  7. data/lib/puppet/confine/false.rb +7 -1
  8. data/lib/puppet/confine/true.rb +7 -1
  9. data/lib/puppet/defaults.rb +0 -18
  10. data/lib/puppet/functions/call.rb +2 -1
  11. data/lib/puppet/functions/group_by.rb +54 -0
  12. data/lib/puppet/functions/index.rb +167 -0
  13. data/lib/puppet/functions/partition.rb +54 -0
  14. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1 -1
  15. data/lib/puppet/pops/issues.rb +4 -0
  16. data/lib/puppet/pops/model/factory.rb +38 -4
  17. data/lib/puppet/pops/parser/egrammar.ra +2 -2
  18. data/lib/puppet/pops/parser/eparser.rb +2 -2
  19. data/lib/puppet/pops/parser/heredoc_support.rb +17 -7
  20. data/lib/puppet/pops/parser/lexer2.rb +6 -1
  21. data/lib/puppet/pops/parser/locator.rb +106 -86
  22. data/lib/puppet/pops/parser/parser_support.rb +11 -2
  23. data/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
  24. data/lib/puppet/pops/validation/checker4_0.rb +2 -2
  25. data/lib/puppet/provider/group/windows_adsi.rb +4 -1
  26. data/lib/puppet/provider/package/apt.rb +2 -2
  27. data/lib/puppet/provider/package/dnf.rb +2 -2
  28. data/lib/puppet/provider/package/gem.rb +2 -2
  29. data/lib/puppet/provider/package/openbsd.rb +2 -2
  30. data/lib/puppet/provider/package/pacman.rb +1 -2
  31. data/lib/puppet/provider/package/pip.rb +1 -2
  32. data/lib/puppet/provider/package/pip3.rb +1 -2
  33. data/lib/puppet/provider/package/pkg.rb +2 -4
  34. data/lib/puppet/provider/package/portage.rb +1 -2
  35. data/lib/puppet/provider/package/rpm.rb +1 -2
  36. data/lib/puppet/provider/package/sun.rb +2 -2
  37. data/lib/puppet/provider/package/windows.rb +2 -2
  38. data/lib/puppet/provider/package/yum.rb +1 -2
  39. data/lib/puppet/provider/package/zypper.rb +2 -2
  40. data/lib/puppet/provider/service/upstart.rb +16 -6
  41. data/lib/puppet/transaction/resource_harness.rb +1 -0
  42. data/lib/puppet/type/file.rb +6 -1
  43. data/lib/puppet/util/log.rb +7 -2
  44. data/lib/puppet/util/pidlock.rb +14 -1
  45. data/lib/puppet/util/windows/process.rb +73 -5
  46. data/lib/puppet/version.rb +1 -1
  47. data/locales/puppet.pot +92 -92
  48. data/man/man5/puppet.conf.5 +2 -2
  49. data/man/man8/puppet-agent.8 +1 -1
  50. data/man/man8/puppet-apply.8 +1 -1
  51. data/man/man8/puppet-catalog.8 +1 -1
  52. data/man/man8/puppet-config.8 +1 -1
  53. data/man/man8/puppet-describe.8 +1 -1
  54. data/man/man8/puppet-device.8 +1 -1
  55. data/man/man8/puppet-doc.8 +1 -1
  56. data/man/man8/puppet-epp.8 +1 -1
  57. data/man/man8/puppet-facts.8 +1 -1
  58. data/man/man8/puppet-filebucket.8 +1 -1
  59. data/man/man8/puppet-generate.8 +1 -1
  60. data/man/man8/puppet-help.8 +1 -1
  61. data/man/man8/puppet-key.8 +1 -1
  62. data/man/man8/puppet-lookup.8 +2 -2
  63. data/man/man8/puppet-man.8 +1 -1
  64. data/man/man8/puppet-module.8 +1 -1
  65. data/man/man8/puppet-node.8 +1 -1
  66. data/man/man8/puppet-parser.8 +1 -1
  67. data/man/man8/puppet-plugin.8 +1 -1
  68. data/man/man8/puppet-report.8 +1 -1
  69. data/man/man8/puppet-resource.8 +1 -1
  70. data/man/man8/puppet-script.8 +1 -1
  71. data/man/man8/puppet-ssl.8 +1 -1
  72. data/man/man8/puppet-status.8 +1 -1
  73. data/man/man8/puppet.8 +2 -2
  74. data/spec/unit/application_spec.rb +8 -1
  75. data/spec/unit/confine/false_spec.rb +27 -0
  76. data/spec/unit/confine/true_spec.rb +27 -0
  77. data/spec/unit/defaults_spec.rb +0 -14
  78. data/spec/unit/functions/group_by_spec.rb +40 -0
  79. data/spec/unit/functions/index_spec.rb +184 -0
  80. data/spec/unit/functions/partition_spec.rb +40 -0
  81. data/spec/unit/pops/loaders/loaders_spec.rb +5 -0
  82. data/spec/unit/pops/parser/locator_spec.rb +45 -0
  83. data/spec/unit/pops/parser/parse_heredoc_spec.rb +111 -15
  84. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +9 -0
  85. data/spec/unit/provider/group/windows_adsi_spec.rb +7 -1
  86. data/spec/unit/transaction/resource_harness_spec.rb +26 -0
  87. data/spec/unit/util/execution_spec.rb +2 -2
  88. data/spec/unit/util/log_spec.rb +15 -0
  89. data/spec/unit/util/pidlock_spec.rb +21 -1
  90. metadata +13 -2
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppet_spec/compiler'
4
+ require 'matchers/resource'
5
+
6
+ describe 'the partition function' do
7
+ include PuppetSpec::Compiler
8
+ include Matchers::Resource
9
+
10
+ context 'for an array' do
11
+ it 'partitions by item' do
12
+ manifest = "notify { String(partition(['', b, ab]) |$s| { $s.empty }): }"
13
+ expect(compile_to_catalog(manifest)).to have_resource("Notify[[[''], ['b', 'ab']]]")
14
+ end
15
+
16
+ it 'partitions by index, item' do
17
+ manifest = "notify { String(partition(['', b, ab]) |$i, $s| { $i == 2 or $s.empty }): }"
18
+ expect(compile_to_catalog(manifest)).to have_resource("Notify[[['', 'ab'], ['b']]]")
19
+ end
20
+ end
21
+
22
+ context 'for a hash' do
23
+ it 'partitions by key-value pair' do
24
+ manifest = "notify { String(partition(a => [1, 2], b => []) |$kv| { $kv[1].empty }): }"
25
+ expect(compile_to_catalog(manifest)).to have_resource("Notify[[[['b', []]], [['a', [1, 2]]]]]")
26
+ end
27
+
28
+ it 'partitions by key, value' do
29
+ manifest = "notify { String(partition(a => [1, 2], b => []) |$k, $v| { $v.empty }): }"
30
+ expect(compile_to_catalog(manifest)).to have_resource("Notify[[[['b', []]], [['a', [1, 2]]]]]")
31
+ end
32
+ end
33
+
34
+ context 'for a string' do
35
+ it 'fails' do
36
+ manifest = "notify { String(partition('something') |$s| { $s.empty }): }"
37
+ expect { compile_to_catalog(manifest) }.to raise_error(Puppet::PreformattedError)
38
+ end
39
+ end
40
+ end
@@ -421,6 +421,11 @@ describe 'loaders' do
421
421
  expect(function.call(scope, 'passed in scope')).to eql("usee::callee_ws() got 'passed in scope'")
422
422
  end
423
423
 
424
+ it 'calls can be made to a non core function via the call() function' do
425
+ call_function = loader.load_typed(typed_name(:function, 'call')).value
426
+ expect(call_function.call(scope, 'user::puppetcaller4')).to eql("usee::callee() got 'first' - usee::callee() got 'second'")
427
+ end
428
+
424
429
  end
425
430
 
426
431
  context 'when a 3x load takes place' do
@@ -41,4 +41,49 @@ describe Puppet::Pops::Parser::Locator do
41
41
  expect(model.body.locator.line_for_offset(2)).to eq(:third_value)
42
42
  end
43
43
 
44
+ it 'A heredoc without margin and interpolated expression location has offset and length relative the source' do
45
+ parser = Puppet::Pops::Parser::Parser.new()
46
+ src = <<-CODE
47
+ # line one
48
+ # line two
49
+ @("END"/L)
50
+ Line four\\
51
+ Line five ${1 +
52
+ 1}
53
+ END
54
+ CODE
55
+
56
+ model = parser.parse_string(src).model
57
+ interpolated_expr = model.body.text_expr.segments[1].expr
58
+ expect(interpolated_expr.left_expr.offset).to eq(84)
59
+ expect(interpolated_expr.left_expr.length).to eq(1)
60
+ expect(interpolated_expr.right_expr.offset).to eq(96)
61
+ expect(interpolated_expr.right_expr.length).to eq(1)
62
+ expect(interpolated_expr.offset).to eq(86) # the + sign
63
+ expect(interpolated_expr.length).to eq(1) # the + sign
64
+ expect(interpolated_expr.locator.extract_tree_text(interpolated_expr)).to eq("1 +\n 1")
65
+ end
66
+
67
+ it 'A heredoc with margin and interpolated expression location has offset and length relative the source' do
68
+ parser = Puppet::Pops::Parser::Parser.new()
69
+ src = <<-CODE
70
+ # line one
71
+ # line two
72
+ @("END"/L)
73
+ Line four\\
74
+ Line five ${1 +
75
+ 1}
76
+ |- END
77
+ CODE
78
+
79
+ model = parser.parse_string(src).model
80
+ interpolated_expr = model.body.text_expr.segments[1].expr
81
+ expect(interpolated_expr.left_expr.offset).to eq(84)
82
+ expect(interpolated_expr.left_expr.length).to eq(1)
83
+ expect(interpolated_expr.right_expr.offset).to eq(96)
84
+ expect(interpolated_expr.right_expr.length).to eq(1)
85
+ expect(interpolated_expr.offset).to eq(86) # the + sign
86
+ expect(interpolated_expr.length).to eq(1) # the + sign
87
+ expect(interpolated_expr.locator.extract_tree_text(interpolated_expr)).to eq("1 +\n 1")
88
+ end
44
89
  end
@@ -10,7 +10,7 @@ describe "egrammar parsing heredoc" do
10
10
  it "parses plain heredoc" do
11
11
  expect(dump(parse("@(END)\nThis is\nheredoc text\nEND\n"))).to eq([
12
12
  "(@()",
13
- " (sublocated 'This is\nheredoc text\n')",
13
+ " 'This is\nheredoc text\n'",
14
14
  ")"
15
15
  ].join("\n"))
16
16
  end
@@ -25,7 +25,7 @@ describe "egrammar parsing heredoc" do
25
25
  ].join("\n")
26
26
  expect(dump(parse(src))).to eq([
27
27
  "(@()",
28
- " (sublocated 'This is\nheredoc text\n')",
28
+ " 'This is\nheredoc text\n'",
29
29
  ")"
30
30
  ].join("\n"))
31
31
  end
@@ -40,7 +40,7 @@ describe "egrammar parsing heredoc" do
40
40
  ].join("\n")
41
41
  expect(dump(parse(src))).to eq([
42
42
  "(@()",
43
- " (sublocated 'This is\nheredoc text')",
43
+ " 'This is\nheredoc text'",
44
44
  ")"
45
45
  ].join("\n"))
46
46
  end
@@ -53,7 +53,7 @@ describe "egrammar parsing heredoc" do
53
53
  CODE
54
54
  expect(dump(parse(src))).to eq([
55
55
  "(@(syntax)",
56
- " (sublocated 'Tex\tt\\n')",
56
+ " 'Tex\tt\\n'",
57
57
  ")"
58
58
  ].join("\n"))
59
59
  end
@@ -66,7 +66,7 @@ describe "egrammar parsing heredoc" do
66
66
  CODE
67
67
  expect(dump(parse(src))).to eq([
68
68
  "(@()",
69
- " (sublocated (cat 'Hello ' (str $name)))",
69
+ " (cat 'Hello ' (str $name))",
70
70
  ")"
71
71
  ].join("\n"))
72
72
  end
@@ -79,7 +79,7 @@ describe "egrammar parsing heredoc" do
79
79
  CODE
80
80
  expect(dump(parse(src))).to eq([
81
81
  "(@()",
82
- " (sublocated (cat 'Hello \\' (str $name)))",
82
+ " (cat 'Hello \\' (str $name))",
83
83
  ")"
84
84
  ].join("\n"))
85
85
  end
@@ -92,7 +92,7 @@ describe "egrammar parsing heredoc" do
92
92
  CODE
93
93
  expect(dump(parse(src))).to eq([
94
94
  "(@()",
95
- " (sublocated (cat 'Hello \\' (str $name)))",
95
+ " (cat 'Hello \\' (str $name))",
96
96
  ")"
97
97
  ].join("\n"))
98
98
  end
@@ -107,7 +107,7 @@ describe "egrammar parsing heredoc" do
107
107
  parse(src)
108
108
  expect(dump(parse(src))).to eq([
109
109
  "(@()",
110
- " (sublocated 'First Line Second Line')",
110
+ " 'First Line Second Line'",
111
111
  ")"
112
112
  ].join("\n"))
113
113
  end
@@ -122,7 +122,7 @@ describe "egrammar parsing heredoc" do
122
122
  parse(src)
123
123
  expect(dump(parse(src))).to eq([
124
124
  "(@()",
125
- " (sublocated ' First Line Second Line')",
125
+ " ' First Line Second Line'",
126
126
  ")"
127
127
  ].join("\n"))
128
128
  end
@@ -135,12 +135,12 @@ describe "egrammar parsing heredoc" do
135
135
  CODE
136
136
  expect(dump(parse(src))).to eq([
137
137
  "(@()",
138
- " (sublocated (cat 'Hello ' (str $name) '$%a'))",
138
+ " (cat 'Hello ' (str $name) '$%a')",
139
139
  ")"
140
140
  ].join("\n"))
141
141
  end
142
142
 
143
- it "parses interpolated [] expression by looking at the correct preceding char for space" do
143
+ it "parses interpolated [] expression by looking at the correct preceding char for space when there is no heredoc margin" do
144
144
  # NOTE: Important not to use the left margin feature here
145
145
  src = <<-CODE
146
146
  $xxxxxxx = @("END")
@@ -150,12 +150,108 @@ END
150
150
  CODE
151
151
  expect(dump(parse(src))).to eq([
152
152
  "(= $xxxxxxx (@()",
153
- " (sublocated (cat (str (slice (slice $facts 'os') 'family')) '",
153
+ " (cat (str (slice (slice $facts 'os') 'family')) '",
154
154
  "XXXXXXX XXX",
155
- "'))",
155
+ "')",
156
156
  "))"].join("\n"))
157
157
  end
158
158
 
159
+ it "parses interpolated [] expression by looking at the correct preceding char for space when there is a heredoc margin" do
160
+ # NOTE: Important not to use the left margin feature here - the problem in PUP 9303 is triggered by lines and text before
161
+ # an interpolation containing [].
162
+ src = <<-CODE
163
+ # comment
164
+ # comment
165
+ $xxxxxxx = @("END")
166
+ 1
167
+ 2
168
+ 3
169
+ 4
170
+ 5
171
+ YYYYY${facts['fqdn']}
172
+ XXXXXXX XXX
173
+ | END
174
+ CODE
175
+ expect(dump(parse(src))).to eq([
176
+ "(= $xxxxxxx (@()",
177
+ " (cat '1", "2", "3", "4", "5",
178
+ "YYYYY' (str (slice $facts 'fqdn')) '",
179
+ "XXXXXXX XXX",
180
+ "')",
181
+ "))"].join("\n"))
182
+ end
183
+
184
+ it "correctly reports an error location in a nested heredoc with margin" do
185
+ # NOTE: Important not to use the left margin feature here - the problem in PUP 9303 is triggered by lines and text before
186
+ # an interpolation containing [].
187
+ src = <<-CODE
188
+ # comment
189
+ # comment
190
+ $xxxxxxx = @("END")
191
+ 1
192
+ 2
193
+ 3
194
+ 4
195
+ 5
196
+ YYYYY${facts]}
197
+ XXXXXXX XXX
198
+ | END
199
+ CODE
200
+ expect{parse(src)}.to raise_error(/Syntax error at '\]' \(line: 9, column: 15\)/)
201
+ end
202
+
203
+ it "correctly reports an error location in a heredoc with line endings escaped" do
204
+ # DO NOT CHANGE INDENTATION OF THIS HEREDOC
205
+ src = <<-CODE
206
+ # line one
207
+ # line two
208
+ @("END"/L)
209
+ First Line\\
210
+ Second Line ${facts]}
211
+ |- END
212
+ CODE
213
+ expect{parse(src)}.to raise_error(/Syntax error at '\]' \(line: 5, column: 24\)/)
214
+ end
215
+
216
+ it "correctly reports an error location in a heredoc with line endings escaped when there is text in the margin" do
217
+ # DO NOT CHANGE INDENTATION OR SPACING OF THIS HEREDOC
218
+ src = <<-CODE
219
+ # line one
220
+ # line two
221
+ @("END"/L)
222
+ First Line\\
223
+ Second Line
224
+ x Third Line ${facts]}
225
+ |- END
226
+ # line 8
227
+ # line 9
228
+ CODE
229
+ expect{parse(src)}.to raise_error(/Syntax error at '\]' \(line: 6, column: 23\)/)
230
+ end
231
+
232
+ it "correctly reports an error location in a heredoc with line endings escaped when there is text in the margin" do
233
+ # DO NOT CHANGE INDENTATION OR SPACING OF THIS HEREDOC
234
+ src = <<-CODE
235
+ @(END)
236
+ AAA
237
+ BBB
238
+ CCC
239
+ DDD
240
+ EEE
241
+ FFF
242
+ |- END
243
+ CODE
244
+ expect(dump(parse(src))).to eq([
245
+ "(@()",
246
+ " 'AAA", # no left space trimmed
247
+ " BBB",
248
+ " CCC",
249
+ " DDD",
250
+ "EEE", # left space trimmed
251
+ " FFF'", # indented one because it is one in from margin marker
252
+ ")"].join("\n"))
253
+ end
254
+
159
255
  it 'parses multiple heredocs on the same line' do
160
256
  src = <<-CODE
161
257
  notice({ @(foo) => @(bar) })
@@ -168,9 +264,9 @@ CODE
168
264
  expect(dump(parse(src))).to eq([
169
265
  '(block',
170
266
  ' (invoke notice ({} ((@()',
171
- ' (sublocated \' hello\')',
267
+ ' \' hello\'',
172
268
  ' ) (@()',
173
- ' (sublocated \' world\')',
269
+ ' \' world\'',
174
270
  ' ))))',
175
271
  ' (invoke notice \'!\')',
176
272
  ')'
@@ -244,6 +244,15 @@ describe 'the type mismatch describer' do
244
244
  expect { eval_and_collect_notices(code) }.to(raise_error(Puppet::Error,
245
245
  /Class\[Test\]: parameter 'opts' expects size to be 1, got 0/))
246
246
  end
247
+
248
+ it "treats Optional as Optional[Any]" do
249
+ code = <<-PUPPET
250
+ class test(Optional $var=undef) {}
251
+ class { 'test': var => 'hello' }
252
+ PUPPET
253
+ expect { eval_and_collect_notices(code) }.not_to raise_error
254
+ end
255
+
247
256
  end
248
257
  end
249
258
  end
@@ -251,7 +251,13 @@ describe Puppet::Type.type(:group).provider(:windows_adsi), :if => Puppet::Util:
251
251
  'user3',
252
252
  ]
253
253
 
254
- expect(provider.members).to match_array([user1.sid, user2.sid, user3.sid])
254
+ expected_member_sids = [user1.sid, user2.sid, user3.sid]
255
+ expected_members = ['user1', 'user2', 'user3']
256
+ provider.stubs(:members_to_s)
257
+ .with(expected_member_sids)
258
+ .returns(expected_members.join(','))
259
+
260
+ expect(provider.members).to match_array(expected_members)
255
261
  end
256
262
 
257
263
  it "should be able to set group members" do
@@ -601,4 +601,30 @@ describe Puppet::Transaction::ResourceHarness do
601
601
  Puppet::Util::Storage.expects(:cache).with(@resource).returns data
602
602
  expect(@harness.cached(@resource, :foo)).to eq("other")
603
603
  end
604
+
605
+ describe "successful event message" do
606
+ let(:test_file) do
607
+ tmpfile('foo').tap do |path|
608
+ File.open(path, 'w') { |fh| fh.write("old contents") }
609
+ end
610
+ end
611
+
612
+ let(:resource) do
613
+ Puppet::Type.type(:file).new(:path => test_file, :backup => false, :content => "hello world")
614
+ end
615
+
616
+ it "contains (corrective) when corrective change" do
617
+ Puppet::Transaction::Event.any_instance.stubs(:corrective_change).returns(true)
618
+ status = @harness.evaluate(resource)
619
+ sync_event = status.events[0]
620
+ expect(sync_event.message).to match(/content changed '{md5}[0-9a-f]+' to '{md5}[0-9a-f]+' \(corrective\)/)
621
+ end
622
+
623
+ it "contains no modifier when intentional change" do
624
+ Puppet::Transaction::Event.any_instance.stubs(:corrective_change).returns(false)
625
+ status = @harness.evaluate(resource)
626
+ sync_event = status.events[0]
627
+ expect(sync_event.message).to match(/content changed '{md5}[0-9a-f]+' to '{md5}[0-9a-f]+'$/)
628
+ end
629
+ end
604
630
  end
@@ -158,7 +158,6 @@ describe Puppet::Util::Execution, if: !Puppet::Util::Platform.jruby? do
158
158
  context 'cwd option' do
159
159
  let(:cwd) { 'cwd' }
160
160
  it "should execute the command in the specified working directory" do
161
- Dir.expects(:chdir).with(cwd).yields
162
161
  Process.expects(:create).with(
163
162
  :command_line => "test command",
164
163
  :startup_info => {
@@ -166,7 +165,8 @@ describe Puppet::Util::Execution, if: !Puppet::Util::Platform.jruby? do
166
165
  :stdout => @stdout,
167
166
  :stderr => @stderr
168
167
  },
169
- :close_handles => false
168
+ :close_handles => false,
169
+ :cwd => cwd
170
170
  )
171
171
 
172
172
  call_exec_windows('test command', { :cwd => cwd }, @stdin, @stdout, @stderr)
@@ -88,6 +88,21 @@ describe Puppet::Util::Log do
88
88
  expect(logs.last.source).to eq(utf_8_msg)
89
89
  end
90
90
 
91
+ require 'puppet/util/log/destinations'
92
+
93
+ it "raises an error when it has no successful logging destinations" do
94
+ # spec_helper.rb redirects log output away from the console,
95
+ # so we have to stop that here, or else the logic we are testing
96
+ # will not be reached.
97
+ Puppet::Util::Log.stubs(:destinations).returns({})
98
+
99
+ our_exception = Puppet::DevError.new("test exception")
100
+ Puppet::FileSystem.expects(:dir).raises(our_exception)
101
+ bad_file = tmpfile("bad_file")
102
+
103
+ expect { Puppet::Util::Log.newdestination(bad_file) }.to raise_error(Puppet::DevError)
104
+ end
105
+
91
106
  describe ".setup_default" do
92
107
  it "should default to :syslog" do
93
108
  Puppet.features.stubs(:syslog?).returns(true)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet/util/pidlock'
5
5
 
6
- describe Puppet::Util::Pidlock do
6
+ describe Puppet::Util::Pidlock, if: !Puppet::Util::Platform.jruby? do
7
7
  require 'puppet_spec/files'
8
8
  include PuppetSpec::Files
9
9
 
@@ -23,6 +23,11 @@ describe Puppet::Util::Pidlock do
23
23
 
24
24
  it "should become locked" do
25
25
  @lock.lock
26
+ if Puppet::Util::Platform.windows?
27
+ Puppet::Util::Windows::Process.stubs(:get_process_image_name_by_pid).with(@lock.lock_pid).returns('C:\Program Files\Puppet Labs\Puppet\puppet\bin\ruby.exe')
28
+ else
29
+ Puppet::Util::Execution.stubs(:execute).with(['ps', '-p', @lock.lock_pid, '-o', 'comm=']).returns('puppet')
30
+ end
26
31
  expect(@lock).to be_locked
27
32
  end
28
33
 
@@ -101,6 +106,11 @@ describe Puppet::Util::Pidlock do
101
106
  describe "#locked?" do
102
107
  it "should return true if locked" do
103
108
  @lock.lock
109
+ if Puppet::Util::Platform.windows?
110
+ Puppet::Util::Windows::Process.stubs(:get_process_image_name_by_pid).with(@lock.lock_pid).returns('C:\Program Files\Puppet Labs\Puppet\puppet\bin\ruby.exe')
111
+ else
112
+ Puppet::Util::Execution.stubs(:execute).with(['ps', '-p', @lock.lock_pid, '-o', 'comm=']).returns('puppet')
113
+ end
104
114
  expect(@lock).to be_locked
105
115
  end
106
116
 
@@ -146,6 +156,11 @@ describe Puppet::Util::Pidlock do
146
156
  end
147
157
 
148
158
  it "should replace with new locks" do
159
+ if Puppet::Util::Platform.windows?
160
+ Puppet::Util::Windows::Process.stubs(:get_process_image_name_by_pid).with(6789).returns('C:\Program Files\Puppet Labs\Puppet\puppet\bin\ruby.exe')
161
+ else
162
+ Puppet::Util::Execution.stubs(:execute).with(['ps', '-p', 6789, '-o', 'comm=']).returns('puppet')
163
+ end
149
164
  @lock.lock
150
165
  expect(Puppet::FileSystem.exist?(@lockfile)).to be_truthy
151
166
  expect(@lock.lock_pid).to eq(6789)
@@ -170,6 +185,11 @@ describe Puppet::Util::Pidlock do
170
185
  before(:each) do
171
186
  # fake our pid to be 1234
172
187
  Process.stubs(:pid).returns(1234)
188
+ if Puppet::Util::Platform.windows?
189
+ Puppet::Util::Windows::Process.stubs(:get_process_image_name_by_pid).with(1234).returns('C:\Program Files\Puppet Labs\Puppet\puppet\bin\ruby.exe')
190
+ else
191
+ Puppet::Util::Execution.stubs(:execute).with(['ps', '-p', 1234, '-o', 'comm=']).returns('puppet')
192
+ end
173
193
  # lock the file
174
194
  @lock.lock
175
195
  # fake our pid to be a different pid, to simulate someone else