|
21 | 21 | describe LogStash::PluginManager::Update do
|
22 | 22 | let(:cmd) { LogStash::PluginManager::Update.new("update") }
|
23 | 23 | let(:sources) { cmd.gemfile.gemset.sources }
|
| 24 | + let(:expect_preflight_error) { false } # hack to bypass before-hook expectations |
24 | 25 |
|
25 | 26 | before(:each) do
|
26 |
| - expect(cmd).to receive(:find_latest_gem_specs).and_return({}) |
27 |
| - allow(cmd).to receive(:warn_local_gems).and_return(nil) |
28 |
| - expect(cmd).to receive(:display_updated_plugins).and_return(nil) |
| 27 | + unless expect_preflight_error |
| 28 | + expect(cmd).to receive(:find_latest_gem_specs).and_return({}) |
| 29 | + allow(cmd).to receive(:warn_local_gems).and_return(nil) |
| 30 | + expect(cmd).to receive(:display_updated_plugins).and_return(nil) |
| 31 | + end |
29 | 32 | end
|
30 | 33 |
|
31 | 34 | it "pass all gem sources to the bundle update command" do
|
32 | 35 | sources = cmd.gemfile.gemset.sources
|
33 | 36 | expect_any_instance_of(LogStash::Bundler).to receive(:invoke!).with(
|
34 |
| - :update => [], :rubygems_source => sources, |
35 |
| - :conservative => true, :local => false |
| 37 | + :update => [], |
| 38 | + :rubygems_source => sources, |
| 39 | + :conservative => true, |
| 40 | + :local => false, |
| 41 | + :level => "minor" # default |
36 | 42 | )
|
37 | 43 | cmd.execute
|
38 | 44 | end
|
|
46 | 52 | expect(cmd.gemfile).to receive(:save).and_return(nil)
|
47 | 53 | expect(cmd).to receive(:plugins_to_update).and_return([plugin])
|
48 | 54 | expect_any_instance_of(LogStash::Bundler).to receive(:invoke!).with(
|
49 |
| - hash_including(:update => [plugin], :rubygems_source => sources) |
| 55 | + hash_including(:update => [plugin], :rubygems_source => sources, :level => "minor") |
50 | 56 | ).and_return(nil)
|
51 | 57 | end
|
52 | 58 |
|
53 | 59 | it "skips version verification when ask for it" do
|
54 |
| - cmd.verify = false |
55 | 60 | expect(cmd).to_not receive(:validates_version)
|
56 |
| - cmd.execute |
| 61 | + cmd.run(["--no-verify"]) |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context "with explicit `--level` flag" do |
| 66 | + LogStash::PluginManager::Update::SUPPORTED_LEVELS.each do |level| |
| 67 | + context "with --level=#{level} (valid)" do |
| 68 | + let(:requested_level) { level } |
| 69 | + |
| 70 | + let(:cmd) { LogStash::PluginManager::Update.new("update") } |
| 71 | + let(:plugin) { OpenStruct.new(:name => "dummy", :options => {}) } |
| 72 | + |
| 73 | + before(:each) do |
| 74 | + cmd.verify = false |
| 75 | + end |
| 76 | + |
| 77 | + it "propagates the level flag as an option to Bundler#invoke!" do |
| 78 | + expect(cmd.gemfile).to receive(:find).with(plugin).and_return(plugin) |
| 79 | + expect(cmd.gemfile).to receive(:save).and_return(nil) |
| 80 | + expect(cmd).to receive(:plugins_to_update).and_return([plugin]) |
| 81 | + expect_any_instance_of(LogStash::Bundler).to receive(:invoke!).with( |
| 82 | + hash_including(:update => [plugin], :rubygems_source => sources, :level => requested_level) |
| 83 | + ).and_return(nil) |
| 84 | + |
| 85 | + cmd.run(["--level=#{requested_level}"]) |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + context "with --level=eVeRyThInG (invalid)" do |
| 91 | + let(:requested_level) { "eVeRyThInG" } |
| 92 | + let(:expect_preflight_error) { true } |
| 93 | + |
| 94 | + let(:cmd) { LogStash::PluginManager::Update.new("update") } |
| 95 | + let(:plugin) { OpenStruct.new(:name => "dummy", :options => {}) } |
| 96 | + |
| 97 | + it "errors helpfully" do |
| 98 | + expect { cmd.run(["--level=#{requested_level}"]) } |
| 99 | + .to raise_error.with_message(including("unsupported level `#{requested_level}`")) |
| 100 | + end |
57 | 101 | end
|
58 | 102 | end
|
59 | 103 | end
|
0 commit comments