summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-03-13 01:22:12 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-03-20 18:27:07 +1100
commitedf00dba76b65108b443af8d0636073cb3d9d975 (patch)
tree75951e613a375dca4780d46dde35b1046f64446d /spec
parenta064ed1a6035c44f123e092b2429895fb45bdbd2 (diff)
downloadpuppet-edf00dba76b65108b443af8d0636073cb3d9d975.tar.gz
puppet-edf00dba76b65108b443af8d0636073cb3d9d975.tar.xz
puppet-edf00dba76b65108b443af8d0636073cb3d9d975.zip
Adding environment support to the REST URI
Also adding it to the Indirection Request. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/request.rb17
-rwxr-xr-xspec/unit/indirector/rest.rb21
2 files changed, 28 insertions, 10 deletions
diff --git a/spec/unit/indirector/request.rb b/spec/unit/indirector/request.rb
index 98ecf2fd3..e2edc2641 100755
--- a/spec/unit/indirector/request.rb
+++ b/spec/unit/indirector/request.rb
@@ -9,6 +9,10 @@ describe Puppet::Indirector::Request do
lambda { Puppet::Indirector::Request.new }.should raise_error(ArgumentError)
end
+ it "should always convert the indirection name to a symbol" do
+ Puppet::Indirector::Request.new("ind", :method, "mykey").indirection_name.should == :ind
+ end
+
it "should use provided value as the key if it is a string" do
Puppet::Indirector::Request.new(:ind, :method, "mykey").key.should == "mykey"
end
@@ -178,6 +182,19 @@ describe Puppet::Indirector::Request do
Puppet::Indirector::Request.new(:myind, :find, "my key").escaped_key.should == URI.escape("my key")
end
+ it "should have an environment accessor" do
+ Puppet::Indirector::Request.new(:myind, :find, "my key", :environment => "foo").should respond_to(:environment)
+ end
+
+ it "should set its environment to an environment instance when a string is specified as its environment" do
+ Puppet::Indirector::Request.new(:myind, :find, "my key", :environment => "foo").environment.should == Puppet::Node::Environment.new("foo")
+ end
+
+ it "should use any passed in environment instances as its environment" do
+ env = Puppet::Node::Environment.new("foo")
+ Puppet::Indirector::Request.new(:myind, :find, "my key", :environment => env).environment.should equal(env)
+ end
+
describe "when building a query string from its options" do
before do
@request = Puppet::Indirector::Request.new(:myind, :find, "my key")
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 25b3bfcb2..361412a54 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -168,8 +168,8 @@ describe Puppet::Indirector::REST do
@searcher.find(@request).should == 'myobject'
end
- it "should use the indirection name and escaped request key to create the path" do
- should_path = "/%s/%s" % [@indirection.name.to_s, "foo"]
+ it "should use the environment, indirection name, and escaped request key to create the path" do
+ should_path = "/%s/%s/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
@connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
@searcher.find(@request)
end
@@ -221,15 +221,15 @@ describe Puppet::Indirector::REST do
@searcher.search(@request).should == 'myobject'
end
- it "should use the plural indirection name as the path if there is no request key" do
- should_path = "/%ss" % [@indirection.name.to_s]
+ it "should use the environment and the plural indirection name as the path if there is no request key" do
+ should_path = "/%s/%ss" % [Puppet::Node::Environment.new, @indirection.name.to_s]
@request.stubs(:key).returns nil
@connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
@searcher.search(@request)
end
- it "should use the plural indirection name and escaped request key to create the path if the request key is set" do
- should_path = "/%ss/%s" % [@indirection.name.to_s, "foo"]
+ it "should use the envrironment, the plural indirection name, and the escaped request key to create the path if the request key is set" do
+ should_path = "/%s/%ss/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
@connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
@searcher.search(@request)
end
@@ -286,8 +286,8 @@ describe Puppet::Indirector::REST do
@searcher.destroy(@request).should == 'myobject'
end
- it "should use the indirection name and escaped request key to create the path" do
- should_path = "/%s/%s" % [@indirection.name.to_s, "foo"]
+ it "should use the environment, the indirection name, and the escaped request key to create the path" do
+ should_path = "/%s/%s/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
@connection.expects(:delete).with { |path, args| path == should_path }.returns(@response)
@searcher.destroy(@request)
end
@@ -337,8 +337,9 @@ describe Puppet::Indirector::REST do
lambda { @searcher.save(@request) }.should raise_error(ArgumentError)
end
- it "should use the indirection name as the path for the request" do
- @connection.expects(:put).with { |path, data, args| path == "/#{@indirection.name.to_s}/" }.returns @response
+ it "should use the environment and the indirection name as the path for the request" do
+ path = "/%s/%s/" % [Puppet::Node::Environment.new, @indirection.name]
+ @connection.expects(:put).with { |path, data, args| path == path }.returns @response
@searcher.save(@request)
end