diff options
author | Ivan Larionov <ivan.larionov@skype.net> | 2014-01-21 13:41:51 +0400 |
---|---|---|
committer | Ivan Larionov <ivan.larionov@skype.net> | 2014-05-31 03:21:59 +0400 |
commit | ab216f0ee10022b2d9c2a65b6c13c9e75d456ad4 (patch) | |
tree | f9e302dbfbe59c62971918a4be2eb0d67c7cea5a /spec/unit/data_bag_spec.rb | |
parent | 42bbac859fe520f1c6fe2626ca109ea4edd322a2 (diff) | |
download | chef-ab216f0ee10022b2d9c2a65b6c13c9e75d456ad4.tar.gz |
[CHEF-3399] Use first seen data bag (do not overwrite). Tests.
Diffstat (limited to 'spec/unit/data_bag_spec.rb')
-rw-r--r-- | spec/unit/data_bag_spec.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 71f74821a3..08860fa018 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -163,15 +163,21 @@ describe Chef::DataBag do Chef::DataBag.load(:foo) end - it "should return the data bag" do - @paths.each do |path| + it "should return merged data bag with first seen values" do + @paths.each_with_index do |path, index| file_dir_stub(path) dir_glob_stub(path, [File.join(path, 'foo/bar.json'), File.join(path, 'foo/baz.json')]) - IO.should_receive(:read).with(File.join(path, 'foo/bar.json')).and_return('{"id": "bar", "name": "Bob Bar" }') - IO.should_receive(:read).with(File.join(path, 'foo/baz.json')).and_return('{"id": "baz", "name": "John Baz" }') + test_dup_key = "{\"id\": \"bar\", \"name\": \"Bob Bar\", \"path\": \"#{path}\"}" + IO.should_receive(:read).with(File.join(path, 'foo/bar.json')).and_return(test_dup_key) + test_uniq_key = "{\"id\": \"baz_#{index}\", \"name\": \"John Baz\", \"path\": \"#{path}\"}" + IO.should_receive(:read).with(File.join(path, 'foo/baz.json')).and_return(test_uniq_key) end data_bag = Chef::DataBag.load('foo') - data_bag.should == { 'bar' => { 'id' => 'bar', 'name' => 'Bob Bar' }, 'baz' => { 'id' => 'baz', 'name' => 'John Baz' }} + test_data_bag = { 'bar' => { 'id' => 'bar', 'name' => 'Bob Bar', 'path' => @paths.first} } + @paths.each_with_index do |path, index| + test_data_bag["baz_#{index}"] = { "id" => "baz_#{index}", "name" => "John Baz", "path" => path } + end + data_bag.should == test_data_bag end it "should return the data bag list" do |