summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-18 17:51:25 -0500
committerLuke Kanies <luke@madstop.com>2008-07-18 17:51:25 -0500
commitebb219e496682862ac98d382afe014cf1c763f2f (patch)
treed754de01560f8724e2cfad5ff3a53d714e37e9ba /spec
parentd8937acb8c9b108e61330cbac703a17b2eaba9b3 (diff)
downloadpuppet-ebb219e496682862ac98d382afe014cf1c763f2f.tar.gz
puppet-ebb219e496682862ac98d382afe014cf1c763f2f.tar.xz
puppet-ebb219e496682862ac98d382afe014cf1c763f2f.zip
Fixed all of the fileserving termini so they use indirection requests.
This looks like a much larger commit than it is -- it doesn't change any behaviour at all, it just adds some integration tests (which expose the problem) and then switches from an ad-hoc api to a request-based api. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/file_serving/metadata.rb1
-rwxr-xr-xspec/integration/indirector/module_files.rb8
-rw-r--r--spec/shared_behaviours/file_server_terminus.rb4
-rw-r--r--spec/shared_behaviours/file_serving.rb22
-rwxr-xr-xspec/unit/file_serving/terminus_helper.rb94
-rwxr-xr-xspec/unit/indirector/direct_file_server.rb13
-rwxr-xr-xspec/unit/indirector/file_metadata/modules.rb6
-rwxr-xr-xspec/unit/indirector/file_server.rb104
-rwxr-xr-xspec/unit/indirector/module_files.rb86
9 files changed, 188 insertions, 150 deletions
diff --git a/spec/integration/file_serving/metadata.rb b/spec/integration/file_serving/metadata.rb
index 5600365f1..067cb566a 100755
--- a/spec/integration/file_serving/metadata.rb
+++ b/spec/integration/file_serving/metadata.rb
@@ -16,4 +16,3 @@ describe Puppet::FileServing::Metadata, " when finding files" do
@indirection = Puppet::FileServing::Metadata.indirection
end
end
-
diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb
index 1831bffbc..ae14aa5a7 100755
--- a/spec/integration/indirector/module_files.rb
+++ b/spec/integration/indirector/module_files.rb
@@ -20,7 +20,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module
FileTest.expects(:exists?).with(filepath).returns(true)
- @terminus.find("puppetmounts://host/modules/mymod/myfile").should be_instance_of(Puppet::FileServing::Content)
+ @request = Puppet::Indirector::Request.new(:content, :find, "puppetmounts://host/modules/mymod/myfile")
+
+ @terminus.find(@request).should be_instance_of(Puppet::FileServing::Content)
end
end
@@ -45,7 +47,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with FileServing::F
Dir.expects(:entries).with(filepath).returns(%w{one two})
- result = @terminus.search("puppetmounts://host/modules/mymod/myfile", :recurse => true)
+ @request = Puppet::Indirector::Request.new(:content, :search, "puppetmounts://host/modules/mymod/myfile", :recurse => true)
+
+ result = @terminus.search(@request)
result.should be_instance_of(Array)
result.length.should == 3
result.each { |r| r.should be_instance_of(Puppet::FileServing::Content) }
diff --git a/spec/shared_behaviours/file_server_terminus.rb b/spec/shared_behaviours/file_server_terminus.rb
index de08f29fc..bb6b67132 100644
--- a/spec/shared_behaviours/file_server_terminus.rb
+++ b/spec/shared_behaviours/file_server_terminus.rb
@@ -24,6 +24,8 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
# Stub out the modules terminus
@modules = mock 'modules terminus'
+
+ @request = Puppet::Indirector::Request.new(:indirection, :method, "puppetmounts://myhost/one/my/file")
end
it "should use the file server configuration to find files" do
@@ -35,6 +37,6 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
@mount1.expects(:file).with("my/file", :node => nil).returns(path)
- @terminus.find("puppetmounts://myhost/one/my/file").should be_instance_of(@test_class)
+ @terminus.find(@request).should be_instance_of(@test_class)
end
end
diff --git a/spec/shared_behaviours/file_serving.rb b/spec/shared_behaviours/file_serving.rb
index 82f207243..ba01f75a1 100644
--- a/spec/shared_behaviours/file_serving.rb
+++ b/spec/shared_behaviours/file_serving.rb
@@ -5,13 +5,13 @@
describe "Puppet::FileServing::Files", :shared => true do
it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
- uri = "puppet://myhost/mymod/my/file"
+ uri = "puppet://myhost/fakemod/my/file"
@indirection.terminus(:rest).expects(:find)
@test_class.find(uri)
end
it "should use the rest terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is not 'puppet'" do
- uri = "puppet:///mymod/my/file"
+ uri = "puppet:///fakemod/my/file"
Puppet.settings.stubs(:value).with(:name).returns("puppetd")
Puppet.settings.stubs(:value).with(:modulepath).returns("")
@indirection.terminus(:rest).expects(:find)
@@ -19,7 +19,7 @@ describe "Puppet::FileServing::Files", :shared => true do
end
it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'puppet'" do
- uri = "puppet:///mymod/my/file"
+ uri = "puppet:///fakemod/my/file"
Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing"))
Puppet.settings.stubs(:value).with(:name).returns("puppet")
Puppet.settings.stubs(:value).with(:modulepath, "testing").returns("")
@@ -33,22 +33,32 @@ describe "Puppet::FileServing::Files", :shared => true do
end
it "should use the file_server terminus when the 'puppetmounts' URI scheme is used" do
- uri = "puppetmounts:///mymod/my/file"
+ uri = "puppetmounts:///fakemod/my/file"
@indirection.terminus(:file_server).expects(:find)
@indirection.terminus(:file_server).stubs(:authorized?).returns(true)
@test_class.find(uri)
end
it "should use the file terminus when the 'file' URI scheme is used" do
- uri = "file:///mymod/my/file"
+ uri = "file:///fakemod/my/file"
@indirection.terminus(:file).expects(:find)
@test_class.find(uri)
end
it "should use the file terminus when a fully qualified path is provided" do
- uri = "/mymod/my/file"
+ uri = "/fakemod/my/file"
@indirection.terminus(:file).expects(:find)
@test_class.find(uri)
end
+
+ it "should use the configuration to test whether the request is allowed" do
+ uri = "puppetmounts:///fakemod/my/file"
+ config = mock 'configuration'
+ @indirection.terminus(:file_server).stubs(:configuration).returns config
+
+ @indirection.terminus(:file_server).expects(:find)
+ config.expects(:authorized?).returns(true)
+ @test_class.find(uri, :node => "foo", :ip => "bar")
+ end
end
diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb
index b919469a2..763ce9eb0 100755
--- a/spec/unit/file_serving/terminus_helper.rb
+++ b/spec/unit/file_serving/terminus_helper.rb
@@ -14,65 +14,63 @@ describe Puppet::FileServing::TerminusHelper do
@model = mock 'model'
@helper.stubs(:model).returns(@model)
+
+ @request = stub 'request', :key => "url", :options => {}
end
it "should use a fileset to find paths" do
fileset = mock 'fileset', :files => []
Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset)
- @helper.path2instances("url", "/my/file")
+ @helper.path2instances(@request, "/my/file")
end
it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do
fileset = mock 'fileset', :files => []
Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset)
- @helper.path2instances("url", "/my/file", :links => :a, :ignore => :b, :recurse => :c)
- end
-end
-
-
-describe Puppet::FileServing::TerminusHelper, " when creating instances" do
- before do
- @helper = Object.new
- @helper.extend(Puppet::FileServing::TerminusHelper)
-
- @model = mock 'model'
- @helper.stubs(:model).returns(@model)
-
- @key = "puppet://host/mount/dir"
-
- @fileset = mock 'fileset', :files => %w{one two}
- Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
- end
-
- it "should create an instance of the model for each path returned by the fileset" do
- @model.expects(:new).returns(:one)
- @model.expects(:new).returns(:two)
- @helper.path2instances(@key, "/my/file").length.should == 2
- end
-
- it "should set each instance's key to be the original key plus the file-specific path" do
- @model.expects(:new).with { |key, options| key == @key + "/one" }.returns(:one)
- @model.expects(:new).with { |key, options| key == @key + "/two" }.returns(:two)
- @helper.path2instances(@key, "/my/file")
- end
-
- it "should set each returned instance's path to the original path" do
- @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one)
- @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two)
- @helper.path2instances(@key, "/my/file")
- end
-
- it "should set each returned instance's relative path to the file-specific path" do
- @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one)
- @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two)
- @helper.path2instances(@key, "/my/file")
+ @request.stubs(:options).returns(:links => :a, :ignore => :b, :recurse => :c)
+ @helper.path2instances(@request, "/my/file")
end
- it "should set the links value on each instance if one is provided" do
- one = mock 'one', :links= => :manage
- two = mock 'two', :links= => :manage
- @model.expects(:new).returns(one)
- @model.expects(:new).returns(two)
- @helper.path2instances(@key, "/my/file", :links => :manage)
+ describe "when creating instances" do
+ before do
+ @request.stubs(:key).returns "puppet://host/mount/dir"
+
+ @fileset = mock 'fileset', :files => %w{one two}
+ Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
+ end
+
+ it "should create an instance of the model for each path returned by the fileset" do
+ @model.expects(:new).returns(:one)
+ @model.expects(:new).returns(:two)
+ @helper.path2instances(@request, "/my/file").length.should == 2
+ end
+
+ it "should set each instance's key to be the original key plus the file-specific path" do
+ @model.expects(:new).with { |key, options| key == @request.key + "/one" }.returns(:one)
+ @model.expects(:new).with { |key, options| key == @request.key + "/two" }.returns(:two)
+ @helper.path2instances(@request, "/my/file")
+ end
+
+ it "should set each returned instance's path to the original path" do
+ @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one)
+ @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two)
+ @helper.path2instances(@request, "/my/file")
+ end
+
+ it "should set each returned instance's relative path to the file-specific path" do
+ @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one)
+ @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two)
+ @helper.path2instances(@request, "/my/file")
+ end
+
+ it "should set the links value on each instance if one is provided" do
+ one = mock 'one', :links= => :manage
+ two = mock 'two', :links= => :manage
+ @model.expects(:new).returns(one)
+ @model.expects(:new).returns(two)
+
+ @request.options[:links] = :manage
+ @helper.path2instances(@request, "/my/file")
+ end
end
end
diff --git a/spec/unit/indirector/direct_file_server.rb b/spec/unit/indirector/direct_file_server.rb
index a8583716a..0753f1bbe 100755
--- a/spec/unit/indirector/direct_file_server.rb
+++ b/spec/unit/indirector/direct_file_server.rb
@@ -69,29 +69,20 @@ describe Puppet::Indirector::DirectFileServer do
end
describe Puppet::Indirector::DirectFileServer, "when searching for multiple files" do
-
it "should return nil if the file does not exist" do
FileTest.expects(:exists?).with("/my/local").returns false
@server.find(@request).should be_nil
end
- it "should pass the original key to :path2instances" do
- FileTest.expects(:exists?).with("/my/local").returns true
- @server.expects(:path2instances).with { |uri, path, options| uri == @uri }
- @server.search(@request)
- end
-
it "should use :path2instances from the terminus_helper to return instances if the file exists" do
FileTest.expects(:exists?).with("/my/local").returns true
@server.expects(:path2instances)
@server.search(@request)
end
- it "should pass any options on to :path2instances" do
+ it "should pass the original request to :path2instances" do
FileTest.expects(:exists?).with("/my/local").returns true
- @server.expects(:path2instances).with { |uri, path, options| options == {:testing => :one, :other => :two}}
-
- @request.stubs(:options).returns(:testing => :one, :other => :two)
+ @server.expects(:path2instances).with(@request, "/my/local")
@server.search(@request)
end
end
diff --git a/spec/unit/indirector/file_metadata/modules.rb b/spec/unit/indirector/file_metadata/modules.rb
index 62f01832c..3905a49ad 100755
--- a/spec/unit/indirector/file_metadata/modules.rb
+++ b/spec/unit/indirector/file_metadata/modules.rb
@@ -23,11 +23,13 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do
@finder.stubs(:environment).returns(nil)
@module = Puppet::Module.new("mymod", "/path/to")
@finder.stubs(:find_module).returns(@module)
+
+ @request = Puppet::Indirector::Request.new(:metadata, :find, "puppetmounts://hostname/modules/mymod/my/file")
end
it "should return nil if the file is not found" do
FileTest.expects(:exists?).with("/path/to/files/my/file").returns false
- @finder.find("puppetmounts://hostname/modules/mymod/my/file").should be_nil
+ @finder.find(@request).should be_nil
end
it "should retrieve the instance's attributes if the file is found" do
@@ -35,6 +37,6 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do
instance = mock 'metadta'
Puppet::FileServing::Metadata.expects(:new).returns instance
instance.expects :collect_attributes
- @finder.find("puppetmounts://hostname/modules/mymod/my/file")
+ @finder.find(@request)
end
end
diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb
index 79be8cc29..ba951737a 100755
--- a/spec/unit/indirector/file_server.rb
+++ b/spec/unit/indirector/file_server.rb
@@ -27,34 +27,37 @@ describe Puppet::Indirector::FileServer do
@uri = "puppetmounts://host/my/local/file"
@configuration = mock 'configuration'
Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
+
+ @request = Puppet::Indirector::Request.new(:myind, :mymethod, @uri)
end
describe Puppet::Indirector::FileServer, " when finding files" do
it "should use the path portion of the URI as the file name" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @file_server.find(@uri)
+ @file_server.find(@request)
end
it "should use the FileServing configuration to convert the file name to a fully qualified path" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @file_server.find(@uri)
+ @file_server.find(@request)
end
it "should pass the node name to the FileServing configuration if one is provided" do
@configuration.expects(:file_path).with("/my/local/file", :node => "testing")
- @file_server.find(@uri, :node => "testing")
+ @request.node = "testing"
+ @file_server.find(@request)
end
it "should return nil if no fully qualified path is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
- @file_server.find(@uri).should be_nil
+ @file_server.find(@request).should be_nil
end
it "should return an instance of the model created with the full path if a file is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
@model.expects(:new).returns(:myinstance)
- @file_server.find(@uri).should == :myinstance
+ @file_server.find(@request).should == :myinstance
end
end
@@ -66,23 +69,24 @@ describe Puppet::Indirector::FileServer do
it "should create the instance with the key used to find the instance" do
@model.expects(:new).with { |key, *options| key == @uri }
- @file_server.find(@uri)
+ @file_server.find(@request)
end
it "should create the instance with the path at which the instance was found" do
@model.expects(:new).with { |key, options| options[:path] == "/some/file" }
- @file_server.find(@uri)
+ @file_server.find(@request)
end
it "should set the provided :links setting on to the instance if one is provided" do
@model.expects(:new).returns(@instance)
@instance.expects(:links=).with(:mytest)
- @file_server.find(@uri, :links => :mytest)
+ @request.options[:links] = :mytest
+ @file_server.find(@request)
end
it "should not set a :links value if no :links parameter is provided" do
@model.expects(:new).returns(@instance)
- @file_server.find(@uri)
+ @file_server.find(@request)
end
end
@@ -93,41 +97,52 @@ describe Puppet::Indirector::FileServer do
end
it "should deny the :destroy method" do
- @file_server.authorized?(:destroy, "whatever").should be_false
+ @request.method = :destroy
+ @file_server.authorized?(@request).should be_false
end
it "should deny the :save method" do
- @file_server.authorized?(:save, "whatever").should be_false
- end
+ @request.method = :save
+ @file_server.authorized?(@request).should be_false
+ end
+
+ describe "and finding file information" do
+ before do
+ @request.key = "puppetmounts://host/my/file"
+ @request.method = :find
+ end
- it "should use the file server configuration to determine authorization" do
- @configuration.expects(:authorized?)
- @file_server.authorized?(:find, "puppetmounts://host/my/file")
- end
+ it "should use the file server configuration to determine authorization" do
+ @configuration.expects(:authorized?)
+ @file_server.authorized?(@request)
+ end
- it "should pass the file path from the URI to the file server configuration" do
- @configuration.expects(:authorized?).with { |uri, *args| uri == "/my/file" }
- @file_server.authorized?(:find, "puppetmounts://host/my/file")
- end
+ it "should pass the file path from the URI to the file server configuration" do
+ @configuration.expects(:authorized?).with { |uri, *args| uri == "/my/file" }
+ @file_server.authorized?(@request)
+ end
- it "should pass the node name to the file server configuration" do
- @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" }
- @file_server.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode")
- end
+ it "should pass the node name to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" }
+ @request.node = "mynode"
+ @file_server.authorized?(@request)
+ end
- it "should pass the IP address to the file server configuration" do
- @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" }
- @file_server.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip")
- end
+ it "should pass the IP address to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" }
+ @request.ip = "myip"
+ @file_server.authorized?(@request)
+ end
- it "should return false if the file server configuration denies authorization" do
- @configuration.expects(:authorized?).returns(false)
- @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_false
- end
+ it "should return false if the file server configuration denies authorization" do
+ @configuration.expects(:authorized?).returns(false)
+ @file_server.authorized?(@request)
+ end
- it "should return true if the file server configuration approves authorization" do
- @configuration.expects(:authorized?).returns(true)
- @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_true
+ it "should return true if the file server configuration approves authorization" do
+ @configuration.expects(:authorized?).returns(true)
+ @file_server.authorized?(@request)
+ end
end
end
@@ -135,34 +150,35 @@ describe Puppet::Indirector::FileServer do
it "should use the path portion of the URI as the file name" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @file_server.search(@uri)
+ @file_server.search(@request)
end
it "should use the FileServing configuration to convert the file name to a fully qualified path" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @file_server.search(@uri)
+ @file_server.search(@request)
end
it "should pass the node name to the FileServing configuration if one is provided" do
@configuration.expects(:file_path).with("/my/local/file", :node => "testing")
- @file_server.search(@uri, :node => "testing")
+ @request.node = "testing"
+ @file_server.search(@request)
end
it "should return nil if no fully qualified path is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
- @file_server.search(@uri).should be_nil
+ @file_server.search(@request).should be_nil
end
it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
- @file_server.expects(:path2instances).with(@uri, "/my/file", {})
- @file_server.search(@uri)
+ @file_server.expects(:path2instances)
+ @file_server.search(@request)
end
- it "should pass any options on to :path2instances" do
+ it "should pass the request on to :path2instances" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
- @file_server.expects(:path2instances).with(@uri, "/my/file", :testing => :one, :other => :two)
- @file_server.search(@uri, :testing => :one, :other => :two)
+ @file_server.expects(:path2instances).with(@request, "/my/file")
+ @file_server.search(@request)
end
end
end
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb
index f5b92e1fd..32dedd4f1 100755
--- a/spec/unit/indirector/module_files.rb
+++ b/spec/unit/indirector/module_files.rb
@@ -27,61 +27,66 @@ describe Puppet::Indirector::ModuleFiles do
@uri = "puppetmounts://host/modules/my/local/file"
@module = Puppet::Module.new("mymod", "/module/path")
+
+ @request = stub 'request', :key => @uri, :options => {}, :node => nil, :ip => nil, :method => :find
end
describe Puppet::Indirector::ModuleFiles, " when finding files" do
it "should strip off the leading '/modules' mount name" do
Puppet::Module.expects(:find).with('my', "myenv").returns @module
- @module_files.find(@uri)
+ @module_files.find(@request)
end
it "should not strip off leading terms that start with '/modules' but are longer words" do
+ @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file"
Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil
- @module_files.find("puppetmounts://host/modulestart/my/local/file")
+ @module_files.find(@request)
end
it "should search for a module whose name is the first term in the remaining file path" do
Puppet::Module.expects(:find).with('my', "myenv").returns @module
- @module_files.find(@uri)
+ @module_files.find(@request)
end
it "should search for a file relative to the module's files directory" do
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file")
- @module_files.find(@uri)
+ @module_files.find(@request)
end
it "should return nil if the module does not exist" do
Puppet::Module.expects(:find).with('my', "myenv").returns nil
- @module_files.find(@uri).should be_nil
+ @module_files.find(@request).should be_nil
end
it "should return nil if the module exists but the file does not" do
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
- @module_files.find(@uri).should be_nil
+ @module_files.find(@request).should be_nil
end
it "should return an instance of the model if a module is found and the file exists" do
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
@model.expects(:new).returns(:myinstance)
- @module_files.find(@uri).should == :myinstance
+ @module_files.find(@request).should == :myinstance
end
it "should use the node's environment to look up the module if the node name is provided" do
node = stub "node", :environment => "testing"
Puppet::Node.expects(:find).with("mynode").returns(node)
Puppet::Module.expects(:find).with('my', "testing")
- @module_files.find(@uri, :node => "mynode")
+
+ @request.stubs(:node).returns "mynode"
+ @module_files.find(@request)
end
it "should use the default environment setting to look up the module if the node name is not provided" do
env = stub "environment", :name => "testing"
Puppet::Node::Environment.stubs(:new).returns(env)
Puppet::Module.expects(:find).with('my', "testing")
- @module_files.find(@uri)
+ @module_files.find(@request)
end
end
@@ -95,23 +100,25 @@ describe Puppet::Indirector::ModuleFiles do
it "should create the instance with the key used to find the instance" do
@model.expects(:new).with { |key, *options| key == @uri }
- @module_files.find(@uri)
+ @module_files.find(@request)
end
it "should create the instance with the path at which the instance was found" do
@model.expects(:new).with { |key, options| options[:path] == "/module/path/files/local/file" }
- @module_files.find(@uri)
+ @module_files.find(@request)
end
it "should set the provided :links setting on to the instance if one is provided" do
@model.expects(:new).returns(@instance)
@instance.expects(:links=).with(:mytest)
- @module_files.find(@uri, :links => :mytest)
+
+ @request.options[:links] = :mytest
+ @module_files.find(@request)
end
it "should not set a :links value if no :links parameter is provided" do
@model.expects(:new).returns(@instance)
- @module_files.find(@uri)
+ @module_files.find(@request)
end
end
@@ -127,46 +134,53 @@ describe Puppet::Indirector::ModuleFiles do
end
it "should deny the :destroy method" do
- @module_files.authorized?(:destroy, "whatever").should be_false
+ @request.expects(:method).returns :destroy
+ @module_files.authorized?(@request).should be_false
end
it "should deny the :save method" do
- @module_files.authorized?(:save, "whatever").should be_false
+ @request.expects(:method).returns :save
+ @module_files.authorized?(@request).should be_false
end
it "should use the file server configuration to determine authorization" do
@configuration.expects(:authorized?)
- @module_files.authorized?(:find, "puppetmounts://host/my/file")
+ @module_files.authorized?(@request)
end
it "should use the path directly from the URI if it already includes /modules" do
+ @request.expects(:key).returns "puppetmounts://host/modules/my/file"
@configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" }
- @module_files.authorized?(:find, "puppetmounts://host/modules/my/file")
+ @module_files.authorized?(@request)
end
it "should add /modules to the file path if it's not included in the URI" do
+ @request.expects(:key).returns "puppetmounts://host/my/file"
@configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" }
- @module_files.authorized?(:find, "puppetmounts://host/my/file")
+ @module_files.authorized?(@request)
end
it "should pass the node name to the file server configuration" do
+ @request.expects(:key).returns "puppetmounts://host/my/file"
@configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" }
- @module_files.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode")
+ @request.stubs(:node).returns "mynode"
+ @module_files.authorized?(@request)
end
it "should pass the IP address to the file server configuration" do
+ @request.expects(:ip).returns "myip"
@configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" }
- @module_files.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip")
+ @module_files.authorized?(@request)
end
it "should return false if the file server configuration denies authorization" do
@configuration.expects(:authorized?).returns(false)
- @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_false
+ @module_files.authorized?(@request).should be_false
end
it "should return true if the file server configuration approves authorization" do
@configuration.expects(:authorized?).returns(true)
- @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_true
+ @module_files.authorized?(@request).should be_true
end
end
@@ -175,69 +189,71 @@ describe Puppet::Indirector::ModuleFiles do
it "should strip off the leading '/modules' mount name" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
- @module_files.search(@uri)
+ @module_files.search(@request)
end
it "should not strip off leading terms that start with '/modules' but are longer words" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil
- @module_files.search("puppetmounts://host/modulestart/my/local/file")
+ @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file"
+ @module_files.search @request
end
it "should search for a module whose name is the first term in the remaining file path" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
- @module_files.search(@uri)
+ @module_files.search(@request)
end
it "should search for a file relative to the module's files directory" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file")
- @module_files.search(@uri)
+ @module_files.search(@request)
end
it "should return nil if the module does not exist" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns nil
- @module_files.search(@uri).should be_nil
+ @module_files.search(@request).should be_nil
end
it "should return nil if the module exists but the file does not" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
- @module_files.search(@uri).should be_nil
+ @module_files.search(@request).should be_nil
end
it "should use the node's environment to look up the module if the node name is provided" do
node = stub "node", :environment => "testing"
Puppet::Node.expects(:find).with("mynode").returns(node)
Puppet::Module.expects(:find).with('my', "testing")
- @module_files.search(@uri, :node => "mynode")
+ @request.stubs(:node).returns "mynode"
+ @module_files.search(@request)
end
it "should use the default environment setting to look up the module if the node name is not provided and the environment is not set to ''" do
env = stub 'env', :name => "testing"
Puppet::Node::Environment.stubs(:new).returns(env)
Puppet::Module.expects(:find).with('my', "testing")
- @module_files.search(@uri)
+ @module_files.search(@request)
end
it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
- @module_files.expects(:path2instances).with(@uri, "/module/path/files/local/file", {})
- @module_files.search(@uri)
+ @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file")
+ @module_files.search(@request)
end
- it "should pass any options on to :path2instances" do
+ it "should pass the request directly to :path2instances" do
Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
Puppet::Module.expects(:find).with('my', "myenv").returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
- @module_files.expects(:path2instances).with(@uri, "/module/path/files/local/file", :testing => :one, :other => :two)
- @module_files.search(@uri, :testing => :one, :other => :two)
+ @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file")
+ @module_files.search(@request)
end
end
end