summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsawanoboly <sawanoboriyu@higanworks.com>2015-09-09 18:21:26 +0900
committerLamont Granquist <lamont@scriptkiddie.org>2015-10-24 20:25:11 -0700
commit219e84f17be85ca1a14986e63b087856748263ef (patch)
tree65325e7b79246e5b5966d18060cfd00275bf7133
parent4731e4bbe5a240ea9b1a725be6c41246ef4fe4a5 (diff)
downloadchef-219e84f17be85ca1a14986e63b087856748263ef.tar.gz
write spec for --json-attribute-file and move configration under render_template
-rw-r--r--lib/chef/knife/bootstrap.rb2
-rw-r--r--spec/unit/knife/bootstrap_spec.rb39
2 files changed, 34 insertions, 7 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index ea623b4f3e..b116ce3866 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -348,6 +348,7 @@ EOS
end
def render_template
+ @config[:first_boot_attributes].merge!(@config[:first_boot_attributes_from_file]) if @config[:first_boot_attributes_from_file]
template_file = find_template
template = IO.read(template_file).chomp
Erubis::Eruby.new(template).evaluate(bootstrap_context)
@@ -357,7 +358,6 @@ EOS
if @config[:first_boot_attributes].any? && @config[:first_boot_attributes_from_file]
raise Chef::Exceptions::BootstrapCommandInputError, jsonstring_and_jsonfile_msg
end
- @config[:first_boot_attributes].merge!(@config[:first_boot_attributes_from_file]) if @config[:first_boot_attributes_from_file]
validate_name_args!
validate_options!
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 48aae3e61b..342c1878f1 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -235,12 +235,39 @@ describe Chef::Knife::Bootstrap do
expect(knife.render_template).to eq('{"run_list":["role[base]","recipe[cupcakes]"]}')
end
- it "should have foo => {bar => baz} in the first_boot" do
- knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
- knife.merge_configs
- expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
- actual_hash = FFI_Yajl::Parser.new.parse(knife.render_template)
- expect(actual_hash).to eq(expected_hash)
+ context "with bootstrap_attribute options" do
+ let(:jsonfile) {
+ file = Tempfile.new (['node', '.json'])
+ File.open(file.path, "w") {|f| f.puts '{"foo":{"bar":"baz"}}' }
+ file
+ }
+
+ it "should have foo => {bar => baz} in the first_boot from cli" do
+ knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
+ knife.merge_configs
+ expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
+ actual_hash = FFI_Yajl::Parser.new.parse(knife.render_template)
+ expect(actual_hash).to eq(expected_hash)
+ end
+
+ it "should have foo => {bar => baz} in the first_boot from file" do
+ knife.parse_options(["--json-attribute-file", jsonfile.path])
+ knife.merge_configs
+ expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
+ actual_hash = FFI_Yajl::Parser.new.parse(knife.render_template)
+ expect(actual_hash).to eq(expected_hash)
+ jsonfile.close
+ end
+
+ context "when --json-attributes and --json-attribute-file were both passed" do
+ it "raises a Chef::Exceptions::BootstrapCommandInputError with the proper error message" do
+ knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
+ knife.parse_options(["--json-attribute-file", jsonfile.path])
+ knife.merge_configs
+ expect{ knife.run }.to raise_error(Chef::Exceptions::BootstrapCommandInputError)
+ jsonfile.close
+ end
+ end
end
end