spec/bosh/stemcell/builder_command_spec.rb in bosh-stemcell-1.5.0.pre.1209 vs spec/bosh/stemcell/builder_command_spec.rb in bosh-stemcell-1.5.0.pre.1210

- old
+ new

@@ -6,17 +6,21 @@ subject(:stemcell_builder_command) do described_class.new( env, infrastructure_name: infrastructure.name, operating_system_name: operating_system.name, + agent_name: agent_name, release_tarball_path: release_tarball_path, version: version ) end let(:env) { {} } + let(:agent_name) { 'ruby' } + let(:expected_agent_name) { 'ruby' } + let(:infrastructure) do instance_double( 'Bosh::Stemcell::Infrastructure::Vsphere', name: 'vsphere', hypervisor: 'esxi' @@ -30,11 +34,12 @@ before do Infrastructure.stub(:for).with('vsphere').and_return(infrastructure) OperatingSystem.stub(:for).with(operating_system.name).and_return(operating_system) StageCollection.stub(:new).with( infrastructure: infrastructure, - operating_system: operating_system + operating_system: operating_system, + agent_name: agent_name, ).and_return(stage_collection) StageRunner.stub(:new).with( build_path: File.join(root_dir, 'build', 'build'), command_env: 'env ', @@ -60,12 +65,11 @@ end let(:stage_collection) do instance_double( 'Bosh::Stemcell::StageCollection', - operating_system_stages: ['FAKE_OS_STAGES'], - infrastructure_stages: ['FAKE_INFRASTRUCTURE_STAGES'] + all_stages: %w(FAKE_OS_STAGES FAKE_INFRASTRUCTURE_STAGES) ) end let(:stage_runner) { instance_double('Bosh::Stemcell::StageRunner', configure_and_apply: nil) } @@ -95,10 +99,40 @@ FileUtils.mkdir_p(etc_dir) FileUtils.touch(settings_file) end end + context 'when agent_name is nil' do + let(:agent_name) { nil } + let(:expected_agent_name) { 'ruby' } + + it 'uses the correct agent name for the stage collection' do + StageCollection.should_receive(:new).with( + infrastructure: infrastructure, + operating_system: operating_system, + agent_name: expected_agent_name, + ).and_return(stage_collection) + + stemcell_builder_command.build + end + end + + context 'when agent_name is foo' do + let(:agent_name) { 'foo' } + let(:expected_agent_name) { 'foo' } + + it 'uses the correct agent name for the stage collection' do + StageCollection.should_receive(:new).with( + infrastructure: infrastructure, + operating_system: operating_system, + agent_name: expected_agent_name, + ).and_return(stage_collection) + + stemcell_builder_command.build + end + end + describe 'sanitizing the environment' do it 'removes any tgz files from current working directory' do expect { stemcell_builder_command.build }.to change { Dir.glob('*.tgz').size }.to(0) @@ -168,19 +202,18 @@ [ "cd #{File.expand_path('../../..', File.dirname(__FILE__))};", "STEMCELL_IMAGE=#{File.join(root_dir, 'work', 'work', 'fake-root-disk-image.raw')}", 'bundle exec rspec -fd', "spec/stemcells/#{operating_system.name}_spec.rb", + "spec/stemcells/#{agent_name}_agent_spec.rb", "spec/stemcells/#{infrastructure.name}_spec.rb", ].join(' ') end it 'calls #configure_and_apply' do stage_runner.should_receive(:configure_and_apply). - with(['FAKE_OS_STAGES']).ordered - stage_runner.should_receive(:configure_and_apply). - with(['FAKE_INFRASTRUCTURE_STAGES']).ordered + with(%w(FAKE_OS_STAGES FAKE_INFRASTRUCTURE_STAGES)).ordered stemcell_builder_command.should_receive(:system). with(expected_rspec_command).ordered stemcell_builder_command.build end @@ -188,12 +221,10 @@ context 'with CentOS' do let(:operating_system) { instance_double('Bosh::Stemcell::OperatingSystem::Centos', name: 'centos') } it 'calls #configure_and_apply' do stage_runner.should_receive(:configure_and_apply). - with(['FAKE_OS_STAGES']).ordered - stage_runner.should_receive(:configure_and_apply). - with(['FAKE_INFRASTRUCTURE_STAGES']).ordered + with(%w(FAKE_OS_STAGES FAKE_INFRASTRUCTURE_STAGES)).ordered stemcell_builder_command.should_receive(:system). with(expected_rspec_command).ordered stemcell_builder_command.build end