summaryrefslogtreecommitdiffstats
path: root/spec/unit/application
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/application')
-rwxr-xr-xspec/unit/application/puppet.rb41
-rwxr-xr-xspec/unit/application/puppetd.rb1
-rwxr-xr-xspec/unit/application/puppetdoc.rb6
-rw-r--r--spec/unit/application/puppetmasterd.rb1
-rwxr-xr-xspec/unit/application/puppetrun.rb14
-rwxr-xr-xspec/unit/application/ralsh.rb61
6 files changed, 67 insertions, 57 deletions
diff --git a/spec/unit/application/puppet.rb b/spec/unit/application/puppet.rb
index 8fb364cdd..be200bb89 100755
--- a/spec/unit/application/puppet.rb
+++ b/spec/unit/application/puppet.rb
@@ -317,70 +317,51 @@ describe "Puppet" do
end
describe "the 'apply' command" do
- confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson?
-
- before do
- #Puppet::Resource::Catalog.stubs(:pson_create).returns Puppet::Resource::Catalog.new
- PSON.stubs(:parse).returns Puppet::Resource::Catalog.new
- end
-
it "should read the catalog in from disk if a file name is provided" do
@puppet.options[:catalog] = "/my/catalog.pson"
-
File.expects(:read).with("/my/catalog.pson").returns "something"
-
+ Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new
@puppet.apply
end
it "should read the catalog in from stdin if '-' is provided" do
@puppet.options[:catalog] = "-"
-
$stdin.expects(:read).returns "something"
-
+ Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new
@puppet.apply
end
- it "should deserialize the catalog from pson" do
+ it "should deserialize the catalog from the default format" do
@puppet.options[:catalog] = "/my/catalog.pson"
-
- File.expects(:read).returns "something"
- PSON.expects(:parse).with("something").returns Puppet::Resource::Catalog.new
-
+ File.stubs(:read).with("/my/catalog.pson").returns "something"
+ Puppet::Resource::Catalog.stubs(:default_format).returns :rot13_piglatin
+ Puppet::Resource::Catalog.stubs(:convert_from).with(:rot13_piglatin,'something').returns Puppet::Resource::Catalog.new
@puppet.apply
end
it "should fail helpfully if deserializing fails" do
@puppet.options[:catalog] = "/my/catalog.pson"
-
- File.expects(:read).returns "something"
- PSON.expects(:parse).raises ArgumentError
-
+ File.stubs(:read).with("/my/catalog.pson").returns "something syntacically invalid"
lambda { @puppet.apply }.should raise_error(Puppet::Error)
end
it "should convert plain data structures into a catalog if deserialization does not do so" do
@puppet.options[:catalog] = "/my/catalog.pson"
-
- File.expects(:read).returns "something"
- PSON.expects(:parse).with("something").returns({:foo => "bar"})
+ File.stubs(:read).with("/my/catalog.pson").returns "something"
+ Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,"something").returns({:foo => "bar"})
Puppet::Resource::Catalog.expects(:pson_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new)
-
@puppet.apply
end
it "should convert the catalog to a RAL catalog and use a Configurer instance to apply it" do
@puppet.options[:catalog] = "/my/catalog.pson"
-
- File.expects(:read).returns "something"
-
+ File.stubs(:read).with("/my/catalog.pson").returns "something"
catalog = Puppet::Resource::Catalog.new
- PSON.expects(:parse).returns catalog
-
+ Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns catalog
catalog.expects(:to_ral).returns "mycatalog"
configurer = stub 'configurer'
Puppet::Configurer.expects(:new).returns configurer
-
configurer.expects(:run).with(:catalog => "mycatalog")
@puppet.apply
diff --git a/spec/unit/application/puppetd.rb b/spec/unit/application/puppetd.rb
index 04c6daf32..9b8d1bea3 100755
--- a/spec/unit/application/puppetd.rb
+++ b/spec/unit/application/puppetd.rb
@@ -173,6 +173,7 @@ describe "puppetd" do
Puppet.stubs(:info)
FileTest.stubs(:exists?).returns(true)
Puppet.stubs(:[])
+ Puppet.stubs(:[]).with(:libdir).returns("/dev/null/lib")
Puppet.settings.stubs(:print_config?)
Puppet.settings.stubs(:print_config)
Puppet::SSL::Host.stubs(:ca_location=)
diff --git a/spec/unit/application/puppetdoc.rb b/spec/unit/application/puppetdoc.rb
index cb60581a4..413fa1186 100755
--- a/spec/unit/application/puppetdoc.rb
+++ b/spec/unit/application/puppetdoc.rb
@@ -293,7 +293,7 @@ describe "puppetdoc" do
@env = stub 'env'
Puppet::Node::Environment.stubs(:new).returns(@env)
@env.stubs(:modulepath).returns(['modules'])
- @env.stubs(:manifestdir).returns(['manifests'])
+ @env.stubs(:[]).with(:manifest).returns('manifests/site.pp')
@puppetdoc.options.stubs(:[]).with(:all).returns(false)
@puppetdoc.options.stubs(:[]).with(:outputdir).returns('doc')
Puppet.settings.stubs(:[]=).with(:document_all, false)
@@ -334,9 +334,9 @@ describe "puppetdoc" do
it "should get modulepath and manifestdir values from the environment" do
@env.expects(:modulepath).returns(['envmodules1','envmodules2'])
- @env.expects(:manifestdir).returns(['envmanifests1','envmanifests2'])
+ @env.expects(:[]).with(:manifest).returns('envmanifests/site.pp')
- Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests1','envmanifests2'])
+ Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests'])
@puppetdoc.rdoc
end
diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/puppetmasterd.rb
index 980138782..f522fccc1 100644
--- a/spec/unit/application/puppetmasterd.rb
+++ b/spec/unit/application/puppetmasterd.rb
@@ -237,6 +237,7 @@ describe "PuppetMaster" do
it "should dispatch to parseonly if parseonly is set" do
Puppet.stubs(:[]).with(:parseonly).returns(true)
+ @puppetmasterd.options[:node] = nil
@puppetmasterd.get_command.should == :parseonly
end
diff --git a/spec/unit/application/puppetrun.rb b/spec/unit/application/puppetrun.rb
index d44b406e9..26811f0db 100755
--- a/spec/unit/application/puppetrun.rb
+++ b/spec/unit/application/puppetrun.rb
@@ -144,11 +144,21 @@ describe "puppetrun" do
Puppet.stubs(:[]).with(:node_terminus).returns("ldap")
end
+ it "should pass the fqdn option to search" do
+ @puppetrun.options.stubs(:[]).with(:fqdn).returns(:something)
+ @puppetrun.options.stubs(:[]).with(:all).returns(true)
+ @puppetrun.stubs(:puts)
+
+ Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([])
+
+ @puppetrun.run_setup
+ end
+
it "should search for all nodes if --all" do
@puppetrun.options.stubs(:[]).with(:all).returns(true)
@puppetrun.stubs(:puts)
- Puppet::Node.expects(:search).with("whatever").returns([])
+ Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([])
@puppetrun.run_setup
end
@@ -158,7 +168,7 @@ describe "puppetrun" do
@puppetrun.stubs(:puts)
@puppetrun.classes = ['class']
- Puppet::Node.expects(:search).with("whatever", :class => "class").returns([])
+ Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
@puppetrun.run_setup
end
diff --git a/spec/unit/application/ralsh.rb b/spec/unit/application/ralsh.rb
index dbc196cdf..b0fa3bdc2 100755
--- a/spec/unit/application/ralsh.rb
+++ b/spec/unit/application/ralsh.rb
@@ -132,17 +132,34 @@ describe "ralsh" do
describe "when running" do
+ def set_args(args)
+ (ARGV.clear << args).flatten!
+ end
+
+ def push_args(*args)
+ @args_stack ||= []
+ @args_stack << ARGV.dup
+ set_args(args)
+ end
+
+ def pop_args
+ set_args(@args_stack.pop)
+ end
+
before :each do
@type = stub_everything 'type', :properties => []
- ARGV.stubs(:shift).returns("type")
- ARGV.stubs(:length).returns(1).then.returns(0)
+ push_args('type')
Puppet::Type.stubs(:type).returns(@type)
end
- it "should raise an error if no type is given" do
- ARGV.stubs(:length).returns(0)
+ after :each do
+ pop_args
+ end
+ it "should raise an error if no type is given" do
+ push_args
lambda { @ralsh.main }.should raise_error
+ pop_args
end
it "should raise an error when editing a remote host" do
@@ -186,11 +203,10 @@ describe "ralsh" do
end
it "should describe the given resource" do
- ARGV.stubs(:shift).returns("type").then.returns('name')
- ARGV.stubs(:length).returns(1).then.returns(1).then.returns(0)
+ push_args('type','name')
@client.expects(:describe).returns(stub_everything)
-
@ralsh.main
+ pop_args
end
end
@@ -208,30 +224,31 @@ describe "ralsh" do
describe 'but with a given name' do
before :each do
- ARGV.stubs(:shift).returns("type").then.returns('name')
- ARGV.stubs(:length).returns(1).then.returns(1).then.returns(0)
- @object = stub_everything 'object', :to_trans => stub_everything('transportable')
- @type.stubs(:new).returns(@object)
- @object.stubs(:retrieve)
+ push_args('type','name')
+ @type.stubs(:new).returns(:bob)
end
- it "should retrieve a specific instance" do
- @type.expects(:new).returns(@object)
- @object.expects(:retrieve)
+ after :each do
+ pop_args
+ end
- @ralsh.main
+ it "should retrieve a specific instance if it exists" do
+ pending
end
- it "should add given parameters to object" do
- ARGV.stubs(:each).yields('param=temp')
- ARGV.stubs(:length).returns(1).then.returns(1).then.returns(1)
- Puppet::Resource::Catalog.stubs(:new).returns(stub_everything)
- @object.expects(:[]=).with('param','temp')
+ it "should create a stub instance if it doesn't exist" do
+ pending
+ end
+
+ it "should add given parameters to the object" do
+ push_args('type','name','param=temp')
+ pending
+ @object.expects(:[]=).with('param','temp')
@ralsh.main
+ pop_args
end
end
end
-
end
end