Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Load configuration when running chef update #605

Merged
merged 1 commit into from
Nov 17, 2015
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
19 changes: 19 additions & 0 deletions lib/chef-dk/command/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
require 'chef-dk/ui'
require 'chef-dk/policyfile_services/install'
require 'chef-dk/policyfile_services/update_attributes'
require 'chef-dk/configurable'

module ChefDK
module Command

class Update < Base

include Configurable

banner(<<-BANNER)
Usage: chef update [ POLICY_FILE ] [options]

Expand All @@ -45,6 +48,11 @@ class Update < Base

BANNER

option :config_file,
short: "-c CONFIG_FILE",
long: "--config CONFIG_FILE",
description: "Path to configuration file"

option :debug,
short: "-D",
long: "--debug",
Expand Down Expand Up @@ -74,6 +82,13 @@ def initialize(*args)

def run(params = [])
return 1 unless apply_params!(params)

# Force config file to be loaded. We don't use the configuration
# directly, but the user may have SSL configuration options that they
# need to talk to a private supermarket (e.g., trusted_certs or
# ssl_verify_mode)
chef_config

if update_attributes?
attributes_updater.run
else
Expand All @@ -98,6 +113,10 @@ def debug?
!!config[:debug]
end

def config_path
config[:config_file]
end

def update_attributes?
!!config[:update_attributes]
end
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/command/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
expect(command.debug?).to be(false)
end

it "doesn't set a config path by default" do
expect(command.config_path).to be_nil
end

context "when debug mode is set" do

let(:params) { [ "-D" ] }
Expand All @@ -48,6 +52,26 @@
end
end

context "when an explicit config file path is given" do

let(:params) { %w[ -c ~/.chef/alternate_config.rb ] }

let(:chef_config_loader) { instance_double("Chef::WorkstationConfigLoader") }

it "sets the config file path to the given value" do
expect(command.config_path).to eq("~/.chef/alternate_config.rb")
end

it "loads the config from the given path" do
expect(Chef::WorkstationConfigLoader).to receive(:new).
with("~/.chef/alternate_config.rb").
and_return(chef_config_loader)
expect(chef_config_loader).to receive(:load)
expect(command.chef_config).to eq(Chef::Config)
end

end

context "when attributes update mode is set" do

let(:params) { ["-a"] }
Expand Down