# # Author:: Adam Jacob () # Author:: Claire McQuin () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") require "ohai/mixin/os" describe "Ohai::System" do extend IntegrationSupport let(:ohai) { Ohai::System.new } describe "#initialize" do it "returns an Ohai::System object" do expect(ohai).to be_a_kind_of(Ohai::System) end it "sets @attributes to a ProvidesMap" do expect(ohai.provides_map).to be_a_kind_of(Ohai::ProvidesMap) end it "sets @v6_dependency_solver to a Hash" do expect(ohai.v6_dependency_solver).to be_a_kind_of(Hash) end it "merges deprecated config settings into the ohai config context" do expect(Ohai::Log).to receive(:warn). with(/Ohai::Config\[:disabled_plugins\] is deprecated/) Ohai::Config[:disabled_plugins] = [ :Foo, :Baz ] expect(Ohai::Config).to receive(:merge_deprecated_config). and_call_original Ohai::System.new expect(Ohai.config[:disabled_plugins]).to eq([ :Foo, :Baz ]) end it "merges provided configuration options into the ohai config context" do config = { disabled_plugins: [ :Foo, :Baz ], directory: "/some/extra/plugins", critical_plugins: [ :Foo, :Bar ], } allow(Ohai::Config).to receive(:merge_deprecated_config) expect(Ohai.config).to receive(:merge!).with(config).and_call_original Ohai::System.new(config) config.each do |option, value| expect(Ohai.config[option]).to eq(value) end end context "when directory is configured" do let(:directory) { "/some/fantastic/plugins" } it "adds directory to plugin_path" do Ohai.config[:directory] = directory Ohai::System.new expect(Ohai.config[:plugin_path]).to include(directory) end end shared_examples_for "appendable deprecated configuration option" do it "logs a warning and configures the option on the ohai config context" do Ohai::Config[option] << value expect(Ohai::Log).to receive(:warn). with(/Ohai::Config\[:#{option}\] is deprecated/) Ohai::System.new expect(Ohai.config[option]).to include(value) end end context "when a top-level hints_path is configured" do include_examples "appendable deprecated configuration option" do let(:option) { :hints_path } let(:value) { "/path/to/hints" } end end context "when a top-level plugin_path is configured" do include_examples "appendable deprecated configuration option" do let(:option) { :plugin_path } let(:value) { "/path/to/plugins" } end end context "first time configuration" do before { allow(Ohai::Log).to receive(:configured?).and_return(false) } it "configures logging" do log_level = :debug Ohai.config[:log_level] = log_level expect(Ohai::Log).to receive(:level=).with(log_level) Ohai::System.new end it "resolves log_level when set to :auto" do expect(Ohai::Log).to receive(:level=).with(:info) Ohai::System.new end end context "after first time configuration" do before { allow(Ohai::Log).to receive(:configured?).and_return(true) } it "configures logging" do expect(Ohai::Log).not_to receive(:init).with(Ohai.config[:log_location]) Ohai::System.new end end end when_plugins_directory "contains v6 and v7 plugins" do with_plugin("zoo.rb", <