|
26 | 26 | end
|
27 | 27 | end
|
28 | 28 |
|
| 29 | + context 'with litmus:install_module' do |
| 30 | + let(:args) { { target_node_name: nil, module_repository: nil } } |
| 31 | + let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }, { 'uri' => 'some.otherhost' }] }] } } |
| 32 | + let(:target_nodes) { ['some.host', 'some.otherhost'] } |
| 33 | + let(:dummy_tar) { 'spec/data/doot.tar.gz' } |
| 34 | + |
| 35 | + before do |
| 36 | + Rake::Task['litmus:install_module'].reenable |
| 37 | + allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash) |
| 38 | + allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:find_targets).with(inventory_hash, args[:target_node_name]).and_return(target_nodes) |
| 39 | + end |
| 40 | + |
| 41 | + it 'installs module' do |
| 42 | + expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar) |
| 43 | + expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'") |
| 44 | + |
| 45 | + expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository]) |
| 46 | + expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}") |
| 47 | + |
| 48 | + Rake::Task['litmus:install_module'].invoke(*args.values) |
| 49 | + end |
| 50 | + |
| 51 | + context 'with unknown target' do |
| 52 | + let(:args) { { target_node_name: 'un.known', module_repository: nil } } |
| 53 | + let(:target_nodes) { [] } |
| 54 | + |
| 55 | + it 'exits with No targets found' do |
| 56 | + expect do |
| 57 | + expect($stdout).to receive(:puts).with('No targets found') |
| 58 | + Rake::Task['litmus:install_module'].invoke(*args.values) |
| 59 | + end.to raise_error(SystemExit) { |error| |
| 60 | + expect(error.status).to eq(0) |
| 61 | + } |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'when build_module returns nil' do |
| 66 | + let(:dummy_tar) { nil } |
| 67 | + |
| 68 | + it 'raises error if build fails' do |
| 69 | + expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar) |
| 70 | + expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'") |
| 71 | + |
| 72 | + expect { Rake::Task['litmus:install_module'].invoke(*args.values) } |
| 73 | + .to raise_error(RuntimeError, "Unable to find package in 'pkg/*.tar.gz'") |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + |
29 | 78 | context 'with litmus:install_modules_from_directory' do
|
30 | 79 | let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
|
31 | 80 | let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }
|
|
0 commit comments