Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load collect_data() even if we've already seen it #1224

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/ohai/dsl/plugin/versionvii.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ def self.optional?
# @param block [block] the actual code to collect data for the specified platforms
def self.collect_data(platform = :default, *other_platforms, &block)
[platform, other_platforms].flatten.each do |plat|
if data_collector.key?(plat)
raise Ohai::Exceptions::IllegalPluginDefinition, "collect_data already defined on platform #{plat}"
else
data_collector[plat] = block
end
Ohai::Log.warn("collect_data already defined on platform '#{plat}' for #{self}, last plugin seen will be used") if data_collector.key?(plat)
data_collector[plat] = block
end
end

Expand Down
21 changes: 10 additions & 11 deletions spec/unit/dsl/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,20 @@
end

it "fails a platform has already been defined in the same plugin" do
expect do
Ohai.plugin(:Test) do
collect_data {}
collect_data {}
end
end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
Ohai.plugin(:Test) { collect_data {} }
expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/).twice
Ohai.plugin(:Test) do
collect_data {}
collect_data {}
end
end

it "fails if a platform has already been defined in another plugin file" do
Ohai.plugin(:Test) { collect_data {} }
expect do
Ohai.plugin(:Test) do
collect_data {}
end
end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
Ohai.plugin(:Test) do
collect_data {}
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

describe "when the plugin defines collect_data on the same platform more than once" do
it "shoud log an illegal plugin definition warning" do
expect(loader.logger).to receive(:warn).with(/Plugin Definition Error: <#{path_to("illegal_def.rb")}>:/)
expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
loader.load_plugin(path_to("illegal_def.rb"))
end

Expand Down