diff options
author | danielsdeleo <dan@opscode.com> | 2013-12-19 15:29:37 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-12-19 15:29:37 -0800 |
commit | 9d5b09026470c322c3cb5ca8a4157c4d2f16cef3 (patch) | |
tree | 25028295729a2362d0cc5a76f930caaca79d1d6a /spec/unit/runner_spec.rb | |
parent | c863cb68bf3a6939fb6489edbb32058e6466b25e (diff) | |
download | ohai-9d5b09026470c322c3cb5ca8a4157c4d2f16cef3.tar.gz |
Explicitly test dependency cycle detection for self-dependency
Diffstat (limited to 'spec/unit/runner_spec.rb')
-rw-r--r-- | spec/unit/runner_spec.rb | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 02602421..a515bdc5 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -293,37 +293,60 @@ describe Ohai::Runner, "run_plugin" do end describe "when a cycle is detected" do - before(:each) do - @ohai = Ohai::System.new - @runner = Ohai::Runner.new(@ohai, true) + let(:ohai) { Ohai::System.new } + let(:runner) { Ohai::Runner.new(ohai, true) } - klass1 = Ohai.plugin(:Thing) { - provides("thing") - depends("other") - collect_data { - thing(other) + context "when there are no edges in the cycle (A->A)" do + let(:plugin_class) do + klass1 = Ohai.plugin(:Thing) do + provides("thing") + depends("thing") + collect_data do + thing(other) + end + end + end + let(:plugin) { plugin_class.new(ohai.data) } + + it "ignores the cycle" do + ohai.provides_map.set_providers_for(plugin, ["thing"]) + + expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other" + runner.run_plugin(plugin) # should not raise + end + + end + + context "when there is one edge in the cycle (A->B and B->A)" do + before(:each) do + klass1 = Ohai.plugin(:Thing) { + provides("thing") + depends("other") + collect_data { + thing(other) + } } - } - klass2 = Ohai.plugin(:Other) { - provides("other") - depends("thing") - collect_data { - other(thing) + klass2 = Ohai.plugin(:Other) { + provides("other") + depends("thing") + collect_data { + other(thing) + } } - } - @plugins = [] - [klass1, klass2].each_with_index do |klass, idx| - @plugins << klass.new(@ohai.data) + @plugins = [] + [klass1, klass2].each_with_index do |klass, idx| + @plugins << klass.new(ohai.data) + end + @plugin1, @plugin2 = @plugins end - @plugin1, @plugin2 = @plugins - end - it "should raise Ohai::Exceptions::DependencyCycle" do - @runner.stub(:fetch_plugins).with(["thing"]).and_return([@plugin1]) - @runner.stub(:fetch_plugins).with(["other"]).and_return([@plugin2]) - expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other" - expect { @runner.run_plugin(@plugin1) }.to raise_error(Ohai::Exceptions::DependencyCycle, expected_error_string) + it "should raise Ohai::Exceptions::DependencyCycle" do + runner.stub(:fetch_plugins).with(["thing"]).and_return([@plugin1]) + runner.stub(:fetch_plugins).with(["other"]).and_return([@plugin2]) + expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other" + expect { runner.run_plugin(@plugin1) }.to raise_error(Ohai::Exceptions::DependencyCycle, expected_error_string) + end end end |