From 8ff48f1212ef91295e5fb5f101bcc311f78fc4ea Mon Sep 17 00:00:00 2001 From: Tom Duffield Date: Wed, 17 Feb 2016 17:18:50 -0600 Subject: Add Insights URL to Chef::Config --- chef-config/lib/chef-config/config.rb | 17 +++++++++++++++++ chef-config/spec/unit/config_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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 -- cgit v1.2.1