|
24 | 24 | it "constructs tasks as expected when every task has a metadata file with the same name (besides extension)" do
|
25 | 25 | task_files = %w{task1.json task1 task2.json task2.exe task3.json task3.sh}.map { |bn| "#{tasks_path}/#{bn}" }
|
26 | 26 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 27 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
27 | 28 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
28 | 29 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({})
|
29 | 30 |
|
|
52 | 53 | it "constructs tasks as expected when some tasks don't have a metadata file" do
|
53 | 54 | task_files = %w{task1 task2.exe task3.json task3.sh}.map { |bn| "#{tasks_path}/#{bn}" }
|
54 | 55 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 56 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
55 | 57 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({})
|
56 | 58 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
57 | 59 |
|
|
66 | 68 | it "constructs a task as expected when a task has implementations" do
|
67 | 69 | task_files = %w{task1.elf task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
68 | 70 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 71 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
69 | 72 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
70 | 73 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({'implementations' => [{"name" => "task1.sh"}]})
|
71 | 74 |
|
|
78 | 81 | it "constructs a task as expected when task metadata declares additional files" do
|
79 | 82 | task_files = %w{task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
80 | 83 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 84 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
81 | 85 | expect(Puppet::Module::Task).to receive(:find_extra_files).and_return([{'name' => 'mymod/lib/file0.elf', 'path' => "/path/to/file0.elf"}])
|
82 | 86 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
83 | 87 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({'files' => ["mymod/lib/file0.elf"]})
|
|
91 | 95 | it "constructs a task as expected when a task implementation declares additional files" do
|
92 | 96 | task_files = %w{task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
93 | 97 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 98 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
94 | 99 | expect(Puppet::Module::Task).to receive(:find_extra_files).and_return([{'name' => 'mymod/lib/file0.elf', 'path' => "/path/to/file0.elf"}])
|
95 | 100 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
96 | 101 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({'implementations' => [{"name" => "task1.sh", "files" => ["mymod/lib/file0.elf"]}]})
|
|
104 | 109 | it "constructs a task as expected when task metadata and a task implementation both declare additional files" do
|
105 | 110 | task_files = %w{task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
106 | 111 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(task_files)
|
| 112 | + task_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
107 | 113 | expect(Puppet::Module::Task).to receive(:find_extra_files).and_return([
|
108 | 114 | {'name' => 'mymod/lib/file0.elf', 'path' => "/path/to/file0.elf"},
|
109 | 115 | {'name' => 'yourmod/files/file1.txt', 'path' => "/other/path/to/file1.txt"}
|
|
124 | 130 | it "constructs a task as expected when a task has files" do
|
125 | 131 | og_files = %w{task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
126 | 132 | expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files)
|
| 133 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
127 | 134 | expect(File).to receive(:exist?).with(any_args).and_return(true).at_least(:once)
|
128 | 135 |
|
129 | 136 | expect(Puppet::Module).to receive(:find).with(othermod.name, "production").and_return(othermod).at_least(:once)
|
|
139 | 146 | it "fails to load a task if its metadata specifies a non-existent file" do
|
140 | 147 | og_files = %w{task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" }
|
141 | 148 | allow(Dir).to receive(:glob).with(tasks_glob).and_return(og_files)
|
| 149 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
142 | 150 | allow(File).to receive(:exist?).with(any_args).and_return(true)
|
143 | 151 |
|
144 | 152 | expect(Puppet::Module).to receive(:find).with(othermod.name, "production").and_return(nil).at_least(:once)
|
|
149 | 157 | end
|
150 | 158 |
|
151 | 159 | it "finds files whose names (besides extensions) are valid task names" do
|
152 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task task_1 xx_t_a_s_k_2_xx}) |
| 160 | + og_files = %w{task task_1 xx_t_a_s_k_2_xx}.map { |bn| "#{tasks_path}/#{bn}" } |
| 161 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 162 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
153 | 163 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
154 | 164 |
|
155 | 165 | expect(tasks.count).to eq(3)
|
156 | 166 | expect(tasks.map{|t| t.name}).to eq(%w{mymod::task mymod::task_1 mymod::xx_t_a_s_k_2_xx})
|
157 | 167 | end
|
158 | 168 |
|
159 | 169 | it "ignores files that have names (besides extensions) that are not valid task names" do
|
160 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{.nottask.exe .wat !runme _task 2task2furious def_a_task_PSYCH Fake_task not-a-task realtask}) |
| 170 | + og_files = %w{.nottask.exe .wat !runme _task 2task2furious def_a_task_PSYCH Fake_task not-a-task realtask}.map { |bn| "#{tasks_path}/#{bn}" } |
| 171 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 172 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
161 | 173 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
162 | 174 |
|
163 | 175 | expect(tasks.count).to eq(1)
|
164 | 176 | expect(tasks.map{|t| t.name}).to eq(%w{mymod::realtask})
|
165 | 177 | end
|
166 | 178 |
|
167 | 179 | it "ignores files that have names ending in .conf and .md" do
|
168 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{ginuwine_task task.conf readme.md other_task.md}) |
| 180 | + og_files = %w{ginuwine_task task.conf readme.md other_task.md}.map { |bn| "#{tasks_path}/#{bn}" } |
| 181 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 182 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
169 | 183 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
170 | 184 |
|
171 | 185 | expect(tasks.count).to eq(1)
|
172 | 186 | expect(tasks.map{|t| t.name}).to eq(%w{mymod::ginuwine_task})
|
173 | 187 | end
|
174 | 188 |
|
| 189 | + it "ignores files which are not regular files" do |
| 190 | + og_files = %w{foo}.map { |bn| "#{tasks_path}/#{bn}" } |
| 191 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 192 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(false) } |
| 193 | + tasks = Puppet::Module::Task.tasks_in_module(mymod) |
| 194 | + |
| 195 | + expect(tasks.count).to eq(0) |
| 196 | + end |
| 197 | + |
175 | 198 | it "gives the 'init' task a name that is just the module's name" do
|
176 | 199 | expect(Puppet::Module::Task.new(mymod, 'init', ["#{tasks_path}/init.sh"]).name).to eq('mymod')
|
177 | 200 | end
|
178 | 201 |
|
179 | 202 | describe :metadata do
|
180 | 203 | it "loads metadata for a task" do
|
181 | 204 | metadata = {'desciption': 'some info'}
|
182 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.exe task1.json}) |
| 205 | + og_files = %w{task1.exe task1.json}.map { |bn| "#{tasks_path}/#{bn}" } |
| 206 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 207 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
183 | 208 | allow(Puppet::Module::Task).to receive(:read_metadata).and_return(metadata)
|
184 | 209 |
|
185 | 210 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
|
189 | 214 | end
|
190 | 215 |
|
191 | 216 | it 'returns nil for metadata if no file is present' do
|
192 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.exe}) |
| 217 | + og_files = %w{task1.exe}.map { |bn| "#{tasks_path}/#{bn}" } |
| 218 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 219 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
193 | 220 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
194 | 221 |
|
195 | 222 | expect(tasks.count).to eq(1)
|
|
212 | 239 |
|
213 | 240 | describe :validate do
|
214 | 241 | it "validates when there is no metadata" do
|
215 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.exe}) |
| 242 | + og_files = %w{task1.exe}.map { |bn| "#{tasks_path}/#{bn}" } |
| 243 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 244 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
216 | 245 |
|
217 | 246 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
218 | 247 |
|
|
223 | 252 | it "validates when an implementation isn't used" do
|
224 | 253 | metadata = {'desciption' => 'some info',
|
225 | 254 | 'implementations' => [ {"name" => "task1.exe"}, ] }
|
226 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.exe task1.sh task1.json}) |
| 255 | + og_files = %w{task1.exe task1.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" } |
| 256 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 257 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
227 | 258 | allow(Puppet::Module::Task).to receive(:read_metadata).and_return(metadata)
|
228 | 259 |
|
229 | 260 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
|
235 | 266 | it "validates when an implementation is another task" do
|
236 | 267 | metadata = {'desciption' => 'some info',
|
237 | 268 | 'implementations' => [ {"name" => "task2.sh"}, ] }
|
238 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.exe task2.sh task1.json}) |
| 269 | + og_files = %w{task1.exe task2.sh task1.json}.map { |bn| "#{tasks_path}/#{bn}" } |
| 270 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 271 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
239 | 272 | allow(Puppet::Module::Task).to receive(:read_metadata).and_return(metadata)
|
240 | 273 |
|
241 | 274 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
|
245 | 278 | end
|
246 | 279 |
|
247 | 280 | it "fails validation when there is no metadata and multiple task files" do
|
248 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.elf task1.exe task1.json task2.ps1 task2.sh}) |
| 281 | + og_files = %w{task1.elf task1.exe task1.json task2.ps1 task2.sh}.map { |bn| "#{tasks_path}/#{bn}" } |
| 282 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 283 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
249 | 284 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
250 | 285 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({})
|
251 | 286 |
|
|
255 | 290 | end
|
256 | 291 |
|
257 | 292 | it "fails validation when an implementation references a non-existant file" do
|
258 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.elf task1.exe task1.json}) |
| 293 | + og_files = %w{task1.elf task1.exe task1.json}.map { |bn| "#{tasks_path}/#{bn}" } |
| 294 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 295 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
259 | 296 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
260 | 297 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({'implementations' => [ { 'name' => 'task1.sh' } ] })
|
261 | 298 |
|
|
265 | 302 | end
|
266 | 303 |
|
267 | 304 | it 'fails validation when there is metadata but no executable' do
|
268 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.json task2.sh}) |
| 305 | + og_files = %w{task1.json task2.sh}.map { |bn| "#{tasks_path}/#{bn}" } |
| 306 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 307 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
269 | 308 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
270 | 309 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({})
|
271 | 310 |
|
272 | 311 | expect { tasks.find { |t| t.name == 'mymod::task1' }.validate }.to raise_error(Puppet::Module::Task::InvalidTask)
|
273 | 312 | end
|
274 | 313 |
|
275 | 314 | it 'fails validation when the implementations are not an array' do
|
276 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.json task2.sh}) |
| 315 | + og_files = %w{task1.json task2.sh}.map { |bn| "#{tasks_path}/#{bn}" } |
| 316 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 317 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
277 | 318 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
278 | 319 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({"implemenations" => {}})
|
279 | 320 |
|
280 | 321 | expect { tasks.find { |t| t.name == 'mymod::task1' }.validate }.to raise_error(Puppet::Module::Task::InvalidTask)
|
281 | 322 | end
|
282 | 323 |
|
283 | 324 | it 'fails validation when the implementation is json' do
|
284 |
| - expect(Dir).to receive(:glob).with(tasks_glob).and_return(%w{task1.json task1.sh}) |
| 325 | + og_files = %w{task1.json task1.sh}.map { |bn| "#{tasks_path}/#{bn}" } |
| 326 | + expect(Dir).to receive(:glob).with(tasks_glob).and_return(og_files) |
| 327 | + og_files.each { |f| expect(File).to receive(:file?).with(f).and_return(true) } |
285 | 328 | tasks = Puppet::Module::Task.tasks_in_module(mymod)
|
286 | 329 | allow_any_instance_of(Puppet::Module::Task).to receive(:metadata).and_return({'implementations' => [ { 'name' => 'task1.json' } ] })
|
287 | 330 |
|
|
0 commit comments