diff options
author | Tommy Bishop <bishop.thomas@gmail.com> | 2011-06-01 00:37:21 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2011-07-19 09:20:59 -0700 |
commit | 51df245bc2a36082439e252d77f78936c51e49bf (patch) | |
tree | 3bb263df8a929cc543723f465bf66247d9f48781 /chef/spec | |
parent | f984a3599f3c1fc3f9e31794acbce228f51b4c1f (diff) | |
download | chef-51df245bc2a36082439e252d77f78936c51e49bf.tar.gz |
[CHEF-2394] load data bag items locally when in solo mode.
also updates so data bag and data bag item tests are more
consistent.
Diffstat (limited to 'chef/spec')
-rw-r--r-- | chef/spec/unit/data_bag_item_spec.rb | 50 | ||||
-rw-r--r-- | chef/spec/unit/data_bag_spec.rb | 40 |
2 files changed, 58 insertions, 32 deletions
diff --git a/chef/spec/unit/data_bag_item_spec.rb b/chef/spec/unit/data_bag_item_spec.rb index 129a0df673..b69cc18c10 100644 --- a/chef/spec/unit/data_bag_item_spec.rb +++ b/chef/spec/unit/data_bag_item_spec.rb @@ -193,30 +193,50 @@ describe Chef::DataBagItem do end end - describe "when loading from an API call" do + describe "when loading" do before do @data_bag_item.raw_data = {"id" => "charlie", "shell" => "zsh", "ssh_keys" => %w{key1 key2}} @data_bag_item.data_bag("users") - @http_client = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@http_client) end - it "converts raw data to a data bag item" do - @http_client.should_receive(:get_rest).with("data/users/charlie").and_return(@data_bag_item.to_hash) - item = Chef::DataBagItem.load(:users, "charlie") - item.should be_a_kind_of(Chef::DataBagItem) - item.should == @data_bag_item - + describe "from an API call" do + before do + @http_client = mock("Chef::REST") + Chef::REST.stub!(:new).and_return(@http_client) + end + + it "converts raw data to a data bag item" do + @http_client.should_receive(:get_rest).with("data/users/charlie").and_return(@data_bag_item.to_hash) + item = Chef::DataBagItem.load(:users, "charlie") + item.should be_a_kind_of(Chef::DataBagItem) + item.should == @data_bag_item + end + + it "does not convert when a DataBagItem is returned from the API call" do + @http_client.should_receive(:get_rest).with("data/users/charlie").and_return(@data_bag_item) + item = Chef::DataBagItem.load(:users, "charlie") + item.should be_a_kind_of(Chef::DataBagItem) + item.should equal(@data_bag_item) + end end - it "does not convert when a DataBagItem is returned from the API call" do - @http_client.should_receive(:get_rest).with("data/users/charlie").and_return(@data_bag_item) - item = Chef::DataBagItem.load(:users, "charlie") - item.should be_a_kind_of(Chef::DataBagItem) - item.should equal(@data_bag_item) + describe "in solo mode" do + before do + Chef::Config[:solo] = true + end + + after do + Chef::Config[:solo] = false + end + + it "converts the raw data to a data bag item" do + Chef::DataBag.should_receive(:load).with('users').and_return({'charlie' => @data_bag_item.to_hash}) + item = Chef::DataBagItem.load('users', 'charlie') + item.should be_a_kind_of(Chef::DataBagItem) + item.should == @data_bag_item + end end end end - diff --git a/chef/spec/unit/data_bag_spec.rb b/chef/spec/unit/data_bag_spec.rb index 92206ab677..89d28de78f 100644 --- a/chef/spec/unit/data_bag_spec.rb +++ b/chef/spec/unit/data_bag_spec.rb @@ -69,31 +69,37 @@ describe Chef::DataBag do end - describe "load" do - before(:each) do - Chef::Config[:chef_server_url] = 'https://myserver.example.com' - @rest_mock = mock('rest') - end + describe "when loading" do + describe "from an API call" do + before do + Chef::Config[:chef_server_url] = 'https://myserver.example.com' + @http_client = mock('Chef::REST') + end - it "should get the data bag from the server" do - Chef::REST.should_receive(:new).with('https://myserver.example.com').and_return(@rest_mock) - @rest_mock.should_receive(:get_rest).with('data/foo') - Chef::DataBag.load('foo') - end + it "should get the data bag from the server" do + Chef::REST.should_receive(:new).with('https://myserver.example.com').and_return(@http_client) + @http_client.should_receive(:get_rest).with('data/foo') + Chef::DataBag.load('foo') + end - it "should return the data bag" do - Chef::REST.stub!(:new).and_return(@rest_mock) - @rest_mock.stub!(:get_rest).and_return({'bar' => 'https://myserver.example.com/data/foo/bar'}) - data_bag = Chef::DataBag.load('foo') - data_bag.should == {'bar' => 'https://myserver.example.com/data/foo/bar'} + it "should return the data bag" do + Chef::REST.stub!(:new).and_return(@http_client) + @http_client.should_receive(:get_rest).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'}) + data_bag = Chef::DataBag.load('foo') + data_bag.should == {'bar' => 'https://myserver.example.com/data/foo/bar'} + end end - describe "when run in solo mode" do - before(:each) do + describe "in solo mode" do + before do Chef::Config[:solo] = true Chef::Config[:data_bag_path] = '/var/chef/data_bags' end + after do + Chef::Config[:solo] = false + end + it "should get the data bag from the data_bag_path" do Dir.should_receive(:glob).with('/var/chef/data_bags/foo/*.json').and_return([]) Chef::DataBag.load('foo') |