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

Commit

Permalink
Merge pull request #128 from shortdudey123/prefer_cli_config
Browse files Browse the repository at this point in the history
Prefer CLI config over Knife config for locate_config_value
  • Loading branch information
martinb3 committed Nov 17, 2016
2 parents a99d3ce + 4196873 commit 56be338
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chef/knife/rackspace_base.rb
Expand Up @@ -159,7 +159,7 @@ def auth_endpoint

def locate_config_value(key)
key = key.to_sym
Chef::Config[:knife][key] || config[key]
config[key] || Chef::Config[:knife][key]
end

def msg_pair(label, value, color = :cyan)
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/rackspace_base_spec.rb
Expand Up @@ -36,3 +36,29 @@ class RackspaceBaseTester < Chef::Knife
expect(tester.auth_endpoint).to eq(::Fog::Rackspace::UK_AUTH_ENDPOINT)
end
end

describe "locate_config_value" do
it 'with cli options' do
# CLI
tester = RackspaceBaseTester.new
tester.parse_options([ "--rackspace-api-key", "12345" ])

# Knife Config
Chef::Config[:knife][:rackspace_api_key] = "67890"

# Test
expect(tester.locate_config_value(:rackspace_api_key)).to eq("12345")
end

it 'without cli options' do
# CLI
tester = RackspaceBaseTester.new
tester.parse_options([])

# Knife Config
Chef::Config[:knife][:rackspace_api_key] = "67890"

# Test
expect(tester.locate_config_value(:rackspace_api_key)).to eq("67890")
end
end

0 comments on commit 56be338

Please sign in to comment.