1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
|
require 'spec_helper'
describe Puppet::Type.type(:cron), :unless => Puppet.features.microsoft_windows? do
let(:simple_provider) do
@provider_class = described_class.provide(:simple) { mk_resource_methods }
allow(@provider_class).to receive(:suitable?).and_return(true)
@provider_class
end
before :each do
allow(described_class).to receive(:defaultprovider).and_return(@provider_class)
end
after :each do
described_class.unprovide(:simple)
end
it "should have :name be its namevar" do
expect(described_class.key_attributes).to eq([:name])
end
describe "when validating attributes" do
[:name, :provider].each do |param|
it "should have a #{param} parameter" do
expect(described_class.attrtype(param)).to eq(:param)
end
end
[:command, :special, :minute, :hour, :weekday, :month, :monthday, :environment, :user, :target].each do |property|
it "should have a #{property} property" do
expect(described_class.attrtype(property)).to eq(:property)
end
end
[:command, :minute, :hour, :weekday, :month, :monthday].each do |cronparam|
it "should have #{cronparam} of type CronParam" do
expect(described_class.attrclass(cronparam).ancestors).to include CronParam
end
end
end
describe "when validating values" do
describe "ensure" do
it "should support present as a value for ensure" do
expect { described_class.new(:name => 'foo', :ensure => :present) }.to_not raise_error
end
it "should support absent as a value for ensure" do
expect { described_class.new(:name => 'foo', :ensure => :present) }.to_not raise_error
end
it "should not support other values" do
expect { described_class.new(:name => 'foo', :ensure => :foo) }.to raise_error(Puppet::Error, /Invalid value/)
end
end
describe "command" do
it "should discard leading spaces" do
expect(described_class.new(:name => 'foo', :command => " /bin/true")[:command]).not_to match Regexp.new(" ")
end
it "should discard trailing spaces" do
expect(described_class.new(:name => 'foo', :command => "/bin/true ")[:command]).not_to match Regexp.new(" ")
end
end
describe "minute" do
it "should support absent" do
expect { described_class.new(:name => 'foo', :minute => 'absent') }.to_not raise_error
end
it "should support *" do
expect { described_class.new(:name => 'foo', :minute => '*') }.to_not raise_error
end
it "should translate absent to :absent" do
expect(described_class.new(:name => 'foo', :minute => 'absent')[:minute]).to eq(:absent)
end
it "should translate * to :absent" do
expect(described_class.new(:name => 'foo', :minute => '*')[:minute]).to eq(:absent)
end
it "should support valid single values" do
expect { described_class.new(:name => 'foo', :minute => '0') }.to_not raise_error
expect { described_class.new(:name => 'foo', :minute => '1') }.to_not raise_error
expect { described_class.new(:name => 'foo', :minute => '59') }.to_not raise_error
end
it "should not support non numeric characters" do
expect { described_class.new(:name => 'foo', :minute => 'z59') }.to raise_error(Puppet::Error, /z59 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '5z9') }.to raise_error(Puppet::Error, /5z9 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '59z') }.to raise_error(Puppet::Error, /59z is not a valid minute/)
end
it "should not support single values out of range" do
expect { described_class.new(:name => 'foo', :minute => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '60') }.to raise_error(Puppet::Error, /60 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '61') }.to raise_error(Puppet::Error, /61 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '120') }.to raise_error(Puppet::Error, /120 is not a valid minute/)
end
it "should support valid multiple values" do
expect { described_class.new(:name => 'foo', :minute => ['0','1','59'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :minute => ['40','30','20'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :minute => ['10','30','20'] ) }.to_not raise_error
end
it "should not support multiple values if at least one is invalid" do
# one invalid
expect { described_class.new(:name => 'foo', :minute => ['0','1','60'] ) }.to raise_error(Puppet::Error, /60 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => ['0','120','59'] ) }.to raise_error(Puppet::Error, /120 is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => ['-1','1','59'] ) }.to raise_error(Puppet::Error, /-1 is not a valid minute/)
# two invalid
expect { described_class.new(:name => 'foo', :minute => ['0','61','62'] ) }.to raise_error(Puppet::Error, /(61|62) is not a valid minute/)
# all invalid
expect { described_class.new(:name => 'foo', :minute => ['-1','61','62'] ) }.to raise_error(Puppet::Error, /(-1|61|62) is not a valid minute/)
end
it "should support valid step syntax" do
expect { described_class.new(:name => 'foo', :minute => '*/2' ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :minute => '10-16/2' ) }.to_not raise_error
end
it "should not support invalid steps" do
expect { described_class.new(:name => 'foo', :minute => '*/A' ) }.to raise_error(Puppet::Error, /\*\/A is not a valid minute/)
expect { described_class.new(:name => 'foo', :minute => '*/2A' ) }.to raise_error(Puppet::Error, /\*\/2A is not a valid minute/)
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :minute => '*/120' ) }.to raise_error(Puppet::Error, /is not a valid minute/)
end
end
describe "hour" do
it "should support absent" do
expect { described_class.new(:name => 'foo', :hour => 'absent') }.to_not raise_error
end
it "should support *" do
expect { described_class.new(:name => 'foo', :hour => '*') }.to_not raise_error
end
it "should translate absent to :absent" do
expect(described_class.new(:name => 'foo', :hour => 'absent')[:hour]).to eq(:absent)
end
it "should translate * to :absent" do
expect(described_class.new(:name => 'foo', :hour => '*')[:hour]).to eq(:absent)
end
it "should support valid single values" do
expect { described_class.new(:name => 'foo', :hour => '0') }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => '11') }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => '12') }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => '13') }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => '23') }.to_not raise_error
end
it "should not support non numeric characters" do
expect { described_class.new(:name => 'foo', :hour => 'z15') }.to raise_error(Puppet::Error, /z15 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => '1z5') }.to raise_error(Puppet::Error, /1z5 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => '15z') }.to raise_error(Puppet::Error, /15z is not a valid hour/)
end
it "should not support single values out of range" do
expect { described_class.new(:name => 'foo', :hour => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => '24') }.to raise_error(Puppet::Error, /24 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => '120') }.to raise_error(Puppet::Error, /120 is not a valid hour/)
end
it "should support valid multiple values" do
expect { described_class.new(:name => 'foo', :hour => ['0','1','23'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => ['5','16','14'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => ['16','13','9'] ) }.to_not raise_error
end
it "should not support multiple values if at least one is invalid" do
# one invalid
expect { described_class.new(:name => 'foo', :hour => ['0','1','24'] ) }.to raise_error(Puppet::Error, /24 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => ['0','-1','5'] ) }.to raise_error(Puppet::Error, /-1 is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => ['-1','1','23'] ) }.to raise_error(Puppet::Error, /-1 is not a valid hour/)
# two invalid
expect { described_class.new(:name => 'foo', :hour => ['0','25','26'] ) }.to raise_error(Puppet::Error, /(25|26) is not a valid hour/)
# all invalid
expect { described_class.new(:name => 'foo', :hour => ['-1','24','120'] ) }.to raise_error(Puppet::Error, /(-1|24|120) is not a valid hour/)
end
it "should support valid step syntax" do
expect { described_class.new(:name => 'foo', :hour => '*/2' ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :hour => '10-18/4' ) }.to_not raise_error
end
it "should not support invalid steps" do
expect { described_class.new(:name => 'foo', :hour => '*/A' ) }.to raise_error(Puppet::Error, /\*\/A is not a valid hour/)
expect { described_class.new(:name => 'foo', :hour => '*/2A' ) }.to raise_error(Puppet::Error, /\*\/2A is not a valid hour/)
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :hour => '*/26' ) }.to raise_error(Puppet::Error, /is not a valid hour/)
end
end
describe "weekday" do
it "should support absent" do
expect { described_class.new(:name => 'foo', :weekday => 'absent') }.to_not raise_error
end
it "should support *" do
expect { described_class.new(:name => 'foo', :weekday => '*') }.to_not raise_error
end
it "should translate absent to :absent" do
expect(described_class.new(:name => 'foo', :weekday => 'absent')[:weekday]).to eq(:absent)
end
it "should translate * to :absent" do
expect(described_class.new(:name => 'foo', :weekday => '*')[:weekday]).to eq(:absent)
end
it "should support valid numeric weekdays" do
expect { described_class.new(:name => 'foo', :weekday => '0') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => '1') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => '6') }.to_not raise_error
# According to http://www.manpagez.com/man/5/crontab 7 is also valid (Sunday)
expect { described_class.new(:name => 'foo', :weekday => '7') }.to_not raise_error
end
it "should support valid weekdays as words (long version)" do
expect { described_class.new(:name => 'foo', :weekday => 'Monday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Tuesday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Wednesday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Thursday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Friday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Saturday') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Sunday') }.to_not raise_error
end
it "should support valid weekdays as words (3 character version)" do
expect { described_class.new(:name => 'foo', :weekday => 'Mon') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Tue') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Wed') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Thu') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Fri') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Sat') }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => 'Sun') }.to_not raise_error
end
it "should not support numeric values out of range" do
expect { described_class.new(:name => 'foo', :weekday => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid weekday/)
expect { described_class.new(:name => 'foo', :weekday => '8') }.to raise_error(Puppet::Error, /8 is not a valid weekday/)
end
it "should not support invalid weekday names" do
expect { described_class.new(:name => 'foo', :weekday => 'Sar') }.to raise_error(Puppet::Error, /Sar is not a valid weekday/)
end
it "should support valid multiple values" do
expect { described_class.new(:name => 'foo', :weekday => ['0','1','6'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => ['Mon','Wed','Friday'] ) }.to_not raise_error
end
it "should not support multiple values if at least one is invalid" do
# one invalid
expect { described_class.new(:name => 'foo', :weekday => ['0','1','8'] ) }.to raise_error(Puppet::Error, /8 is not a valid weekday/)
expect { described_class.new(:name => 'foo', :weekday => ['Mon','Fii','Sat'] ) }.to raise_error(Puppet::Error, /Fii is not a valid weekday/)
# two invalid
expect { described_class.new(:name => 'foo', :weekday => ['Mos','Fii','Sat'] ) }.to raise_error(Puppet::Error, /(Mos|Fii) is not a valid weekday/)
# all invalid
expect { described_class.new(:name => 'foo', :weekday => ['Mos','Fii','Saa'] ) }.to raise_error(Puppet::Error, /(Mos|Fii|Saa) is not a valid weekday/)
expect { described_class.new(:name => 'foo', :weekday => ['-1','8','11'] ) }.to raise_error(Puppet::Error, /(-1|8|11) is not a valid weekday/)
end
it "should support valid step syntax" do
expect { described_class.new(:name => 'foo', :weekday => '*/2' ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :weekday => '0-4/2' ) }.to_not raise_error
end
it "should not support invalid steps" do
expect { described_class.new(:name => 'foo', :weekday => '*/A' ) }.to raise_error(Puppet::Error, /\*\/A is not a valid weekday/)
expect { described_class.new(:name => 'foo', :weekday => '*/2A' ) }.to raise_error(Puppet::Error, /\*\/2A is not a valid weekday/)
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :weekday => '*/9' ) }.to raise_error(Puppet::Error, /is not a valid weekday/)
end
end
describe "month" do
it "should support absent" do
expect { described_class.new(:name => 'foo', :month => 'absent') }.to_not raise_error
end
it "should support *" do
expect { described_class.new(:name => 'foo', :month => '*') }.to_not raise_error
end
it "should translate absent to :absent" do
expect(described_class.new(:name => 'foo', :month => 'absent')[:month]).to eq(:absent)
end
it "should translate * to :absent" do
expect(described_class.new(:name => 'foo', :month => '*')[:month]).to eq(:absent)
end
it "should support valid numeric values" do
expect { described_class.new(:name => 'foo', :month => '1') }.to_not raise_error
expect { described_class.new(:name => 'foo', :month => '12') }.to_not raise_error
end
it "should support valid months as words" do
expect( described_class.new(:name => 'foo', :month => 'January')[:month] ).to eq(['1'])
expect( described_class.new(:name => 'foo', :month => 'February')[:month] ).to eq(['2'])
expect( described_class.new(:name => 'foo', :month => 'March')[:month] ).to eq(['3'])
expect( described_class.new(:name => 'foo', :month => 'April')[:month] ).to eq(['4'])
expect( described_class.new(:name => 'foo', :month => 'May')[:month] ).to eq(['5'])
expect( described_class.new(:name => 'foo', :month => 'June')[:month] ).to eq(['6'])
expect( described_class.new(:name => 'foo', :month => 'July')[:month] ).to eq(['7'])
expect( described_class.new(:name => 'foo', :month => 'August')[:month] ).to eq(['8'])
expect( described_class.new(:name => 'foo', :month => 'September')[:month] ).to eq(['9'])
expect( described_class.new(:name => 'foo', :month => 'October')[:month] ).to eq(['10'])
expect( described_class.new(:name => 'foo', :month => 'November')[:month] ).to eq(['11'])
expect( described_class.new(:name => 'foo', :month => 'December')[:month] ).to eq(['12'])
end
it "should support valid months as words (3 character short version)" do
expect( described_class.new(:name => 'foo', :month => 'Jan')[:month] ).to eq(['1'])
expect( described_class.new(:name => 'foo', :month => 'Feb')[:month] ).to eq(['2'])
expect( described_class.new(:name => 'foo', :month => 'Mar')[:month] ).to eq(['3'])
expect( described_class.new(:name => 'foo', :month => 'Apr')[:month] ).to eq(['4'])
expect( described_class.new(:name => 'foo', :month => 'May')[:month] ).to eq(['5'])
expect( described_class.new(:name => 'foo', :month => 'Jun')[:month] ).to eq(['6'])
expect( described_class.new(:name => 'foo', :month => 'Jul')[:month] ).to eq(['7'])
expect( described_class.new(:name => 'foo', :month => 'Aug')[:month] ).to eq(['8'])
expect( described_class.new(:name => 'foo', :month => 'Sep')[:month] ).to eq(['9'])
expect( described_class.new(:name => 'foo', :month => 'Oct')[:month] ).to eq(['10'])
expect( described_class.new(:name => 'foo', :month => 'Nov')[:month] ).to eq(['11'])
expect( described_class.new(:name => 'foo', :month => 'Dec')[:month] ).to eq(['12'])
end
it "should not support numeric values out of range" do
expect { described_class.new(:name => 'foo', :month => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '0') }.to raise_error(Puppet::Error, /0 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '13') }.to raise_error(Puppet::Error, /13 is not a valid month/)
end
it "should not support words that are not valid months" do
expect { described_class.new(:name => 'foo', :month => 'Jal') }.to raise_error(Puppet::Error, /Jal is not a valid month/)
end
it "should not support single values out of range" do
expect { described_class.new(:name => 'foo', :month => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '60') }.to raise_error(Puppet::Error, /60 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '61') }.to raise_error(Puppet::Error, /61 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '120') }.to raise_error(Puppet::Error, /120 is not a valid month/)
end
it "should support valid multiple values" do
expect { described_class.new(:name => 'foo', :month => ['1','9','12'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :month => ['Jan','March','Jul'] ) }.to_not raise_error
end
it "should not support multiple values if at least one is invalid" do
# one invalid
expect { described_class.new(:name => 'foo', :month => ['0','1','12'] ) }.to raise_error(Puppet::Error, /0 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => ['1','13','10'] ) }.to raise_error(Puppet::Error, /13 is not a valid month/)
expect { described_class.new(:name => 'foo', :month => ['Jan','Feb','Jxx'] ) }.to raise_error(Puppet::Error, /Jxx is not a valid month/)
# two invalid
expect { described_class.new(:name => 'foo', :month => ['Jan','Fex','Jux'] ) }.to raise_error(Puppet::Error, /(Fex|Jux) is not a valid month/)
# all invalid
expect { described_class.new(:name => 'foo', :month => ['-1','0','13'] ) }.to raise_error(Puppet::Error, /(-1|0|13) is not a valid month/)
expect { described_class.new(:name => 'foo', :month => ['Jax','Fex','Aux'] ) }.to raise_error(Puppet::Error, /(Jax|Fex|Aux) is not a valid month/)
end
it "should support valid step syntax" do
expect { described_class.new(:name => 'foo', :month => '*/2' ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :month => '1-12/3' ) }.to_not raise_error
end
it "should not support invalid steps" do
expect { described_class.new(:name => 'foo', :month => '*/A' ) }.to raise_error(Puppet::Error, /\*\/A is not a valid month/)
expect { described_class.new(:name => 'foo', :month => '*/2A' ) }.to raise_error(Puppet::Error, /\*\/2A is not a valid month/)
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :month => '*/13' ) }.to raise_error(Puppet::Error, /is not a valid month/)
end
end
describe "monthday" do
it "should support absent" do
expect { described_class.new(:name => 'foo', :monthday => 'absent') }.to_not raise_error
end
it "should support *" do
expect { described_class.new(:name => 'foo', :monthday => '*') }.to_not raise_error
end
it "should translate absent to :absent" do
expect(described_class.new(:name => 'foo', :monthday => 'absent')[:monthday]).to eq(:absent)
end
it "should translate * to :absent" do
expect(described_class.new(:name => 'foo', :monthday => '*')[:monthday]).to eq(:absent)
end
it "should support valid single values" do
expect { described_class.new(:name => 'foo', :monthday => '1') }.to_not raise_error
expect { described_class.new(:name => 'foo', :monthday => '30') }.to_not raise_error
expect { described_class.new(:name => 'foo', :monthday => '31') }.to_not raise_error
end
it "should not support non numeric characters" do
expect { described_class.new(:name => 'foo', :monthday => 'z23') }.to raise_error(Puppet::Error, /z23 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => '2z3') }.to raise_error(Puppet::Error, /2z3 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => '23z') }.to raise_error(Puppet::Error, /23z is not a valid monthday/)
end
it "should not support single values out of range" do
expect { described_class.new(:name => 'foo', :monthday => '-1') }.to raise_error(Puppet::Error, /-1 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => '0') }.to raise_error(Puppet::Error, /0 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => '32') }.to raise_error(Puppet::Error, /32 is not a valid monthday/)
end
it "should support valid multiple values" do
expect { described_class.new(:name => 'foo', :monthday => ['1','23','31'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :monthday => ['31','23','1'] ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :monthday => ['1','31','23'] ) }.to_not raise_error
end
it "should not support multiple values if at least one is invalid" do
# one invalid
expect { described_class.new(:name => 'foo', :monthday => ['1','23','32'] ) }.to raise_error(Puppet::Error, /32 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => ['-1','12','23'] ) }.to raise_error(Puppet::Error, /-1 is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => ['13','32','30'] ) }.to raise_error(Puppet::Error, /32 is not a valid monthday/)
# two invalid
expect { described_class.new(:name => 'foo', :monthday => ['-1','0','23'] ) }.to raise_error(Puppet::Error, /(-1|0) is not a valid monthday/)
# all invalid
expect { described_class.new(:name => 'foo', :monthday => ['-1','0','32'] ) }.to raise_error(Puppet::Error, /(-1|0|32) is not a valid monthday/)
end
it "should support valid step syntax" do
expect { described_class.new(:name => 'foo', :monthday => '*/2' ) }.to_not raise_error
expect { described_class.new(:name => 'foo', :monthday => '10-16/2' ) }.to_not raise_error
end
it "should not support invalid steps" do
expect { described_class.new(:name => 'foo', :monthday => '*/A' ) }.to raise_error(Puppet::Error, /\*\/A is not a valid monthday/)
expect { described_class.new(:name => 'foo', :monthday => '*/2A' ) }.to raise_error(Puppet::Error, /\*\/2A is not a valid monthday/)
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :monthday => '*/32' ) }.to raise_error(Puppet::Error, /is not a valid monthday/)
end
end
describe "special" do
%w(reboot yearly annually monthly weekly daily midnight hourly).each do |value|
it "should support the value '#{value}'" do
expect { described_class.new(:name => 'foo', :special => value ) }.to_not raise_error
end
end
context "when combined with numeric schedule fields" do
context "which are 'absent'" do
[ %w(reboot yearly annually monthly weekly daily midnight hourly), :absent ].flatten.each { |value|
it "should accept the value '#{value}' for special" do
expect {
described_class.new(:name => 'foo', :minute => :absent, :special => value )
}.to_not raise_error
end
}
end
context "which are not absent" do
%w(reboot yearly annually monthly weekly daily midnight hourly).each { |value|
it "should not accept the value '#{value}' for special" do
expect {
described_class.new(:name => 'foo', :minute => "1", :special => value )
}.to raise_error(Puppet::Error, /cannot specify both a special schedule and a value/)
end
}
it "should accept the 'absent' value for special" do
expect {
described_class.new(:name => 'foo', :minute => "1", :special => :absent )
}.to_not raise_error
end
end
end
end
describe "environment" do
it "it should accept an :environment that looks like a path" do
expect do
described_class.new(:name => 'foo',:environment => 'PATH=/bin:/usr/bin:/usr/sbin')
end.to_not raise_error
end
it "should not accept environment variables that do not contain '='" do
expect do
described_class.new(:name => 'foo',:environment => 'INVALID')
end.to raise_error(Puppet::Error, /Invalid environment setting "INVALID"/)
end
it "should accept empty environment variables that do not contain '='" do
expect do
described_class.new(:name => 'foo',:environment => 'MAILTO=')
end.to_not raise_error
end
it "should accept 'absent'" do
expect do
described_class.new(:name => 'foo',:environment => 'absent')
end.to_not raise_error
end
end
end
describe "when autorequiring resources" do
before :each do
@user_bob = Puppet::Type.type(:user).new(:name => 'bob', :ensure => :present)
@user_alice = Puppet::Type.type(:user).new(:name => 'alice', :ensure => :present)
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource @user_bob, @user_alice
end
it "should autorequire the user" do
@resource = described_class.new(:name => 'dummy', :command => '/usr/bin/uptime', :user => 'alice')
@catalog.add_resource @resource
req = @resource.autorequire
expect(req.size).to eq(1)
expect(req[0].target).to eq(@resource)
expect(req[0].source).to eq(@user_alice)
end
end
it "should not require a command when removing an entry" do
entry = described_class.new(:name => "test_entry", :ensure => :absent)
expect(entry.value(:command)).to eq(nil)
end
it "should default to user => root if Etc.getpwuid(Process.uid) returns nil (#12357)" do
expect(Etc).to receive(:getpwuid).and_return(nil)
entry = described_class.new(:name => "test_entry", :ensure => :present)
expect(entry.value(:user)).to eql "root"
end
end
|