diff --git a/lib/puppet_litmus/rake_tasks.rb b/lib/puppet_litmus/rake_tasks.rb index 62c4547a..dcb2fe6a 100644 --- a/lib/puppet_litmus/rake_tasks.rb +++ b/lib/puppet_litmus/rake_tasks.rb @@ -210,9 +210,9 @@ # module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) } raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil? - install_module(inventory_hash, args[:target_node_name], module_tar, args[:module_repository]) + install_module(inventory_hash, target_nodes, module_tar, args[:module_repository]) - puts "Installed '#{module_tar}' on #{args[:target_node_name]}" + puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}" end # Install the puppet modules from a source directory to nodes. It does not install dependencies. @@ -241,10 +241,8 @@ include BoltSpec::Run module_tars.each do |module_tar| puts "Installing '#{module_tar}'" - target_nodes.each do |target_node_name| - install_module(inventory_hash, target_node_name, module_tar, args[:module_repository], args[:ignore_dependencies]) - puts "Installed '#{module_tar}' on #{target_node_name}" - end + install_module(inventory_hash, target_nodes, module_tar, args[:module_repository], args[:ignore_dependencies]) + puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}" end end diff --git a/spec/lib/puppet_litmus/rake_tasks_spec.rb b/spec/lib/puppet_litmus/rake_tasks_spec.rb index cad91179..313ad48e 100644 --- a/spec/lib/puppet_litmus/rake_tasks_spec.rb +++ b/spec/lib/puppet_litmus/rake_tasks_spec.rb @@ -26,6 +26,55 @@ end end + context 'with litmus:install_module' do + let(:args) { { target_node_name: nil, module_repository: nil } } + let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }, { 'uri' => 'some.otherhost' }] }] } } + let(:target_nodes) { ['some.host', 'some.otherhost'] } + let(:dummy_tar) { 'spec/data/doot.tar.gz' } + + before do + Rake::Task['litmus:install_module'].reenable + allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash) + allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:find_targets).with(inventory_hash, args[:target_node_name]).and_return(target_nodes) + end + + it 'installs module' do + expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar) + expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'") + + expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository]) + expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}") + + Rake::Task['litmus:install_module'].invoke(*args.values) + end + + context 'with unknown target' do + let(:args) { { target_node_name: 'un.known', module_repository: nil } } + let(:target_nodes) { [] } + + it 'exits with No targets found' do + expect do + expect($stdout).to receive(:puts).with('No targets found') + Rake::Task['litmus:install_module'].invoke(*args.values) + end.to raise_error(SystemExit) { |error| + expect(error.status).to eq(0) + } + end + end + + context 'when build_module returns nil' do + let(:dummy_tar) { nil } + + it 'raises error if build fails' do + expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar) + expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'") + + expect { Rake::Task['litmus:install_module'].invoke(*args.values) } + .to raise_error(RuntimeError, "Unable to find package in 'pkg/*.tar.gz'") + end + end + end + context 'with litmus:install_modules_from_directory' do let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } } let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') } diff --git a/spec/lib/puppet_litmus/util_spec.rb b/spec/lib/puppet_litmus/util_spec.rb index dfefc28b..964303e5 100644 --- a/spec/lib/puppet_litmus/util_spec.rb +++ b/spec/lib/puppet_litmus/util_spec.rb @@ -5,11 +5,12 @@ RSpec.describe PuppetLitmus::Util do context 'when using interpolate_powershell' do + let(:command) { 'foo' } + let(:encoded) { Base64.strict_encode64(command.encode('UTF-16LE')) } + it 'interpolates the command' do - expect(described_class.interpolate_powershell('foo')).to match(/powershell\.exe/) - expect(described_class.interpolate_powershell('foo')).to match(/NoProfile/) - expect(described_class.interpolate_powershell('foo')).to match(/EncodedCommand/) - expect(described_class.interpolate_powershell('foo')).not_to match(/foo/) + expect(described_class.interpolate_powershell(command)).to eql("powershell.exe -NoProfile -EncodedCommand #{encoded}") + expect(described_class.interpolate_powershell(command)).not_to match(/#{command}/) end end end