summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-12-27 12:43:52 +1100
committerJames Turnbull <james@lovedthanlost.net>2008-12-27 12:43:52 +1100
commit4c648bb1e7428806550f57160f72892709b0a30f (patch)
treefeb1108c0608a95ec088554dae7753d2c9609a14 /spec/unit/indirector
parent34335b7a2e6950d4bb3dcaaf2bfe88cbc684007e (diff)
parent7403330c4f63c290ba3cc5992706a3f0b1c9caa0 (diff)
downloadpuppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.gz
puppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.xz
puppet-4c648bb1e7428806550f57160f72892709b0a30f.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG
Diffstat (limited to 'spec/unit/indirector')
-rwxr-xr-xspec/unit/indirector/yaml.rb21
1 files changed, 14 insertions, 7 deletions
diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb
index 081ae9666..7536fbc25 100755
--- a/spec/unit/indirector/yaml.rb
+++ b/spec/unit/indirector/yaml.rb
@@ -58,12 +58,12 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
proc { @store.save(@request) }.should raise_error(ArgumentError)
end
- it "should convert Ruby objects to YAML and write them to disk" do
+ it "should convert Ruby objects to YAML and write them to disk using a write lock" do
yaml = @subject.to_yaml
file = mock 'file'
path = @store.send(:path, @subject.name)
FileTest.expects(:exist?).with(File.dirname(path)).returns(true)
- File.expects(:open).with(path, "w", 0660).yields(file)
+ @store.expects(:writelock).with(path, 0660).yields(file)
file.expects(:print).with(yaml)
@store.save(@request)
@@ -74,9 +74,11 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
file = mock 'file'
path = @store.send(:path, @subject.name)
dir = File.dirname(path)
+
FileTest.expects(:exist?).with(dir).returns(false)
Dir.expects(:mkdir).with(dir)
- File.expects(:open).with(path, "w", 0660).yields(file)
+
+ @store.expects(:writelock).yields(file)
file.expects(:print).with(yaml)
@store.save(@request)
@@ -84,24 +86,29 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
end
describe Puppet::Indirector::Yaml, " when retrieving YAML" do
- it "should read YAML in from disk and convert it to Ruby objects" do
+ it "should read YAML in from disk using a read lock and convert it to Ruby objects" do
path = @store.send(:path, @subject.name)
yaml = @subject.to_yaml
FileTest.expects(:exist?).with(path).returns(true)
- File.expects(:read).with(path).returns(yaml)
+
+ fh = mock 'filehandle'
+ @store.expects(:readlock).with(path).yields fh
+ fh.expects(:read).returns yaml
@store.find(@request).instance_variable_get("@name").should == :me
end
it "should fail coherently when the stored YAML is invalid" do
path = @store.send(:path, @subject.name)
+ FileTest.expects(:exist?).with(path).returns(true)
# Something that will fail in yaml
yaml = "--- !ruby/object:Hash"
- FileTest.expects(:exist?).with(path).returns(true)
- File.expects(:read).with(path).returns(yaml)
+ fh = mock 'filehandle'
+ @store.expects(:readlock).yields fh
+ fh.expects(:read).returns yaml
proc { @store.find(@request) }.should raise_error(Puppet::Error)
end