summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-04-11 13:53:27 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:53:27 -0500
commitcb617f20ed6e0af362937760f33f5ddc34e626ee (patch)
tree20fca09fe661f30765b5691273f37aed83e15249 /spec
parenta6a397b21ce9306307c7614b671de63d74d8141e (diff)
downloadpuppet-cb617f20ed6e0af362937760f33f5ddc34e626ee.tar.gz
puppet-cb617f20ed6e0af362937760f33f5ddc34e626ee.tar.xz
puppet-cb617f20ed6e0af362937760f33f5ddc34e626ee.zip
Making the changes necessary to get the REST support
to work with the current state of the indirection work, including using a request object and an expiration date.
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/indirector/rest.rb20
-rwxr-xr-xspec/unit/indirector/rest.rb62
2 files changed, 44 insertions, 38 deletions
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index a969a975b..8e3c92d5c 100644
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -9,7 +9,6 @@ class Puppet::TestIndirectedFoo
indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
attr_reader :value
- attr_accessor :version
def initialize(value = 0)
@value = value
@@ -51,6 +50,7 @@ describe Puppet::Indirector::REST do
end
it "should not fail" do
+ Puppet::TestIndirectedFoo.find('bar')
lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
end
@@ -62,8 +62,8 @@ describe Puppet::Indirector::REST do
Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
end
- it 'should set a version timestamp on model instance' do
- Puppet::TestIndirectedFoo.find('bar').version.should_not be_nil
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
end
end
@@ -275,8 +275,8 @@ describe Puppet::Indirector::REST do
Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
end
- it 'should set a version timestamp on model instance' do
- Puppet::TestIndirectedFoo.find('bar').version.should_not be_nil
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
end
end
@@ -330,11 +330,9 @@ describe Puppet::Indirector::REST do
Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value)
end
- it 'should set a version timestamp on model instances' do
- pending("Luke looking at why this version magic might not be working") do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.version.should_not be_nil
- end
+ it 'should set an expiration on model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.expiration.should_not be_nil
end
end
end
@@ -453,4 +451,4 @@ describe Puppet::Indirector::REST do
@server.unlisten
end
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index e511098ab..e46e32f1c 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -198,45 +198,47 @@ describe Puppet::Indirector::REST do
@result = { :foo => 'bar'}.to_yaml
@searcher.stubs(:network_fetch).returns(@result) # neuter the network connection
@model.stubs(:from_yaml).returns(@instance)
+
+ @request = stub 'request', :key => 'foo'
end
it "should look up the model instance over the network" do
@searcher.expects(:network_fetch).returns(@result)
- @searcher.find('foo')
+ @searcher.find(@request)
end
it "should look up the model instance using the named indirection" do
@searcher.expects(:network_fetch).with {|path| path =~ %r{^#{@indirection.name.to_s}/} }.returns(@result)
- @searcher.find('foo')
+ @searcher.find(@request)
end
it "should look up the model instance using the provided key" do
@searcher.expects(:network_fetch).with {|path| path =~ %r{/foo$} }.returns(@result)
- @searcher.find('foo')
+ @searcher.find(@request)
end
it "should deserialize result data to a Model instance" do
@model.expects(:from_yaml)
- @searcher.find('foo')
+ @searcher.find(@request)
end
it "should return the deserialized Model instance" do
- @searcher.find('foo').should == @instance
+ @searcher.find(@request).should == @instance
end
it "should return nil when deserialized model instance is nil" do
@model.stubs(:from_yaml).returns(nil)
- @searcher.find('foo').should be_nil
+ @searcher.find(@request).should be_nil
end
it "should generate an error when result data deserializes improperly" do
@model.stubs(:from_yaml).raises(ArgumentError)
- lambda { @searcher.find('foo') }.should raise_error(ArgumentError)
+ lambda { @searcher.find(@request) }.should raise_error(ArgumentError)
end
it "should generate an error when result data specifies an error" do
@searcher.stubs(:network_fetch).returns(RuntimeError.new("bogus").to_yaml)
- lambda { @searcher.find('foo') }.should raise_error(RuntimeError)
+ lambda { @searcher.find(@request) }.should raise_error(RuntimeError)
end
end
@@ -245,36 +247,38 @@ describe Puppet::Indirector::REST do
@result = [1, 2].to_yaml
@searcher.stubs(:network_fetch).returns(@result)
@model.stubs(:from_yaml).returns(@instance)
+
+ @request = stub 'request', :key => 'foo'
end
it "should look up the model data over the network" do
@searcher.expects(:network_fetch).returns(@result)
- @searcher.search('foo')
+ @searcher.search(@request)
end
it "should look up the model instance using the named indirection" do
@searcher.expects(:network_fetch).with {|path| path =~ %r{^#{@indirection.name.to_s}s/} }.returns(@result)
- @searcher.search('foo')
+ @searcher.search(@request)
end
it "should look up the model instance using the provided key" do
@searcher.expects(:network_fetch).with {|path| path =~ %r{/foo$} }.returns(@result)
- @searcher.search('foo')
+ @searcher.search(@request)
end
it "should deserialize result data into a list of Model instances" do
@model.expects(:from_yaml).at_least(2)
- @searcher.search('foo')
+ @searcher.search(@request)
end
it "should generate an error when result data deserializes improperly" do
@model.stubs(:from_yaml).raises(ArgumentError)
- lambda { @searcher.search('foo') }.should raise_error(ArgumentError)
+ lambda { @searcher.search(@request) }.should raise_error(ArgumentError)
end
it "should generate an error when result data specifies an error" do
@searcher.stubs(:network_fetch).returns(RuntimeError.new("bogus").to_yaml)
- lambda { @searcher.search('foo') }.should raise_error(RuntimeError)
+ lambda { @searcher.search(@request) }.should raise_error(RuntimeError)
end
end
@@ -283,35 +287,37 @@ describe Puppet::Indirector::REST do
@result = true.to_yaml
@searcher.stubs(:network_delete).returns(@result) # neuter the network connection
@model.stubs(:from_yaml).returns(@instance)
+
+ @request = stub 'request', :key => 'foo'
end
it "should look up the model instance over the network" do
@searcher.expects(:network_delete).returns(@result)
- @searcher.destroy('foo')
+ @searcher.destroy(@request)
end
it "should look up the model instance using the named indirection" do
@searcher.expects(:network_delete).with {|path| path =~ %r{^#{@indirection.name.to_s}/} }.returns(@result)
- @searcher.destroy('foo')
+ @searcher.destroy(@request)
end
it "should look up the model instance using the provided key" do
@searcher.expects(:network_delete).with {|path| path =~ %r{/foo$} }.returns(@result)
- @searcher.destroy('foo')
+ @searcher.destroy(@request)
end
it "should deserialize result data" do
YAML.expects(:load).with(@result)
- @searcher.destroy('foo')
+ @searcher.destroy(@request)
end
it "should return deserialized result data" do
- @searcher.destroy('foo').should == true
+ @searcher.destroy(@request).should == true
end
it "should generate an error when result data specifies an error" do
@searcher.stubs(:network_delete).returns(RuntimeError.new("bogus").to_yaml)
- lambda { @searcher.destroy('foo') }.should raise_error(RuntimeError)
+ lambda { @searcher.destroy(@request) }.should raise_error(RuntimeError)
end
end
@@ -320,6 +326,8 @@ describe Puppet::Indirector::REST do
@result = { :foo => 'bar'}.to_yaml
@searcher.stubs(:network_put).returns(@result) # neuter the network connection
@model.stubs(:from_yaml).returns(@instance)
+
+ @request = stub 'request', :instance => @instance
end
it "should re-enable caching in the terminus" do
@@ -328,7 +336,7 @@ describe Puppet::Indirector::REST do
it "should save the model instance over the network" do
@searcher.expects(:network_put).returns(@result)
- @searcher.save(@instance)
+ @searcher.save(@request)
end
it "should save the model instance using the named indirection" do
@@ -336,31 +344,31 @@ describe Puppet::Indirector::REST do
path =~ %r{^#{@indirection.name.to_s}/} and
data == @instance.to_yaml
end.returns(@result)
- @searcher.save(@instance)
+ @searcher.save(@request)
end
it "should deserialize result data to a Model instance" do
@model.expects(:from_yaml)
- @searcher.save(@instance)
+ @searcher.save(@request)
end
it "should return the resulting deserialized Model instance" do
- @searcher.save(@instance).should == @instance
+ @searcher.save(@request).should == @instance
end
it "should return nil when deserialized model instance is nil" do
@model.stubs(:from_yaml).returns(nil)
- @searcher.save(@instance).should be_nil
+ @searcher.save(@request).should be_nil
end
it "should generate an error when result data deserializes improperly" do
@model.stubs(:from_yaml).raises(ArgumentError)
- lambda { @searcher.save(@instance) }.should raise_error(ArgumentError)
+ lambda { @searcher.save(@request) }.should raise_error(ArgumentError)
end
it "should generate an error when result data specifies an error" do
@searcher.stubs(:network_put).returns(RuntimeError.new("bogus").to_yaml)
- lambda { @searcher.save(@instance) }.should raise_error(RuntimeError)
+ lambda { @searcher.save(@request) }.should raise_error(RuntimeError)
end
end
end