summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-05 00:08:15 -0500
committerLuke Kanies <luke@madstop.com>2007-10-05 00:08:15 -0500
commit275af562b462813ddf5ddbad2192ddc2bf57770c (patch)
treeaceabf68095b8c34fd599f245022a9aaab0984da /spec
parentce0178316d8cefd072f53d39b59ce47332f6ec8f (diff)
parent29accba1b9343f4967c15d36506b3bf60d5f0f9c (diff)
downloadpuppet-275af562b462813ddf5ddbad2192ddc2bf57770c.tar.gz
puppet-275af562b462813ddf5ddbad2192ddc2bf57770c.tar.xz
puppet-275af562b462813ddf5ddbad2192ddc2bf57770c.zip
Merge branch 'routing' of http://git.rickbradley.com/puppet into routing
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/network/rest_server.rb131
-rwxr-xr-xspec/unit/node/configuration.rb20
-rwxr-xr-xspec/unit/other/modules.rb51
-rwxr-xr-xspec/unit/other/transobject.rb1
-rwxr-xr-xspec/unit/parser/interpreter.rb51
-rwxr-xr-xspec/unit/util/settings.rb19
6 files changed, 223 insertions, 50 deletions
diff --git a/spec/unit/network/rest_server.rb b/spec/unit/network/rest_server.rb
index 156e11b08..408bb36b3 100644
--- a/spec/unit/network/rest_server.rb
+++ b/spec/unit/network/rest_server.rb
@@ -7,31 +7,130 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/rest_server'
+describe Puppet::Network::RESTServer, "when initializing" do
+ it "should require specifying which HTTP server will be used to provide access to clients" do
+ Proc.new { Puppet::Network::RESTServer.new }.should raise_error(ArgumentError)
+ end
+end
+
describe Puppet::Network::RESTServer, "in general" do
- it "should provide a way to specify that an indirection is to be made accessible to clients"
- it "should provide a way to specify that an indirection is to no longer be made accessible to clients"
+ before do
+ @server = Puppet::Network::RESTServer.new(:server => :mongrel)
+ end
+
+ it "should allow registering an indirection for client access by specifying its indirection name" do
+ Proc.new { @server.register(:foo) }.should_not raise_error
+ end
+
+ it "should require at least one indirection name when registering indirections for client access" do
+ Proc.new { @server.register }.should raise_error(ArgumentError)
+ end
+
+ it "should allow for numerous indirections to be registered at once for client access" do
+ Proc.new { @server.register(:foo, :bar, :baz) }.should_not raise_error
+ end
+
+ it "should allow the use of indirection names to specify which indirections are to be no longer accessible to clients" do
+ @server.register(:foo)
+ Proc.new { @server.unregister(:foo) }.should_not raise_error
+ end
+
+ it "should leave other indirections accessible to clients when turning off indirections" do
+ @server.register(:foo, :bar)
+ @server.unregister(:foo)
+ Proc.new { @server.unregister(:bar)}.should_not raise_error
+ end
+
+ it "should allow specifying numerous indirections which are to be no longer accessible to clients" do
+ @server.register(:foo, :bar)
+ Proc.new { @server.unregister(:foo, :bar) }.should_not raise_error
+ end
+
+ it "should not allow turning off unknown indirection names" do
+ @server.register(:foo, :bar)
+ Proc.new { @server.unregister(:baz) }.should raise_error(ArgumentError)
+ end
+
+ it "should disable client access immediately when turning off indirections" do
+ @server.register(:foo, :bar)
+ @server.unregister(:foo)
+ Proc.new { @server.unregister(:foo) }.should raise_error(ArgumentError)
+ end
+
+ it "should allow turning off all indirections at once" do
+ @server.register(:foo, :bar)
+ @server.unregister
+ [ :foo, :bar, :baz].each do |indirection|
+ Proc.new { @server.unregister(indirection) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "should provide a means of determining whether it is listening" do
+ @server.should respond_to(:listening?)
+ end
+
+ it "should provide a means of determining which HTTP server will be used to provide access to clients" do
+ @server.server.should == :mongrel
+ end
+
+ it "should allow for multiple configurations, each allowing a different HTTP server handling different indirections" do
+ @server2 = Puppet::Network::RESTServer.new(:server => :webrick)
+ @server.register(:foo, :bar)
+ @server2.register(:foo, :xyzzy)
+ @server.unregister(:foo, :bar)
+ @server2.unregister(:foo, :xyzzy)
+ Proc.new { @server.unregister(:xyzzy) }.should raise_error(ArgumentError)
+ Proc.new { @server2.unregister(:bar)}.should raise_error(ArgumentError)
+ end
end
describe Puppet::Network::RESTServer, "when listening is not turned on" do
- it "should allow picking which technology to use to make indirections accessible to clients"
- it "should allow listening to be turned on"
- it "should not allow listening to be turned off"
- it "should not route HTTP GET requests on indirector's name to indirector find for the specified technology"
- it "should not route HTTP GET requests on indirector's plural name to indirector search for the specified technology"
- it "should not route HTTP DELETE requests on indirector's name to indirector destroy for the specified technology"
- it "should not route HTTP POST requests on indirector's name to indirector save for the specified technology"
+ before do
+ @server = Puppet::Network::RESTServer.new(:server => :mongrel)
+ end
+
+ it "should allow listening to be turned on" do
+ Proc.new { @server.listen }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned off" do
+ Proc.new { @server.unlisten }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that it is not listening" do
+ @server.should_not be_listening
+ end
+
+ it "should not route HTTP GET requests on indirector's name to indirector find for the specified HTTP server"
+ it "should not route HTTP GET requests on indirector's plural name to indirector search for the specified HTTP server"
+ it "should not route HTTP DELETE requests on indirector's name to indirector destroy for the specified HTTP server"
+ it "should not route HTTP POST requests on indirector's name to indirector save for the specified HTTP server"
# TODO: FIXME write integrations which fire up actual webrick / mongrel servers and are thus webrick / mongrel specific?]
end
describe Puppet::Network::RESTServer, "when listening is turned on" do
- it "should not allow picking which technology to use to make indirections accessible to clients"
- it "should allow listening to be turned off"
- it "should not allow listening to be turned on"
- it "should route HTTP GET requests on indirector's name to indirector find for the specified technology"
- it "should route HTTP GET requests on indirector's plural name to indirector search for the specified technology"
- it "should route HTTP DELETE requests on indirector's name to indirector destroy for the specified technology"
- it "should route HTTP POST requests on indirector's name to indirector save for the specified technology"
+ before do
+ @server = Puppet::Network::RESTServer.new(:server => :mongrel)
+ @server.listen
+ end
+
+ it "should allow listening to be turned off" do
+ Proc.new { @server.unlisten }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned on" do
+ Proc.new { @server.listen }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that it is listening" do
+ @server.should be_listening
+ end
+
+ it "should route HTTP GET requests on indirector's name to indirector find for the specified HTTP server"
+ it "should route HTTP GET requests on indirector's plural name to indirector search for the specified HTTP server"
+ it "should route HTTP DELETE requests on indirector's name to indirector destroy for the specified HTTP server"
+ it "should route HTTP POST requests on indirector's name to indirector save for the specified HTTP server"
# TODO: FIXME [ write integrations which fire up actual webrick / mongrel servers and are thus webrick / mongrel specific?]
end
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index 8ba55f50c..6b0677973 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -68,6 +68,23 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do
Puppet::Parser::Resource.new(:type => type, :title => name, :source => @source, :scope => @scope)
end
+ it "should always create a TransBucket for the 'main' class" do
+ config = Puppet::Node::Configuration.new("mynode")
+
+ @scope = mkscope
+ @source = mock 'source'
+
+ main = mkresource("class", :main)
+ config.add_vertex!(main)
+
+ bucket = mock 'bucket'
+ bucket.expects(:classes=).with(config.classes)
+ main.stubs(:builtin?).returns(false)
+ main.expects(:to_transbucket).returns(bucket)
+
+ config.extract_to_transportable.should equal(bucket)
+ end
+
# This isn't really a spec-style test, but I don't know how better to do it.
it "should transform the resource graph into a tree of TransBuckets and TransObjects" do
config = Puppet::Node::Configuration.new("mynode")
@@ -283,12 +300,14 @@ describe Puppet::Node::Configuration, " when applying host configurations" do
it "should send a report if reporting is enabled" do
Puppet[:report] = true
@transaction.expects :send_report
+ @transaction.stubs :any_failed? => false
@config.apply
end
it "should send a report if report summaries are enabled" do
Puppet[:summarize] = true
@transaction.expects :send_report
+ @transaction.stubs :any_failed? => false
@config.apply
end
@@ -302,6 +321,7 @@ describe Puppet::Node::Configuration, " when applying host configurations" do
it "should sync the state database after applying" do
Puppet::Util::Storage.expects(:store)
+ @transaction.stubs :any_failed? => false
@config.apply
end
diff --git a/spec/unit/other/modules.rb b/spec/unit/other/modules.rb
index f53c43e89..26ca3907d 100755
--- a/spec/unit/other/modules.rb
+++ b/spec/unit/other/modules.rb
@@ -108,22 +108,55 @@ describe Puppet::Module, " when searching for templates" do
after { Puppet.settings.clear }
end
-describe Puppet::Module, " when searching for manifests" do
- it "should return the manifests from the first found module" do
- Puppet[:modulepath] = "/one:/two"
- File.stubs(:directory?).returns(true)
- Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp})
- Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"]
+describe Puppet::Module, " when searching for manifests when no module is found" do
+ before do
+ File.stubs(:find).returns(nil)
end
- it "should search the cwd if no module is found" do
- Puppet[:modulepath] = "/one:/two"
- File.stubs(:find).returns(nil)
+ it "should not look for modules when paths are fully qualified" do
+ Puppet.expects(:value).with(:modulepath).never
+ file = "/fully/qualified/file.pp"
+ Dir.stubs(:glob).with(file).returns([file])
+ Puppet::Module.find_manifests(file)
+ end
+
+ it "should directly return fully qualified files" do
+ file = "/fully/qualified/file.pp"
+ Dir.stubs(:glob).with(file).returns([file])
+ Puppet::Module.find_manifests(file).should == [file]
+ end
+
+ it "should match against provided fully qualified patterns" do
+ pattern = "/fully/qualified/pattern/*"
+ Dir.expects(:glob).with(pattern).returns(%w{my file list})
+ Puppet::Module.find_manifests(pattern).should == %w{my file list}
+ end
+
+ it "should look for files relative to the current directory" do
cwd = Dir.getwd
Dir.expects(:glob).with("#{cwd}/mymod/init.pp").returns(["#{cwd}/mymod/init.pp"])
Puppet::Module.find_manifests("mymod/init.pp").should == ["#{cwd}/mymod/init.pp"]
end
+ it "should only return files, not directories" do
+ pattern = "/fully/qualified/pattern/*"
+ file = "/my/file"
+ dir = "/my/directory"
+ Dir.expects(:glob).with(pattern).returns([file, dir])
+ FileTest.expects(:directory?).with(file).returns(false)
+ FileTest.expects(:directory?).with(dir).returns(true)
+ Puppet::Module.find_manifests(pattern).should == [file]
+ end
+end
+
+describe Puppet::Module, " when searching for manifests in a found module" do
+ it "should return the manifests from the first found module" do
+ Puppet[:modulepath] = "/one:/two"
+ File.stubs(:directory?).returns(true)
+ Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp})
+ Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"]
+ end
+
it "should use the node environment if specified" do
Puppet.settings.expects(:value).with(:modulepath, "myenv").returns("/env/modules")
File.stubs(:directory?).returns(true)
diff --git a/spec/unit/other/transobject.rb b/spec/unit/other/transobject.rb
index 07c9dc761..144940b7e 100755
--- a/spec/unit/other/transobject.rb
+++ b/spec/unit/other/transobject.rb
@@ -113,4 +113,3 @@ class TestTransportable < Test::Unit::TestCase
end
end
-# $Id$
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb
index a79267b52..b4aa2a2d1 100755
--- a/spec/unit/parser/interpreter.rb
+++ b/spec/unit/parser/interpreter.rb
@@ -100,12 +100,7 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do
@parser = mock('parser')
end
- it "it should an exception when nothing is there and nil is returned" do
- @interp.expects(:create_parser).with(:myenv).returns(nil)
- @interp.send(:parser, :myenv).should be_nil
- end
-
- it "should create and return a new parser and use the same parser when the parser does not need reparsing" do
+ it "should use the same parser when the parser does not need reparsing" do
@interp.expects(:create_parser).with(:myenv).returns(@parser)
@interp.send(:parser, :myenv).should equal(@parser)
@@ -125,7 +120,12 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do
@interp.send(:parser, :myenv).should equal(newparser)
end
- it "should keep the old parser if create_parser doesn't return anything." do
+ it "should fail intelligently if a parser cannot be created and one does not already exist" do
+ @interp.expects(:create_parser).with(:myenv).raises(ArgumentError)
+ proc { @interp.send(:parser, :myenv) }.should raise_error(ArgumentError)
+ end
+
+ it "should keep the old parser if a new parser cannot be created" do
# Get the first parser in the hash.
@interp.expects(:create_parser).with(:myenv).returns(@parser)
@interp.send(:parser, :myenv).should equal(@parser)
@@ -134,7 +134,7 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do
@parser.expects(:reparse?).returns(true)
# But fail to create a new parser
- @interp.expects(:create_parser).with(:myenv).returns(nil)
+ @interp.expects(:create_parser).with(:myenv).raises(ArgumentError)
# And make sure we still get the old valid parser
@interp.send(:parser, :myenv).should equal(@parser)
@@ -154,27 +154,30 @@ end
describe Puppet::Parser::Interpreter, " when compiling configurations" do
before do
@interp = Puppet::Parser::Interpreter.new
+ @node = stub 'node', :environment => :myenv
+ @compile = mock 'compile'
+ @parser = mock 'parser'
end
- it "should create a configuration with the node, parser, and whether to use ast nodes" do
- node = mock('node')
- node.expects(:environment).returns(:myenv)
- compile = mock 'compile'
- compile.expects(:compile).returns(:config)
- parser = mock 'parser'
- @interp.expects(:parser).with(:myenv).returns(parser)
+ it "should create a compile with the node, parser, and whether to use ast nodes when ast nodes is true" do
+ @compile.expects(:compile).returns(:config)
+ @interp.expects(:parser).with(:myenv).returns(@parser)
@interp.expects(:usenodes?).returns(true)
- Puppet::Parser::Compile.expects(:new).with(node, parser, :ast_nodes => true).returns(compile)
- @interp.compile(node)
+ Puppet::Parser::Compile.expects(:new).with(@node, @parser, :ast_nodes => true).returns(@compile)
+ @interp.compile(@node)
+ end
- # Now try it when usenodes is true
- @interp = Puppet::Parser::Interpreter.new :UseNodes => false
- node.expects(:environment).returns(:myenv)
- compile.expects(:compile).returns(:config)
- @interp.expects(:parser).with(:myenv).returns(parser)
+ it "should create a compile with the node, parser, and whether to use ast nodes when ast nodes is false" do
+ @compile.expects(:compile).returns(:config)
+ @interp.expects(:parser).with(:myenv).returns(@parser)
@interp.expects(:usenodes?).returns(false)
- Puppet::Parser::Compile.expects(:new).with(node, parser, :ast_nodes => false).returns(compile)
- @interp.compile(node).should equal(:config)
+ Puppet::Parser::Compile.expects(:new).with(@node, @parser, :ast_nodes => false).returns(@compile)
+ @interp.compile(@node).should equal(:config)
+ end
+
+ it "should fail intelligently when no parser can be found" do
+ @interp.expects(:parser).with(:myenv).returns(nil)
+ proc { @interp.compile(@node) }.should raise_error(Puppet::ParseError)
end
end
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index 8d11737b3..e647ce1cd 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -395,6 +395,17 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d
@settings.setdefaults :files, :myfile => {:default => "/myfile", :desc => "a", :mode => 0755}
end
+ def stub_transaction
+ @bucket = mock 'bucket'
+ @config = mock 'config'
+ @trans = mock 'transaction'
+
+ @settings.expects(:to_transportable).with(:whatever).returns(@bucket)
+ @bucket.expects(:to_configuration).returns(@config)
+ @config.expects(:apply).yields(@trans)
+ @config.stubs(:host_config=)
+ end
+
it "should provide a method that writes files with the correct modes" do
pending "Not converted from test/unit yet"
end
@@ -518,6 +529,7 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d
Puppet::Util::Storage.expects(:store).never
Puppet::Util::Storage.expects(:load).never
Dir.expects(:mkdir).with("/maindir")
+ Dir.expects(:mkdir).with("/seconddir")
@settings.use(:main)
end
@@ -532,4 +544,11 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d
@settings.use(:other)
@settings.reuse
end
+
+ it "should fail if any resources fail" do
+ stub_transaction
+ @trans.expects(:any_failed?).returns(true)
+
+ proc { @settings.use(:whatever) }.should raise_error(RuntimeError)
+ end
end