diff options
author | Ben Somers <somers.ben@gmail.com> | 2013-05-14 11:25:07 -0700 |
---|---|---|
committer | Ben Somers <somers.ben@gmail.com> | 2014-06-08 16:33:58 -0700 |
commit | fb8375f99b6cf192484049383a9349416873e1fa (patch) | |
tree | 7fd203472a4858e138c26b57807053bb42f26184 /spec/unit/role_spec.rb | |
parent | 92519eb2cf7ae1b362f22d5710a229c5809a47cc (diff) | |
download | chef-fb8375f99b6cf192484049383a9349416873e1fa.tar.gz |
Enabling storage of roles in subdirectories
Storing roles in subdirectories is already effectively enabled
for Hosted Chef, as the directory structure gets flattened when
they are uploaded. But it is not currently possible with Chef-Solo;
one has to flatten the directory manually before running Chef-Solo.
This patch changes that behavior, and enables Chef-Solo with roles
in subdirectories.
Diffstat (limited to 'spec/unit/role_spec.rb')
-rw-r--r-- | spec/unit/role_spec.rb | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index f36b7f13bd..caa98f66b5 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -251,24 +251,43 @@ EOR describe "when loading from disk" do it "should return a Chef::Role object from JSON" do - File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.json')).exactly(1).times.and_return(true) - IO.should_receive(:read).with(File.join(Chef::Config[:role_path], 'lolcat.json')).and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }') + Dir.should_receive(:glob).and_return(["#{Chef::Config[:role_path]}/memes", "#{Chef::Config[:role_path]}/memes/lolcat.json"]) + file_path = File.join(Chef::Config[:role_path], 'memes/lolcat.json') + File.should_receive(:exists?).with(file_path).exactly(1).times.and_return(true) + IO.should_receive(:read).with(file_path).and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }') @role.should be_a_kind_of(Chef::Role) @role.class.from_disk("lolcat") end it "should return a Chef::Role object from a Ruby DSL" do - File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.json')).exactly(1).times.and_return(false) - File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.rb')).exactly(2).times.and_return(true) - File.should_receive(:readable?).with(File.join(Chef::Config[:role_path], 'lolcat.rb')).exactly(1).times.and_return(true) - IO.should_receive(:read).with(File.join(Chef::Config[:role_path], 'lolcat.rb')).and_return(ROLE_DSL) + Dir.should_receive(:glob).and_return(["#{Chef::Config[:role_path]}/memes", "#{Chef::Config[:role_path]}/memes/lolcat.rb"]) + js_path = File.join(Chef::Config[:role_path], 'memes/lolcat.rb') + rb_path = File.join(Chef::Config[:role_path], 'memes/lolcat.rb') + File.should_receive(:exists?).with(rb_path).exactly(2).times.and_return(true) + File.should_receive(:readable?).with(rb_path).exactly(1).times.and_return(true) + ROLE_DSL=<<-EOR +name "ceiling_cat" +description "like Aliens, but furry" +EOR + IO.should_receive(:read).with(rb_path).and_return(ROLE_DSL) + @role.should be_a_kind_of(Chef::Role) + @role.class.from_disk("lolcat") + end + + it "should prefer a Chef::Role Object from JSON over one from a Ruby DSL" do + Dir.should_receive(:glob).and_return(["#{Chef::Config[:role_path]}/memes", "#{Chef::Config[:role_path]}/memes/lolcat.json", "#{Chef::Config[:role_path]}/memes/lolcat.rb"]) + js_path = File.join(Chef::Config[:role_path], 'memes/lolcat.json') + rb_path = File.join(Chef::Config[:role_path], 'memes/lolcat.rb') + File.should_receive(:exists?).with(js_path).exactly(1).times.and_return(true) + File.should_not_receive(:exists?).with(rb_path) + IO.should_receive(:read).with(js_path).and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }') @role.should be_a_kind_of(Chef::Role) @role.class.from_disk("lolcat") end it "should raise an exception if the file does not exist" do - File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.json')).exactly(1).times.and_return(false) - File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.rb')).exactly(1).times.and_return(false) + Dir.should_receive(:glob).and_return(["#{Chef::Config[:role_path]}/meme.rb"]) + File.should_not_receive(:exists?) lambda {@role.class.from_disk("lolcat")}.should raise_error(Chef::Exceptions::RoleNotFound) end end |