diff options
author | Tom Duffield <tom@chef.io> | 2016-02-17 17:18:50 -0600 |
---|---|---|
committer | Tom Duffield <tom@chef.io> | 2016-02-18 10:28:57 -0600 |
commit | 8ff48f1212ef91295e5fb5f101bcc311f78fc4ea (patch) | |
tree | b9f87c9aaf4c7aebea395fbfccd7cbb9a4dbc04a | |
parent | 83bab84325ce969d03d6f6373497fa8b21e80b53 (diff) | |
download | chef-IPO-44/td-mc/add-insights-url-config.tar.gz |
Add Insights URL to Chef::ConfigIPO-44/td-mc/add-insights-url-config
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 17 | ||||
-rw-r--r-- | chef-config/spec/unit/config_spec.rb | 23 |
2 files changed, 40 insertions, 0 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index ac55853bc7..edd8cc525c 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -386,6 +386,23 @@ module ChefConfig default :ez, false default :enable_reporting, true default :enable_reporting_url_fatals, false + + ### + # Insights + # + # Insights is a product that integrates analytics, metrics, and data for Chef, + # Delivery Workflow, and more. + # + configurable(:insights_url).writes_value do |uri| + unless is_valid_url? uri + raise ConfigurationError, "#{uri} is an invalid insights_url." + end + uri.to_s.strip + end + + # Sending data to Insights is disabled when the URL is unconfigured + default(:insights_enabled) { !self.configuration[:insights_url].nil? } + # Possible values for :audit_mode # :enabled, :disabled, :audit_only, # diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index dbde3d3160..e92eacf118 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -802,6 +802,29 @@ RSpec.describe ChefConfig::Config do end + describe "insights integration" do + + it "marks insights disabled by default" do + expect(ChefConfig::Config.insights_url).to be_nil + expect(ChefConfig::Config.insights_enabled).to eq(false) + end + + it "errors on invalid insights_url" do + expect { ChefConfig::Config.insights_url = "127.0.0.1" }.to raise_error(ChefConfig::ConfigurationError) + end + + context "when insights_url is set with valid url" do + before do + ChefConfig::Config.insights_url = "https://insights.example.com" + end + + it "marks insights as enabled" do + expect(ChefConfig::Config.insights_url).to eq("https://insights.example.com") + expect(ChefConfig::Config.insights_enabled).to eq(true) + end + end + end + describe "Treating deprecation warnings as errors" do context "when using our default RSpec configuration" do |