|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'json' |
| 4 | +require 'ostruct' |
4 | 5 |
|
5 | 6 | require_relative '../spec_helper' |
6 | 7 |
|
|
375 | 376 | expect { obj.send(:cleanup_checkout_dir, dir, logger) }.not_to raise_error |
376 | 377 | end |
377 | 378 | end |
| 379 | + |
| 380 | + describe '#assert_that_puppet_environment_directory_exists' do |
| 381 | + before(:each) do |
| 382 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/yup').and_return(true) |
| 383 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/nope').and_return(false) |
| 384 | + end |
| 385 | + |
| 386 | + context 'when preserve_environments is set' do |
| 387 | + context 'and environment is specified' do |
| 388 | + it 'should return without raising error when directory exists' do |
| 389 | + described_object = described_class.allocate |
| 390 | + described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'yup') |
| 391 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 392 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error |
| 393 | + end |
| 394 | + |
| 395 | + it 'should raise Errno::ENOENT when directory does not exist' do |
| 396 | + described_object = described_class.allocate |
| 397 | + described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'nope') |
| 398 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 399 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT) |
| 400 | + end |
| 401 | + end |
| 402 | + |
| 403 | + context 'and environment is not specified' do |
| 404 | + it 'should return without raising error when directory exists' do |
| 405 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true) |
| 406 | + described_object = described_class.allocate |
| 407 | + described_object.instance_variable_set('@opts', preserve_environments: true) |
| 408 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 409 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error |
| 410 | + end |
| 411 | + |
| 412 | + it 'should raise Errno::ENOENT when directory does not exist' do |
| 413 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false) |
| 414 | + described_object = described_class.allocate |
| 415 | + described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'nope') |
| 416 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 417 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT) |
| 418 | + end |
| 419 | + end |
| 420 | + end |
| 421 | + |
| 422 | + context 'when preserve_environments is not set' do |
| 423 | + context 'and environment is specified' do |
| 424 | + it 'should return without raising error when directory exists' do |
| 425 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true) |
| 426 | + described_object = described_class.allocate |
| 427 | + described_object.instance_variable_set('@opts', environment: 'nope') |
| 428 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 429 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error |
| 430 | + end |
| 431 | + |
| 432 | + it 'should raise Errno::ENOENT when directory does not exist' do |
| 433 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false) |
| 434 | + described_object = described_class.allocate |
| 435 | + described_object.instance_variable_set('@opts', environment: 'yup') |
| 436 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 437 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT) |
| 438 | + end |
| 439 | + end |
| 440 | + |
| 441 | + context 'and environment is not specified' do |
| 442 | + it 'should return without raising error when directory exists' do |
| 443 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true) |
| 444 | + described_object = described_class.allocate |
| 445 | + described_object.instance_variable_set('@opts', {}) |
| 446 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 447 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error |
| 448 | + end |
| 449 | + |
| 450 | + it 'should raise Errno::ENOENT when directory does not exist' do |
| 451 | + allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false) |
| 452 | + described_object = described_class.allocate |
| 453 | + described_object.instance_variable_set('@opts', {}) |
| 454 | + described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert')) |
| 455 | + expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT) |
| 456 | + end |
| 457 | + end |
| 458 | + end |
| 459 | + end |
378 | 460 | end |
0 commit comments