summaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration')
-rwxr-xr-xspec/integration/application/apply_spec.rb32
-rwxr-xr-xspec/integration/configurer_spec.rb40
-rwxr-xr-xspec/integration/defaults_spec.rb396
-rwxr-xr-xspec/integration/file_serving/content_spec.rb12
-rwxr-xr-xspec/integration/file_serving/fileset_spec.rb10
-rwxr-xr-xspec/integration/file_serving/metadata_spec.rb12
-rwxr-xr-xspec/integration/file_serving/terminus_helper_spec.rb20
-rw-r--r--spec/integration/indirector/bucket_file/rest_spec.rb116
-rwxr-xr-xspec/integration/indirector/catalog/compiler_spec.rb116
-rwxr-xr-xspec/integration/indirector/catalog/queue_spec.rb70
-rwxr-xr-xspec/integration/indirector/certificate/rest_spec.rb116
-rwxr-xr-xspec/integration/indirector/certificate_request/rest_spec.rb156
-rwxr-xr-xspec/integration/indirector/certificate_revocation_list/rest_spec.rb132
-rwxr-xr-xspec/integration/indirector/direct_file_server_spec.rb104
-rwxr-xr-xspec/integration/indirector/file_content/file_server_spec.rb114
-rwxr-xr-xspec/integration/indirector/file_metadata/file_server_spec.rb10
-rwxr-xr-xspec/integration/indirector/node/ldap_spec.rb12
-rw-r--r--spec/integration/indirector/report/rest_spec.rb168
-rwxr-xr-xspec/integration/indirector/rest_spec.rb966
-rwxr-xr-xspec/integration/network/client_spec.rb18
-rwxr-xr-xspec/integration/network/formats_spec.rb154
-rwxr-xr-xspec/integration/network/handler_spec.rb26
-rwxr-xr-xspec/integration/network/server/mongrel_spec.rb96
-rwxr-xr-xspec/integration/network/server/webrick_spec.rb150
-rwxr-xr-xspec/integration/node/environment_spec.rb94
-rwxr-xr-xspec/integration/node/facts_spec.rb52
-rwxr-xr-xspec/integration/node_spec.rb162
-rwxr-xr-xspec/integration/parser/collector_spec.rb50
-rwxr-xr-xspec/integration/parser/compiler_spec.rb34
-rwxr-xr-xspec/integration/parser/functions/require_spec.rb74
-rwxr-xr-xspec/integration/parser/parser_spec.rb186
-rwxr-xr-xspec/integration/provider/mailalias/aliases_spec.rb22
-rwxr-xr-xspec/integration/provider/package_spec.rb30
-rwxr-xr-xspec/integration/provider/service/init_spec.rb30
-rwxr-xr-xspec/integration/reference/providers_spec.rb12
-rwxr-xr-xspec/integration/reports_spec.rb12
-rwxr-xr-xspec/integration/resource/catalog_spec.rb76
-rwxr-xr-xspec/integration/resource/type_collection_spec.rb142
-rwxr-xr-xspec/integration/ssl/certificate_authority_spec.rb178
-rwxr-xr-xspec/integration/ssl/certificate_request_spec.rb70
-rwxr-xr-xspec/integration/ssl/certificate_revocation_list_spec.rb44
-rwxr-xr-xspec/integration/ssl/host_spec.rb114
-rwxr-xr-xspec/integration/transaction/report_spec.rb26
-rwxr-xr-xspec/integration/transaction_spec.rb380
-rwxr-xr-xspec/integration/type/file_spec.rb698
-rwxr-xr-xspec/integration/type/package_spec.rb30
-rwxr-xr-xspec/integration/type/tidy_spec.rb34
-rwxr-xr-xspec/integration/type_spec.rb22
-rwxr-xr-xspec/integration/util/autoload_spec.rb198
-rwxr-xr-xspec/integration/util/feature_spec.rb72
-rwxr-xr-xspec/integration/util/file_locking_spec.rb52
-rwxr-xr-xspec/integration/util/rdoc/parser_spec.rb84
-rwxr-xr-xspec/integration/util/settings_spec.rb32
53 files changed, 3028 insertions, 3028 deletions
diff --git a/spec/integration/application/apply_spec.rb b/spec/integration/application/apply_spec.rb
index c6e73e880..840917eff 100755
--- a/spec/integration/application/apply_spec.rb
+++ b/spec/integration/application/apply_spec.rb
@@ -7,27 +7,27 @@ require 'puppet_spec/files'
require 'puppet/application/apply'
describe "apply" do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- describe "when applying provided catalogs" do
- confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson?
- it "should be able to apply catalogs provided in a file in pson" do
- file_to_create = tmpfile("pson_catalog")
- catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Resource.new(:file, file_to_create, :parameters => {:content => "my stuff"})
- catalog.add_resource resource
+ describe "when applying provided catalogs" do
+ confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson?
+ it "should be able to apply catalogs provided in a file in pson" do
+ file_to_create = tmpfile("pson_catalog")
+ catalog = Puppet::Resource::Catalog.new
+ resource = Puppet::Resource.new(:file, file_to_create, :parameters => {:content => "my stuff"})
+ catalog.add_resource resource
- manifest = tmpfile("manifest")
+ manifest = tmpfile("manifest")
- File.open(manifest, "w") { |f| f.print catalog.to_pson }
+ File.open(manifest, "w") { |f| f.print catalog.to_pson }
- puppet = Puppet::Application[:apply]
- puppet.options[:catalog] = manifest
+ puppet = Puppet::Application[:apply]
+ puppet.options[:catalog] = manifest
- puppet.apply
+ puppet.apply
- File.should be_exist(file_to_create)
- File.read(file_to_create).should == "my stuff"
- end
+ File.should be_exist(file_to_create)
+ File.read(file_to_create).should == "my stuff"
end
+ end
end
diff --git a/spec/integration/configurer_spec.rb b/spec/integration/configurer_spec.rb
index fce24a1b2..9a8b66fe4 100755
--- a/spec/integration/configurer_spec.rb
+++ b/spec/integration/configurer_spec.rb
@@ -5,31 +5,31 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/configurer'
describe Puppet::Configurer do
- describe "when downloading plugins" do
- it "should use the :pluginsignore setting, split on whitespace, for ignoring remote files" do
- resource = Puppet::Type.type(:notify).new :name => "yay"
- Puppet::Type.type(:file).expects(:new).with { |args| args[:ignore] == Puppet[:pluginsignore].split(/\s+/) }.returns resource
-
- configurer = Puppet::Configurer.new
- configurer.stubs(:download_plugins?).returns true
- configurer.download_plugins
- end
+ describe "when downloading plugins" do
+ it "should use the :pluginsignore setting, split on whitespace, for ignoring remote files" do
+ resource = Puppet::Type.type(:notify).new :name => "yay"
+ Puppet::Type.type(:file).expects(:new).with { |args| args[:ignore] == Puppet[:pluginsignore].split(/\s+/) }.returns resource
+
+ configurer = Puppet::Configurer.new
+ configurer.stubs(:download_plugins?).returns true
+ configurer.download_plugins
end
+ end
- describe "when running" do
- it "should send a transaction report with valid data" do
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource(Puppet::Type.type(:notify).new(:title => "testing"))
+ describe "when running" do
+ it "should send a transaction report with valid data" do
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource(Puppet::Type.type(:notify).new(:title => "testing"))
- configurer = Puppet::Configurer.new
+ configurer = Puppet::Configurer.new
- Puppet::Transaction::Report.indirection.expects(:save).with do |x, report|
- report.time.class == Time and report.logs.length > 0
- end
+ Puppet::Transaction::Report.indirection.expects(:save).with do |x, report|
+ report.time.class == Time and report.logs.length > 0
+ end
- Puppet[:report] = true
+ Puppet[:report] = true
- configurer.run :catalog => catalog
- end
+ configurer.run :catalog => catalog
end
+ end
end
diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb
index 3fa753823..4ae2983f4 100755
--- a/spec/integration/defaults_spec.rb
+++ b/spec/integration/defaults_spec.rb
@@ -5,254 +5,254 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/defaults'
describe "Puppet defaults" do
- include Puppet::Util::Execution
- after { Puppet.settings.clear }
+ include Puppet::Util::Execution
+ after { Puppet.settings.clear }
- describe "when setting the :factpath" do
- it "should add the :factpath to Facter's search paths" do
- Facter.expects(:search).with("/my/fact/path")
+ describe "when setting the :factpath" do
+ it "should add the :factpath to Facter's search paths" do
+ Facter.expects(:search).with("/my/fact/path")
- Puppet.settings[:factpath] = "/my/fact/path"
- end
+ Puppet.settings[:factpath] = "/my/fact/path"
end
+ end
- describe "when setting the :certname" do
- it "should fail if the certname is not downcased" do
- lambda { Puppet.settings[:certname] = "Host.Domain.Com" }.should raise_error(ArgumentError)
- end
+ describe "when setting the :certname" do
+ it "should fail if the certname is not downcased" do
+ lambda { Puppet.settings[:certname] = "Host.Domain.Com" }.should raise_error(ArgumentError)
end
+ end
- describe "when configuring the :crl" do
- it "should warn if :cacrl is set to false" do
- Puppet.expects(:warning)
- Puppet.settings[:cacrl] = 'false'
- end
+ describe "when configuring the :crl" do
+ it "should warn if :cacrl is set to false" do
+ Puppet.expects(:warning)
+ Puppet.settings[:cacrl] = 'false'
end
+ end
- describe "when setting the :catalog_format" do
- it "should log a deprecation notice" do
- Puppet.expects(:warning)
- Puppet.settings[:catalog_format] = 'marshal'
- end
- it "should copy the value to :preferred_serialization_format" do
- Puppet.settings[:catalog_format] = 'marshal'
- Puppet.settings[:preferred_serialization_format].should == 'marshal'
- end
+ describe "when setting the :catalog_format" do
+ it "should log a deprecation notice" do
+ Puppet.expects(:warning)
+ Puppet.settings[:catalog_format] = 'marshal'
end
-
- it "should have a clientyamldir setting" do
- Puppet.settings[:clientyamldir].should_not be_nil
+ it "should copy the value to :preferred_serialization_format" do
+ Puppet.settings[:catalog_format] = 'marshal'
+ Puppet.settings[:preferred_serialization_format].should == 'marshal'
end
-
- it "should have different values for the yamldir and clientyamldir" do
- Puppet.settings[:yamldir].should_not == Puppet.settings[:clientyamldir]
+ end
+
+ it "should have a clientyamldir setting" do
+ Puppet.settings[:clientyamldir].should_not be_nil
+ end
+
+ it "should have different values for the yamldir and clientyamldir" do
+ Puppet.settings[:yamldir].should_not == Puppet.settings[:clientyamldir]
+ end
+
+ it "should have a client_datadir setting" do
+ Puppet.settings[:client_datadir].should_not be_nil
+ end
+
+ it "should have different values for the server_datadir and client_datadir" do
+ Puppet.settings[:server_datadir].should_not == Puppet.settings[:client_datadir]
+ end
+
+ # See #1232
+ it "should not specify a user or group for the clientyamldir" do
+ Puppet.settings.setting(:clientyamldir).owner.should be_nil
+ Puppet.settings.setting(:clientyamldir).group.should be_nil
+ end
+
+ it "should use the service user and group for the yamldir" do
+ Puppet.settings.stubs(:service_user_available?).returns true
+ Puppet.settings.setting(:yamldir).owner.should == Puppet.settings[:user]
+ Puppet.settings.setting(:yamldir).group.should == Puppet.settings[:group]
+ end
+
+ # See #1232
+ it "should not specify a user or group for the rundir" do
+ Puppet.settings.setting(:rundir).owner.should be_nil
+ Puppet.settings.setting(:rundir).group.should be_nil
+ end
+
+ it "should specify that the host private key should be owned by the service user" do
+ Puppet.settings.stubs(:service_user_available?).returns true
+ Puppet.settings.setting(:hostprivkey).owner.should == Puppet.settings[:user]
+ end
+
+ it "should specify that the host certificate should be owned by the service user" do
+ Puppet.settings.stubs(:service_user_available?).returns true
+ Puppet.settings.setting(:hostcert).owner.should == Puppet.settings[:user]
+ end
+
+ it "should use a bind address of ''" do
+ Puppet.settings.clear
+ Puppet.settings[:bindaddress].should == ""
+ end
+
+ [:factdest].each do |setting|
+ it "should force the :factdest to be a directory" do
+ Puppet.settings[setting].should =~ /\/$/
end
+ end
- it "should have a client_datadir setting" do
- Puppet.settings[:client_datadir].should_not be_nil
+ [:modulepath, :factpath].each do |setting|
+ it "should configure '#{setting}' not to be a file setting, so multi-directory settings are acceptable" do
+ Puppet.settings.setting(setting).should be_instance_of(Puppet::Util::Settings::Setting)
end
+ end
- it "should have different values for the server_datadir and client_datadir" do
- Puppet.settings[:server_datadir].should_not == Puppet.settings[:client_datadir]
+ it "should add /usr/sbin and /sbin to the path if they're not there" do
+ withenv("PATH" => "/usr/bin:/usr/local/bin") do
+ Puppet.settings[:path] = "none" # this causes it to ignore the setting
+ ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/usr/sbin")
+ ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/sbin")
end
+ end
- # See #1232
- it "should not specify a user or group for the clientyamldir" do
- Puppet.settings.setting(:clientyamldir).owner.should be_nil
- Puppet.settings.setting(:clientyamldir).group.should be_nil
- end
+ it "should default to pson for the preferred serialization format" do
+ Puppet.settings.value(:preferred_serialization_format).should == "pson"
+ end
- it "should use the service user and group for the yamldir" do
- Puppet.settings.stubs(:service_user_available?).returns true
- Puppet.settings.setting(:yamldir).owner.should == Puppet.settings[:user]
- Puppet.settings.setting(:yamldir).group.should == Puppet.settings[:group]
- end
+ describe "when enabling storeconfigs" do
+ before do
+ Puppet::Resource::Catalog.stubs(:cache_class=)
+ Puppet::Node::Facts.stubs(:cache_class=)
+ Puppet::Node.stubs(:cache_class=)
- # See #1232
- it "should not specify a user or group for the rundir" do
- Puppet.settings.setting(:rundir).owner.should be_nil
- Puppet.settings.setting(:rundir).group.should be_nil
+ Puppet.features.stubs(:rails?).returns true
end
- it "should specify that the host private key should be owned by the service user" do
- Puppet.settings.stubs(:service_user_available?).returns true
- Puppet.settings.setting(:hostprivkey).owner.should == Puppet.settings[:user]
+ it "should set the Catalog cache class to :active_record" do
+ Puppet::Resource::Catalog.expects(:cache_class=).with(:active_record)
+ Puppet.settings[:storeconfigs] = true
end
- it "should specify that the host certificate should be owned by the service user" do
- Puppet.settings.stubs(:service_user_available?).returns true
- Puppet.settings.setting(:hostcert).owner.should == Puppet.settings[:user]
+ it "should not set the Catalog cache class to :active_record if asynchronous storeconfigs is enabled" do
+ Puppet::Resource::Catalog.expects(:cache_class=).with(:active_record).never
+ Puppet.settings.expects(:value).with(:async_storeconfigs).returns true
+ Puppet.settings[:storeconfigs] = true
end
- it "should use a bind address of ''" do
- Puppet.settings.clear
- Puppet.settings[:bindaddress].should == ""
+ it "should set the Facts cache class to :active_record" do
+ Puppet::Node::Facts.expects(:cache_class=).with(:active_record)
+ Puppet.settings[:storeconfigs] = true
end
- [:factdest].each do |setting|
- it "should force the :factdest to be a directory" do
- Puppet.settings[setting].should =~ /\/$/
- end
+ it "should set the Node cache class to :active_record" do
+ Puppet::Node.expects(:cache_class=).with(:active_record)
+ Puppet.settings[:storeconfigs] = true
end
- [:modulepath, :factpath].each do |setting|
- it "should configure '#{setting}' not to be a file setting, so multi-directory settings are acceptable" do
- Puppet.settings.setting(setting).should be_instance_of(Puppet::Util::Settings::Setting)
- end
+ it "should fail if rails is not available" do
+ Puppet.features.stubs(:rails?).returns false
+ lambda { Puppet.settings[:storeconfigs] = true }.should raise_error
end
-
- it "should add /usr/sbin and /sbin to the path if they're not there" do
- withenv("PATH" => "/usr/bin:/usr/local/bin") do
- Puppet.settings[:path] = "none" # this causes it to ignore the setting
- ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/usr/sbin")
- ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/sbin")
- end
+ end
+
+ describe "when enabling asynchronous storeconfigs" do
+ before do
+ Puppet::Resource::Catalog.stubs(:cache_class=)
+ Puppet::Node::Facts.stubs(:cache_class=)
+ Puppet::Node.stubs(:cache_class=)
+ Puppet.features.stubs(:rails?).returns true
end
- it "should default to pson for the preferred serialization format" do
- Puppet.settings.value(:preferred_serialization_format).should == "pson"
+ it "should set storeconfigs to true" do
+ Puppet.settings[:async_storeconfigs] = true
+ Puppet.settings[:storeconfigs].should be_true
end
- describe "when enabling storeconfigs" do
- before do
- Puppet::Resource::Catalog.stubs(:cache_class=)
- Puppet::Node::Facts.stubs(:cache_class=)
- Puppet::Node.stubs(:cache_class=)
-
- Puppet.features.stubs(:rails?).returns true
- end
-
- it "should set the Catalog cache class to :active_record" do
- Puppet::Resource::Catalog.expects(:cache_class=).with(:active_record)
- Puppet.settings[:storeconfigs] = true
- end
-
- it "should not set the Catalog cache class to :active_record if asynchronous storeconfigs is enabled" do
- Puppet::Resource::Catalog.expects(:cache_class=).with(:active_record).never
- Puppet.settings.expects(:value).with(:async_storeconfigs).returns true
- Puppet.settings[:storeconfigs] = true
- end
-
- it "should set the Facts cache class to :active_record" do
- Puppet::Node::Facts.expects(:cache_class=).with(:active_record)
- Puppet.settings[:storeconfigs] = true
- end
-
- it "should set the Node cache class to :active_record" do
- Puppet::Node.expects(:cache_class=).with(:active_record)
- Puppet.settings[:storeconfigs] = true
- end
-
- it "should fail if rails is not available" do
- Puppet.features.stubs(:rails?).returns false
- lambda { Puppet.settings[:storeconfigs] = true }.should raise_error
- end
+ it "should set the Catalog cache class to :queue" do
+ Puppet::Resource::Catalog.expects(:cache_class=).with(:queue)
+ Puppet.settings[:async_storeconfigs] = true
end
- describe "when enabling asynchronous storeconfigs" do
- before do
- Puppet::Resource::Catalog.stubs(:cache_class=)
- Puppet::Node::Facts.stubs(:cache_class=)
- Puppet::Node.stubs(:cache_class=)
- Puppet.features.stubs(:rails?).returns true
- end
-
- it "should set storeconfigs to true" do
- Puppet.settings[:async_storeconfigs] = true
- Puppet.settings[:storeconfigs].should be_true
- end
-
- it "should set the Catalog cache class to :queue" do
- Puppet::Resource::Catalog.expects(:cache_class=).with(:queue)
- Puppet.settings[:async_storeconfigs] = true
- end
-
- it "should set the Facts cache class to :active_record" do
- Puppet::Node::Facts.expects(:cache_class=).with(:active_record)
- Puppet.settings[:storeconfigs] = true
- end
-
- it "should set the Node cache class to :active_record" do
- Puppet::Node.expects(:cache_class=).with(:active_record)
- Puppet.settings[:storeconfigs] = true
- end
+ it "should set the Facts cache class to :active_record" do
+ Puppet::Node::Facts.expects(:cache_class=).with(:active_record)
+ Puppet.settings[:storeconfigs] = true
end
- describe "when enabling thin storeconfigs" do
- before do
- Puppet::Resource::Catalog.stubs(:cache_class=)
- Puppet::Node::Facts.stubs(:cache_class=)
- Puppet::Node.stubs(:cache_class=)
- Puppet.features.stubs(:rails?).returns true
- end
-
- it "should set storeconfigs to true" do
- Puppet.settings[:thin_storeconfigs] = true
- Puppet.settings[:storeconfigs].should be_true
- end
+ it "should set the Node cache class to :active_record" do
+ Puppet::Node.expects(:cache_class=).with(:active_record)
+ Puppet.settings[:storeconfigs] = true
end
-
- it "should have a setting for determining the configuration version and should default to an empty string" do
- Puppet.settings[:config_version].should == ""
- end
-
- describe "when enabling reports" do
- it "should use the default server value when report server is unspecified" do
- Puppet.settings[:server] = "server"
- Puppet.settings[:report_server].should == "server"
- end
-
- it "should use the default masterport value when report port is unspecified" do
- Puppet.settings[:masterport] = "1234"
- Puppet.settings[:report_port].should == "1234"
- end
-
- it "should set report_server when reportserver is set" do
- Puppet.settings[:reportserver] = "reportserver"
- Puppet.settings[:report_server].should == "reportserver"
- end
-
- it "should use report_port when set" do
- Puppet.settings[:masterport] = "1234"
- Puppet.settings[:report_port] = "5678"
- Puppet.settings[:report_port].should == "5678"
- end
-
- it "should prefer report_server over reportserver" do
- Puppet.settings[:reportserver] = "reportserver"
- Puppet.settings[:report_server] = "report_server"
- Puppet.settings[:report_server].should == "report_server"
- end
+ end
+
+ describe "when enabling thin storeconfigs" do
+ before do
+ Puppet::Resource::Catalog.stubs(:cache_class=)
+ Puppet::Node::Facts.stubs(:cache_class=)
+ Puppet::Node.stubs(:cache_class=)
+ Puppet.features.stubs(:rails?).returns true
end
- it "should have a :caname setting that defaults to the cert name" do
- Puppet.settings[:certname] = "foo"
- Puppet.settings[:ca_name].should == "foo"
+ it "should set storeconfigs to true" do
+ Puppet.settings[:thin_storeconfigs] = true
+ Puppet.settings[:storeconfigs].should be_true
end
+ end
- it "should have a 'prerun_command' that defaults to the empty string" do
- Puppet.settings[:prerun_command].should == ""
- end
+ it "should have a setting for determining the configuration version and should default to an empty string" do
+ Puppet.settings[:config_version].should == ""
+ end
- it "should have a 'postrun_command' that defaults to the empty string" do
- Puppet.settings[:postrun_command].should == ""
+ describe "when enabling reports" do
+ it "should use the default server value when report server is unspecified" do
+ Puppet.settings[:server] = "server"
+ Puppet.settings[:report_server].should == "server"
end
- it "should have a 'certificate_revocation' setting that defaults to true" do
- Puppet.settings[:certificate_revocation].should be_true
+ it "should use the default masterport value when report port is unspecified" do
+ Puppet.settings[:masterport] = "1234"
+ Puppet.settings[:report_port].should == "1234"
end
- it "should have an http_compression setting that defaults to false" do
- Puppet.settings[:http_compression].should be_false
+ it "should set report_server when reportserver is set" do
+ Puppet.settings[:reportserver] = "reportserver"
+ Puppet.settings[:report_server].should == "reportserver"
end
- describe "reportdir" do
- subject { Puppet.settings[:reportdir] }
- it { should == "#{Puppet[:vardir]}/reports" }
+ it "should use report_port when set" do
+ Puppet.settings[:masterport] = "1234"
+ Puppet.settings[:report_port] = "5678"
+ Puppet.settings[:report_port].should == "5678"
end
- describe "reporturl" do
- subject { Puppet.settings[:reporturl] }
- it { should == "http://localhost:3000/reports" }
+ it "should prefer report_server over reportserver" do
+ Puppet.settings[:reportserver] = "reportserver"
+ Puppet.settings[:report_server] = "report_server"
+ Puppet.settings[:report_server].should == "report_server"
end
+ end
+
+ it "should have a :caname setting that defaults to the cert name" do
+ Puppet.settings[:certname] = "foo"
+ Puppet.settings[:ca_name].should == "foo"
+ end
+
+ it "should have a 'prerun_command' that defaults to the empty string" do
+ Puppet.settings[:prerun_command].should == ""
+ end
+
+ it "should have a 'postrun_command' that defaults to the empty string" do
+ Puppet.settings[:postrun_command].should == ""
+ end
+
+ it "should have a 'certificate_revocation' setting that defaults to true" do
+ Puppet.settings[:certificate_revocation].should be_true
+ end
+
+ it "should have an http_compression setting that defaults to false" do
+ Puppet.settings[:http_compression].should be_false
+ end
+
+ describe "reportdir" do
+ subject { Puppet.settings[:reportdir] }
+ it { should == "#{Puppet[:vardir]}/reports" }
+ end
+
+ describe "reporturl" do
+ subject { Puppet.settings[:reporturl] }
+ it { should == "http://localhost:3000/reports" }
+ end
end
diff --git a/spec/integration/file_serving/content_spec.rb b/spec/integration/file_serving/content_spec.rb
index a51b36223..1443b9592 100755
--- a/spec/integration/file_serving/content_spec.rb
+++ b/spec/integration/file_serving/content_spec.rb
@@ -9,12 +9,12 @@ require 'puppet/file_serving/content'
require 'shared_behaviours/file_serving'
describe Puppet::FileServing::Content, " when finding files" do
- it_should_behave_like "Puppet::FileServing::Files"
+ it_should_behave_like "Puppet::FileServing::Files"
- before do
- @test_class = Puppet::FileServing::Content
- @indirection = Puppet::FileServing::Content.indirection
- end
+ before do
+ @test_class = Puppet::FileServing::Content
+ @indirection = Puppet::FileServing::Content.indirection
+ end
- after { Puppet::Util::Cacher.expire }
+ after { Puppet::Util::Cacher.expire }
end
diff --git a/spec/integration/file_serving/fileset_spec.rb b/spec/integration/file_serving/fileset_spec.rb
index 80bf0f376..e5afe8f70 100755
--- a/spec/integration/file_serving/fileset_spec.rb
+++ b/spec/integration/file_serving/fileset_spec.rb
@@ -5,10 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/fileset'
describe Puppet::FileServing::Fileset do
- it "should be able to recurse on a single file" do
- @path = Tempfile.new("fileset_integration")
+ it "should be able to recurse on a single file" do
+ @path = Tempfile.new("fileset_integration")
- fileset = Puppet::FileServing::Fileset.new(@path.path)
- lambda { fileset.files }.should_not raise_error
- end
+ fileset = Puppet::FileServing::Fileset.new(@path.path)
+ lambda { fileset.files }.should_not raise_error
+ end
end
diff --git a/spec/integration/file_serving/metadata_spec.rb b/spec/integration/file_serving/metadata_spec.rb
index bd105e412..1e67309e5 100755
--- a/spec/integration/file_serving/metadata_spec.rb
+++ b/spec/integration/file_serving/metadata_spec.rb
@@ -10,12 +10,12 @@ require 'shared_behaviours/file_serving'
require 'puppet/indirector/file_metadata/file_server'
describe Puppet::FileServing::Metadata, " when finding files" do
- it_should_behave_like "Puppet::FileServing::Files"
+ it_should_behave_like "Puppet::FileServing::Files"
- before do
- @test_class = Puppet::FileServing::Metadata
- @indirection = Puppet::FileServing::Metadata.indirection
- end
+ before do
+ @test_class = Puppet::FileServing::Metadata
+ @indirection = Puppet::FileServing::Metadata.indirection
+ end
- after { Puppet::Util::Cacher.expire }
+ after { Puppet::Util::Cacher.expire }
end
diff --git a/spec/integration/file_serving/terminus_helper_spec.rb b/spec/integration/file_serving/terminus_helper_spec.rb
index 7d2587af1..5fd47c954 100755
--- a/spec/integration/file_serving/terminus_helper_spec.rb
+++ b/spec/integration/file_serving/terminus_helper_spec.rb
@@ -5,18 +5,18 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/terminus_helper'
class TerminusHelperIntegrationTester
- include Puppet::FileServing::TerminusHelper
- def model
- Puppet::FileServing::Metadata
- end
+ include Puppet::FileServing::TerminusHelper
+ def model
+ Puppet::FileServing::Metadata
+ end
end
describe Puppet::FileServing::TerminusHelper do
- it "should be able to recurse on a single file" do
- @path = Tempfile.new("fileset_integration")
- request = Puppet::Indirector::Request.new(:metadata, :find, @path.path, :recurse => true)
+ it "should be able to recurse on a single file" do
+ @path = Tempfile.new("fileset_integration")
+ request = Puppet::Indirector::Request.new(:metadata, :find, @path.path, :recurse => true)
- tester = TerminusHelperIntegrationTester.new
- lambda { tester.path2instances(request, @path.path) }.should_not raise_error
- end
+ tester = TerminusHelperIntegrationTester.new
+ lambda { tester.path2instances(request, @path.path) }.should_not raise_error
+ end
end
diff --git a/spec/integration/indirector/bucket_file/rest_spec.rb b/spec/integration/indirector/bucket_file/rest_spec.rb
index 94d6e3a62..4d90a8c59 100644
--- a/spec/integration/indirector/bucket_file/rest_spec.rb
+++ b/spec/integration/indirector/bucket_file/rest_spec.rb
@@ -7,62 +7,62 @@ require 'puppet/network/server'
require 'puppet/network/http/webrick/rest'
describe "Filebucket REST Terminus" do
- before do
- Puppet[:masterport] = 34343
- Puppet[:server] = "localhost"
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
-
- Puppet::Util::Cacher.expire
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- # Generate the certificate with a local CA
- Puppet::SSL::Host.ca_location = :local
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
- ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- @host = Puppet::SSL::Host.new(Puppet[:certname])
-
- @params = { :port => 34343, :handlers => [ :file_bucket_file ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- @old_terminus = Puppet::FileBucket::File.indirection.terminus_class
- Puppet::FileBucket::File.terminus_class = :rest
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @file_bucket_file = stub_everything 'file_bucket_file'
- @mock_model = stub('faked model', :name => "file_bucket_file", :convert_from => @file_bucket_file)
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
- end
-
- after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
- @server.unlisten
- Puppet::FileBucket::File.terminus_class = @old_terminus
- end
-
- it "should be able save a file to the remote filebucket" do
- @file_bucket_file.expects(:save)
-
- file_bucket_file = Puppet::FileBucket::File.new("pouet")
- file_bucket_file.save
- end
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @host = Puppet::SSL::Host.new(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :file_bucket_file ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ @old_terminus = Puppet::FileBucket::File.indirection.terminus_class
+ Puppet::FileBucket::File.terminus_class = :rest
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @file_bucket_file = stub_everything 'file_bucket_file'
+ @mock_model = stub('faked model', :name => "file_bucket_file", :convert_from => @file_bucket_file)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ Puppet::FileBucket::File.terminus_class = @old_terminus
+ end
+
+ it "should be able save a file to the remote filebucket" do
+ @file_bucket_file.expects(:save)
+
+ file_bucket_file = Puppet::FileBucket::File.new("pouet")
+ file_bucket_file.save
+ end
end
diff --git a/spec/integration/indirector/catalog/compiler_spec.rb b/spec/integration/indirector/catalog/compiler_spec.rb
index 4905b389e..ede502e3c 100755
--- a/spec/integration/indirector/catalog/compiler_spec.rb
+++ b/spec/integration/indirector/catalog/compiler_spec.rb
@@ -7,62 +7,62 @@ require 'puppet/resource/catalog'
Puppet::Resource::Catalog.indirection.terminus(:compiler)
describe Puppet::Resource::Catalog::Compiler do
- before do
- Facter.stubs(:value).returns "something"
- @catalog = Puppet::Resource::Catalog.new
-
- @one = Puppet::Resource.new(:file, "/one")
-
- @two = Puppet::Resource.new(:file, "/two")
- @catalog.add_resource(@one, @two)
- end
-
- after { Puppet.settings.clear }
-
- it "should remove virtual resources when filtering" do
- @one.virtual = true
- Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.should == [ @two.ref ]
- end
-
- it "should not remove exported resources when filtering" do
- @one.exported = true
- Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.sort.should == [ @one.ref, @two.ref ]
- end
-
- it "should remove virtual exported resources when filtering" do
- @one.exported = true
- @one.virtual = true
- Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.should == [ @two.ref ]
- end
-
- it "should filter out virtual resources when finding a catalog" do
- @one.virtual = true
- request = stub 'request', :name => "mynode"
- Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
-
- Puppet::Resource::Catalog.find(request).resource_refs.should == [ @two.ref ]
- end
-
- it "should not filter out exported resources when finding a catalog" do
- @one.exported = true
- request = stub 'request', :name => "mynode"
- Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
-
- Puppet::Resource::Catalog.find(request).resource_refs.sort.should == [ @one.ref, @two.ref ]
- end
-
- it "should filter out virtual exported resources when finding a catalog" do
- @one.exported = true
- @one.virtual = true
- request = stub 'request', :name => "mynode"
- Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
- Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
-
- Puppet::Resource::Catalog.find(request).resource_refs.should == [ @two.ref ]
- end
+ before do
+ Facter.stubs(:value).returns "something"
+ @catalog = Puppet::Resource::Catalog.new
+
+ @one = Puppet::Resource.new(:file, "/one")
+
+ @two = Puppet::Resource.new(:file, "/two")
+ @catalog.add_resource(@one, @two)
+ end
+
+ after { Puppet.settings.clear }
+
+ it "should remove virtual resources when filtering" do
+ @one.virtual = true
+ Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.should == [ @two.ref ]
+ end
+
+ it "should not remove exported resources when filtering" do
+ @one.exported = true
+ Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.sort.should == [ @one.ref, @two.ref ]
+ end
+
+ it "should remove virtual exported resources when filtering" do
+ @one.exported = true
+ @one.virtual = true
+ Puppet::Resource::Catalog.indirection.terminus.filter(@catalog).resource_refs.should == [ @two.ref ]
+ end
+
+ it "should filter out virtual resources when finding a catalog" do
+ @one.virtual = true
+ request = stub 'request', :name => "mynode"
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
+
+ Puppet::Resource::Catalog.find(request).resource_refs.should == [ @two.ref ]
+ end
+
+ it "should not filter out exported resources when finding a catalog" do
+ @one.exported = true
+ request = stub 'request', :name => "mynode"
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
+
+ Puppet::Resource::Catalog.find(request).resource_refs.sort.should == [ @one.ref, @two.ref ]
+ end
+
+ it "should filter out virtual exported resources when finding a catalog" do
+ @one.exported = true
+ @one.virtual = true
+ request = stub 'request', :name => "mynode"
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:extract_facts_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:node_from_request)
+ Puppet::Resource::Catalog.indirection.terminus.stubs(:compile).returns(@catalog)
+
+ Puppet::Resource::Catalog.find(request).resource_refs.should == [ @two.ref ]
+ end
end
diff --git a/spec/integration/indirector/catalog/queue_spec.rb b/spec/integration/indirector/catalog/queue_spec.rb
index 5a781c1a8..0f8bd41fb 100755
--- a/spec/integration/indirector/catalog/queue_spec.rb
+++ b/spec/integration/indirector/catalog/queue_spec.rb
@@ -6,56 +6,56 @@ require 'puppet/resource/catalog'
describe "Puppet::Resource::Catalog::Queue" do
- confine "Missing pson support; cannot test queue" => Puppet.features.pson?
+ confine "Missing pson support; cannot test queue" => Puppet.features.pson?
- before do
- Puppet::Resource::Catalog.indirection.terminus(:queue)
- @catalog = Puppet::Resource::Catalog.new
+ before do
+ Puppet::Resource::Catalog.indirection.terminus(:queue)
+ @catalog = Puppet::Resource::Catalog.new
- @one = Puppet::Resource.new(:file, "/one")
- @two = Puppet::Resource.new(:file, "/two")
- @catalog.add_resource(@one, @two)
+ @one = Puppet::Resource.new(:file, "/one")
+ @two = Puppet::Resource.new(:file, "/two")
+ @catalog.add_resource(@one, @two)
- @catalog.add_edge(@one, @two)
+ @catalog.add_edge(@one, @two)
- Puppet[:trace] = true
- end
+ Puppet[:trace] = true
+ end
- after { Puppet.settings.clear }
+ after { Puppet.settings.clear }
- it "should render catalogs to pson and send them via the queue client when catalogs are saved" do
- terminus = Puppet::Resource::Catalog.indirection.terminus(:queue)
+ it "should render catalogs to pson and send them via the queue client when catalogs are saved" do
+ terminus = Puppet::Resource::Catalog.indirection.terminus(:queue)
- client = mock 'client'
- terminus.stubs(:client).returns client
+ client = mock 'client'
+ terminus.stubs(:client).returns client
- client.expects(:send_message).with(:catalog, @catalog.to_pson)
+ client.expects(:send_message).with(:catalog, @catalog.to_pson)
- request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog)
+ request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog)
- terminus.save(request)
- end
+ terminus.save(request)
+ end
- it "should intern catalog messages when they are passed via a subscription" do
- client = mock 'client'
- Puppet::Resource::Catalog::Queue.stubs(:client).returns client
+ it "should intern catalog messages when they are passed via a subscription" do
+ client = mock 'client'
+ Puppet::Resource::Catalog::Queue.stubs(:client).returns client
- pson = @catalog.to_pson
+ pson = @catalog.to_pson
- client.expects(:subscribe).with(:catalog).yields(pson)
+ client.expects(:subscribe).with(:catalog).yields(pson)
- Puppet.expects(:err).never
+ Puppet.expects(:err).never
- result = []
- Puppet::Resource::Catalog::Queue.subscribe do |catalog|
- result << catalog
- end
+ result = []
+ Puppet::Resource::Catalog::Queue.subscribe do |catalog|
+ result << catalog
+ end
- catalog = result.shift
- catalog.should be_instance_of(Puppet::Resource::Catalog)
+ catalog = result.shift
+ catalog.should be_instance_of(Puppet::Resource::Catalog)
- catalog.resource(:file, "/one").should be_instance_of(Puppet::Resource)
- catalog.resource(:file, "/two").should be_instance_of(Puppet::Resource)
- catalog.should be_edge(catalog.resource(:file, "/one"), catalog.resource(:file, "/two"))
- end
+ catalog.resource(:file, "/one").should be_instance_of(Puppet::Resource)
+ catalog.resource(:file, "/two").should be_instance_of(Puppet::Resource)
+ catalog.should be_edge(catalog.resource(:file, "/one"), catalog.resource(:file, "/two"))
+ end
end
diff --git a/spec/integration/indirector/certificate/rest_spec.rb b/spec/integration/indirector/certificate/rest_spec.rb
index 8042f8680..356a7d316 100755
--- a/spec/integration/indirector/certificate/rest_spec.rb
+++ b/spec/integration/indirector/certificate/rest_spec.rb
@@ -7,62 +7,62 @@ require 'puppet/network/server'
require 'puppet/network/http/webrick/rest'
describe "Certificate REST Terminus" do
- before do
- Puppet[:masterport] = 34343
- Puppet[:server] = "localhost"
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
-
- Puppet::Util::Cacher.expire
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- # Generate the certificate with a local CA
- Puppet::SSL::Host.ca_location = :local
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
- ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- @host = Puppet::SSL::Host.new(Puppet[:certname])
-
- @params = { :port => 34343, :handlers => [ :certificate ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # Then switch to a remote CA, so that we go through REST.
- Puppet::SSL::Host.ca_location = :remote
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @mock_model = stub('faked model', :name => "certificate")
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
- end
-
- after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
- @server.unlisten
- end
-
- it "should be able to retrieve a remote certificate" do
- @mock_model.expects(:find).returns @host.certificate
- result = Puppet::SSL::Certificate.find('bar')
-
- # There's no good '==' method on certs.
- result.content.to_s.should == @host.certificate.content.to_s
- result.name.should == "bar"
- end
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @host = Puppet::SSL::Host.new(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :certificate ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # Then switch to a remote CA, so that we go through REST.
+ Puppet::SSL::Host.ca_location = :remote
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @mock_model = stub('faked model', :name => "certificate")
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ end
+
+ it "should be able to retrieve a remote certificate" do
+ @mock_model.expects(:find).returns @host.certificate
+ result = Puppet::SSL::Certificate.find('bar')
+
+ # There's no good '==' method on certs.
+ result.content.to_s.should == @host.certificate.content.to_s
+ result.name.should == "bar"
+ end
end
diff --git a/spec/integration/indirector/certificate_request/rest_spec.rb b/spec/integration/indirector/certificate_request/rest_spec.rb
index 86fb1ba4a..2c98ef66c 100755
--- a/spec/integration/indirector/certificate_request/rest_spec.rb
+++ b/spec/integration/indirector/certificate_request/rest_spec.rb
@@ -7,82 +7,82 @@ require 'puppet/network/server'
require 'puppet/network/http/webrick/rest'
describe "Certificate Request REST Terminus" do
- before do
- Puppet::Util::Cacher.expire
-
- Puppet[:masterport] = 34343
- Puppet[:server] = "localhost"
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- # Generate the certificate with a local CA
- Puppet::SSL::Host.ca_location = :local
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- # Create the CSR and write it to disk
- @host = Puppet::SSL::Host.new("foo.madstop.com")
- @host.generate_certificate_request
-
- # Now remove the cached csr
- Puppet::SSL::Host.ca_location = :none
- Puppet::SSL::Host.destroy("foo.madstop.com")
-
- @params = { :port => 34343, :handlers => [ :certificate_request ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # Then switch to a remote CA, so that we go through REST.
- Puppet::SSL::Host.ca_location = :remote
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @mock_model = stub('faked model', :name => "certificate request")
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
- end
-
- after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
- @server.unlisten
- end
-
- it "should be able to save a certificate request to the CA" do
- key = Puppet::SSL::Key.new("bar.madstop.com")
- key.generate
-
- csr = Puppet::SSL::CertificateRequest.new("bar.madstop.com")
- csr.generate(key.content)
-
- server_csr = mock 'csr'
- server_csr.expects(:save)
- @mock_model.expects(:convert_from).with("s", csr.content.to_s).returns server_csr
-
- csr.save
- end
-
- it "should be able to retrieve a remote certificate request" do
- # We're finding the cached value :/
- @mock_model.expects(:find).returns @host.certificate_request
- result = Puppet::SSL::CertificateRequest.find('foo.madstop.com')
-
- # There's no good '==' method on certs.
- result.content.to_s.should == @host.certificate_request.content.to_s
- result.name.should == @host.certificate_request.name
- end
+ before do
+ Puppet::Util::Cacher.expire
+
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ # Create the CSR and write it to disk
+ @host = Puppet::SSL::Host.new("foo.madstop.com")
+ @host.generate_certificate_request
+
+ # Now remove the cached csr
+ Puppet::SSL::Host.ca_location = :none
+ Puppet::SSL::Host.destroy("foo.madstop.com")
+
+ @params = { :port => 34343, :handlers => [ :certificate_request ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # Then switch to a remote CA, so that we go through REST.
+ Puppet::SSL::Host.ca_location = :remote
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @mock_model = stub('faked model', :name => "certificate request")
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ end
+
+ it "should be able to save a certificate request to the CA" do
+ key = Puppet::SSL::Key.new("bar.madstop.com")
+ key.generate
+
+ csr = Puppet::SSL::CertificateRequest.new("bar.madstop.com")
+ csr.generate(key.content)
+
+ server_csr = mock 'csr'
+ server_csr.expects(:save)
+ @mock_model.expects(:convert_from).with("s", csr.content.to_s).returns server_csr
+
+ csr.save
+ end
+
+ it "should be able to retrieve a remote certificate request" do
+ # We're finding the cached value :/
+ @mock_model.expects(:find).returns @host.certificate_request
+ result = Puppet::SSL::CertificateRequest.find('foo.madstop.com')
+
+ # There's no good '==' method on certs.
+ result.content.to_s.should == @host.certificate_request.content.to_s
+ result.name.should == @host.certificate_request.name
+ end
end
diff --git a/spec/integration/indirector/certificate_revocation_list/rest_spec.rb b/spec/integration/indirector/certificate_revocation_list/rest_spec.rb
index 8c8d6e113..62a2f808e 100755
--- a/spec/integration/indirector/certificate_revocation_list/rest_spec.rb
+++ b/spec/integration/indirector/certificate_revocation_list/rest_spec.rb
@@ -7,70 +7,70 @@ require 'puppet/network/server'
require 'puppet/network/http/webrick/rest'
describe "Certificate REST Terminus" do
- before do
- Puppet[:masterport] = 34343
- Puppet[:server] = "localhost"
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
-
- Puppet::Util::Cacher.expire
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- # Generate the certificate with a local CA
- Puppet::SSL::Host.ca_location = :local
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- @params = { :port => 34343, :handlers => [ :certificate_revocation_list ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # And make sure we've generated the CRL
- @crl = ca.crl
-
- # Now remove the cached crl
- Puppet::SSL::Host.ca_location = :none
- Puppet::SSL::CertificateRevocationList.destroy(Puppet::SSL::CA_NAME)
-
- # This is necessary so that we create the SSL store before we start
- # using REST. This is necessary to prevent an infinite loop,
- # which only occurs during testing.
- Puppet::Network::HttpPool.ssl_host.ssl_store
-
- # Then switch to a remote CA, so that we go through REST.
- Puppet::SSL::Host.ca_location = :remote
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @mock_model = stub('faked model', :name => "certificate")
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
- end
-
- after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
- @server.unlisten
- end
-
- it "should be able to retrieve a remote CRL" do
- @mock_model.expects(:find).returns @crl
- result = Puppet::SSL::CertificateRevocationList.find('bar')
-
- # There's no good '==' method on certs.
- result.content.to_s.should == @crl.content.to_s
- end
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :certificate_revocation_list ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # And make sure we've generated the CRL
+ @crl = ca.crl
+
+ # Now remove the cached crl
+ Puppet::SSL::Host.ca_location = :none
+ Puppet::SSL::CertificateRevocationList.destroy(Puppet::SSL::CA_NAME)
+
+ # This is necessary so that we create the SSL store before we start
+ # using REST. This is necessary to prevent an infinite loop,
+ # which only occurs during testing.
+ Puppet::Network::HttpPool.ssl_host.ssl_store
+
+ # Then switch to a remote CA, so that we go through REST.
+ Puppet::SSL::Host.ca_location = :remote
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @mock_model = stub('faked model', :name => "certificate")
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ end
+
+ it "should be able to retrieve a remote CRL" do
+ @mock_model.expects(:find).returns @crl
+ result = Puppet::SSL::CertificateRevocationList.find('bar')
+
+ # There's no good '==' method on certs.
+ result.content.to_s.should == @crl.content.to_s
+ end
end
diff --git a/spec/integration/indirector/direct_file_server_spec.rb b/spec/integration/indirector/direct_file_server_spec.rb
index d2b933cd5..24a55a34f 100755
--- a/spec/integration/indirector/direct_file_server_spec.rb
+++ b/spec/integration/indirector/direct_file_server_spec.rb
@@ -8,66 +8,66 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/indirector/file_content/file'
describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model" do
- before do
- # We just test a subclass, since it's close enough.
- @terminus = Puppet::Indirector::FileContent::File.new
+ before do
+ # We just test a subclass, since it's close enough.
+ @terminus = Puppet::Indirector::FileContent::File.new
- @filepath = "/path/to/my/file"
- end
+ @filepath = "/path/to/my/file"
+ end
- it "should return an instance of the model" do
- FileTest.expects(:exists?).with(@filepath).returns(true)
+ it "should return an instance of the model" do
+ FileTest.expects(:exists?).with(@filepath).returns(true)
- @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}")).should be_instance_of(Puppet::FileServing::Content)
- end
+ @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}")).should be_instance_of(Puppet::FileServing::Content)
+ end
- it "should return an instance capable of returning its content" do
- FileTest.expects(:exists?).with(@filepath).returns(true)
- File.stubs(:lstat).with(@filepath).returns(stub("stat", :ftype => "file"))
- File.expects(:read).with(@filepath).returns("my content")
+ it "should return an instance capable of returning its content" do
+ FileTest.expects(:exists?).with(@filepath).returns(true)
+ File.stubs(:lstat).with(@filepath).returns(stub("stat", :ftype => "file"))
+ File.expects(:read).with(@filepath).returns("my content")
- instance = @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}"))
+ instance = @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}"))
- instance.content.should == "my content"
- end
+ instance.content.should == "my content"
+ end
end
describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model" do
- before do
- @terminus = Puppet::Indirector::FileContent::File.new
-
- @path = Tempfile.new("direct_file_server_testing")
- path = @path.path
- @path.close!
- @path = path
-
- Dir.mkdir(@path)
- File.open(File.join(@path, "one"), "w") { |f| f.print "one content" }
- File.open(File.join(@path, "two"), "w") { |f| f.print "two content" }
-
- @request = @terminus.indirection.request(:search, "file:///#{@path}", :recurse => true)
- end
-
- after do
- system("rm -rf #{@path}")
- end
-
- it "should return an instance for every file in the fileset" do
- 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) }
- end
-
- it "should return instances capable of returning their content" do
- @terminus.search(@request).each do |instance|
- case instance.full_path
- when /one/; instance.content.should == "one content"
- when /two/; instance.content.should == "two content"
- when @path
- else
- raise "No valid key for #{instance.path.inspect}"
- end
- end
+ before do
+ @terminus = Puppet::Indirector::FileContent::File.new
+
+ @path = Tempfile.new("direct_file_server_testing")
+ path = @path.path
+ @path.close!
+ @path = path
+
+ Dir.mkdir(@path)
+ File.open(File.join(@path, "one"), "w") { |f| f.print "one content" }
+ File.open(File.join(@path, "two"), "w") { |f| f.print "two content" }
+
+ @request = @terminus.indirection.request(:search, "file:///#{@path}", :recurse => true)
+ end
+
+ after do
+ system("rm -rf #{@path}")
+ end
+
+ it "should return an instance for every file in the fileset" do
+ 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) }
+ end
+
+ it "should return instances capable of returning their content" do
+ @terminus.search(@request).each do |instance|
+ case instance.full_path
+ when /one/; instance.content.should == "one content"
+ when /two/; instance.content.should == "two content"
+ when @path
+ else
+ raise "No valid key for #{instance.path.inspect}"
+ end
end
+ end
end
diff --git a/spec/integration/indirector/file_content/file_server_spec.rb b/spec/integration/indirector/file_content/file_server_spec.rb
index e8f777ef8..5de7f1de0 100755
--- a/spec/integration/indirector/file_content/file_server_spec.rb
+++ b/spec/integration/indirector/file_content/file_server_spec.rb
@@ -11,84 +11,84 @@ require 'shared_behaviours/file_server_terminus'
require 'puppet_spec/files'
describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
- it_should_behave_like "Puppet::Indirector::FileServerTerminus"
- include PuppetSpec::Files
+ it_should_behave_like "Puppet::Indirector::FileServerTerminus"
+ include PuppetSpec::Files
- before do
- @terminus = Puppet::Indirector::FileContent::FileServer.new
- @test_class = Puppet::FileServing::Content
- end
+ before do
+ @terminus = Puppet::Indirector::FileContent::FileServer.new
+ @test_class = Puppet::FileServing::Content
+ end
- it "should find plugin file content in the environment specified in the request" do
- path = tmpfile("file_content_with_env")
+ it "should find plugin file content in the environment specified in the request" do
+ path = tmpfile("file_content_with_env")
- Dir.mkdir(path)
+ Dir.mkdir(path)
- modpath = File.join(path, "mod")
- FileUtils.mkdir_p(File.join(modpath, "lib"))
- file = File.join(modpath, "lib", "file.rb")
- File.open(file, "w") { |f| f.puts "1" }
+ modpath = File.join(path, "mod")
+ FileUtils.mkdir_p(File.join(modpath, "lib"))
+ file = File.join(modpath, "lib", "file.rb")
+ File.open(file, "w") { |f| f.puts "1" }
- Puppet.settings[:modulepath] = "/no/such/file"
+ Puppet.settings[:modulepath] = "/no/such/file"
- env = Puppet::Node::Environment.new("foo")
- env.stubs(:modulepath).returns [path]
+ env = Puppet::Node::Environment.new("foo")
+ env.stubs(:modulepath).returns [path]
- result = Puppet::FileServing::Content.search("plugins", :environment => "foo", :recurse => true)
+ result = Puppet::FileServing::Content.search("plugins", :environment => "foo", :recurse => true)
- result.should_not be_nil
- result.length.should == 2
- result[1].should be_instance_of(Puppet::FileServing::Content)
- result[1].content.should == "1\n"
- end
+ result.should_not be_nil
+ result.length.should == 2
+ result[1].should be_instance_of(Puppet::FileServing::Content)
+ result[1].content.should == "1\n"
+ end
- it "should find file content in modules" do
- path = tmpfile("file_content")
+ it "should find file content in modules" do
+ path = tmpfile("file_content")
- Dir.mkdir(path)
+ Dir.mkdir(path)
- modpath = File.join(path, "mymod")
- FileUtils.mkdir_p(File.join(modpath, "files"))
- file = File.join(modpath, "files", "myfile")
- File.open(file, "w") { |f| f.puts "1" }
+ modpath = File.join(path, "mymod")
+ FileUtils.mkdir_p(File.join(modpath, "files"))
+ file = File.join(modpath, "files", "myfile")
+ File.open(file, "w") { |f| f.puts "1" }
- Puppet.settings[:modulepath] = path
+ Puppet.settings[:modulepath] = path
- result = Puppet::FileServing::Content.find("modules/mymod/myfile")
+ result = Puppet::FileServing::Content.find("modules/mymod/myfile")
- result.should_not be_nil
- result.should be_instance_of(Puppet::FileServing::Content)
- result.content.should == "1\n"
- end
+ result.should_not be_nil
+ result.should be_instance_of(Puppet::FileServing::Content)
+ result.content.should == "1\n"
+ end
- it "should find file content in files when node name expansions are used" do
- Puppet::Util::Cacher.expire
- FileTest.stubs(:exists?).returns true
- FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
+ it "should find file content in files when node name expansions are used" do
+ Puppet::Util::Cacher.expire
+ FileTest.stubs(:exists?).returns true
+ FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
- @path = tmpfile("file_server_testing")
+ @path = tmpfile("file_server_testing")
- Dir.mkdir(@path)
- subdir = File.join(@path, "mynode")
- Dir.mkdir(subdir)
- File.open(File.join(subdir, "myfile"), "w") { |f| f.puts "1" }
+ Dir.mkdir(@path)
+ subdir = File.join(@path, "mynode")
+ Dir.mkdir(subdir)
+ File.open(File.join(subdir, "myfile"), "w") { |f| f.puts "1" }
- # Use a real mount, so the integration is a bit deeper.
- @mount1 = Puppet::FileServing::Configuration::Mount::File.new("one")
- @mount1.stubs(:allowed?).returns true
- @mount1.path = File.join(@path, "%h")
+ # Use a real mount, so the integration is a bit deeper.
+ @mount1 = Puppet::FileServing::Configuration::Mount::File.new("one")
+ @mount1.stubs(:allowed?).returns true
+ @mount1.path = File.join(@path, "%h")
- @parser = stub 'parser', :changed? => false
- @parser.stubs(:parse).returns("one" => @mount1)
+ @parser = stub 'parser', :changed? => false
+ @parser.stubs(:parse).returns("one" => @mount1)
- Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
+ Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
- path = File.join(@path, "myfile")
+ path = File.join(@path, "myfile")
- result = Puppet::FileServing::Content.find("one/myfile", :environment => "foo", :node => "mynode")
+ result = Puppet::FileServing::Content.find("one/myfile", :environment => "foo", :node => "mynode")
- result.should_not be_nil
- result.should be_instance_of(Puppet::FileServing::Content)
- result.content.should == "1\n"
- end
+ result.should_not be_nil
+ result.should be_instance_of(Puppet::FileServing::Content)
+ result.content.should == "1\n"
+ end
end
diff --git a/spec/integration/indirector/file_metadata/file_server_spec.rb b/spec/integration/indirector/file_metadata/file_server_spec.rb
index 7caa2e4de..d60012192 100755
--- a/spec/integration/indirector/file_metadata/file_server_spec.rb
+++ b/spec/integration/indirector/file_metadata/file_server_spec.rb
@@ -9,10 +9,10 @@ require 'puppet/indirector/file_metadata/file_server'
require 'shared_behaviours/file_server_terminus'
describe Puppet::Indirector::FileMetadata::FileServer, " when finding files" do
- it_should_behave_like "Puppet::Indirector::FileServerTerminus"
+ it_should_behave_like "Puppet::Indirector::FileServerTerminus"
- before do
- @terminus = Puppet::Indirector::FileMetadata::FileServer.new
- @test_class = Puppet::FileServing::Metadata
- end
+ before do
+ @terminus = Puppet::Indirector::FileMetadata::FileServer.new
+ @test_class = Puppet::FileServing::Metadata
+ end
end
diff --git a/spec/integration/indirector/node/ldap_spec.rb b/spec/integration/indirector/node/ldap_spec.rb
index 82273111f..e4c0867ad 100755
--- a/spec/integration/indirector/node/ldap_spec.rb
+++ b/spec/integration/indirector/node/ldap_spec.rb
@@ -5,11 +5,11 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/node/ldap'
describe Puppet::Node::Ldap do
- it "should use a restrictive filter when searching for nodes in a class" do
- ldap = Puppet::Node.indirection.terminus(:ldap)
- Puppet::Node.indirection.stubs(:terminus).returns ldap
- ldap.expects(:ldapsearch).with("(&(objectclass=puppetClient)(puppetclass=foo))")
+ it "should use a restrictive filter when searching for nodes in a class" do
+ ldap = Puppet::Node.indirection.terminus(:ldap)
+ Puppet::Node.indirection.stubs(:terminus).returns ldap
+ ldap.expects(:ldapsearch).with("(&(objectclass=puppetClient)(puppetclass=foo))")
- Puppet::Node.search "eh", :class => "foo"
- end
+ Puppet::Node.search "eh", :class => "foo"
+ end
end
diff --git a/spec/integration/indirector/report/rest_spec.rb b/spec/integration/indirector/report/rest_spec.rb
index 1ddced9f9..089f8fd3f 100644
--- a/spec/integration/indirector/report/rest_spec.rb
+++ b/spec/integration/indirector/report/rest_spec.rb
@@ -7,90 +7,90 @@ require 'puppet/network/server'
require 'puppet/network/http/webrick/rest'
describe "Report REST Terminus" do
- before do
- Puppet[:masterport] = 34343
- Puppet[:server] = "localhost"
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
-
- Puppet::Util::Cacher.expire
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- # Generate the certificate with a local CA
- Puppet::SSL::Host.ca_location = :local
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
- ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- @host = Puppet::SSL::Host.new(Puppet[:certname])
-
- @params = { :port => 34343, :handlers => [ :report ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # Let's use REST for our reports :-)
- @old_terminus = Puppet::Transaction::Report.indirection.terminus_class
- Puppet::Transaction::Report.terminus_class = :rest
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'save', which would cause an immediate
- # return.
- @report = stub_everything 'report'
- @mock_model = stub_everything 'faked model', :name => "report", :convert_from => @report
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
- end
-
- after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
- @server.unlisten
- Puppet::Transaction::Report.terminus_class = @old_terminus
- end
-
- it "should be able to send a report to the server" do
- @report.expects(:save)
-
- report = Puppet::Transaction::Report.new
-
- resourcemetrics = {
- :total => 12,
- :out_of_sync => 20,
- :applied => 45,
- :skipped => 1,
- :restarted => 23,
- :failed_restarts => 1,
- :scheduled => 10
- }
- report.add_metric(:resources, resourcemetrics)
-
- timemetrics = {
- :resource1 => 10,
- :resource2 => 50,
- :resource3 => 40,
- :resource4 => 20,
- }
- report.add_metric(:times, timemetrics)
-
-
- report.add_metric(
- :changes,
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @host = Puppet::SSL::Host.new(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :report ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # Let's use REST for our reports :-)
+ @old_terminus = Puppet::Transaction::Report.indirection.terminus_class
+ Puppet::Transaction::Report.terminus_class = :rest
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'save', which would cause an immediate
+ # return.
+ @report = stub_everything 'report'
+ @mock_model = stub_everything 'faked model', :name => "report", :convert_from => @report
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ Puppet::Transaction::Report.terminus_class = @old_terminus
+ end
+
+ it "should be able to send a report to the server" do
+ @report.expects(:save)
+
+ report = Puppet::Transaction::Report.new
+
+ resourcemetrics = {
+ :total => 12,
+ :out_of_sync => 20,
+ :applied => 45,
+ :skipped => 1,
+ :restarted => 23,
+ :failed_restarts => 1,
+ :scheduled => 10
+ }
+ report.add_metric(:resources, resourcemetrics)
+
+ timemetrics = {
+ :resource1 => 10,
+ :resource2 => 50,
+ :resource3 => 40,
+ :resource4 => 20,
+ }
+ report.add_metric(:times, timemetrics)
+
+
+ report.add_metric(
+ :changes,
- :total => 20
- )
+ :total => 20
+ )
- report.save
- end
+ report.save
+ end
end
diff --git a/spec/integration/indirector/rest_spec.rb b/spec/integration/indirector/rest_spec.rb
index 57ace8562..e9048392a 100755
--- a/spec/integration/indirector/rest_spec.rb
+++ b/spec/integration/indirector/rest_spec.rb
@@ -7,23 +7,23 @@ require 'puppet/indirector/rest'
# a fake class that will be indirected via REST
class Puppet::TestIndirectedFoo
- extend Puppet::Indirector
- indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
+ extend Puppet::Indirector
+ indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
- attr_reader :value
- attr_accessor :name
+ attr_reader :value
+ attr_accessor :name
- def initialize(value = 0)
- @value = value
- end
+ def initialize(value = 0)
+ @value = value
+ end
- def self.from_yaml(yaml)
- YAML.load(yaml)
- end
+ def self.from_yaml(yaml)
+ YAML.load(yaml)
+ end
- def name
- "bob"
- end
+ def name
+ "bob"
+ end
end
# empty Terminus class -- this would normally have to be in a directory findable by the autoloader, but we short-circuit that below
@@ -32,493 +32,493 @@ end
describe Puppet::Indirector::REST do
- before do
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
+ before do
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::SSL::Host.ca_location = :local
+
+ Puppet::TestIndirectedFoo.terminus_class = :rest
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ end
+
+ describe "when using webrick" do
+ before :each do
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :test_indirected_foo ], :xmlrpc_handlers => [ :status ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @mock_model = stub('faked model', :name => "foo")
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ # do not trigger the authorization layer
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
+ end
+
+ describe "when finding a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @model_instance = Puppet::TestIndirectedFoo.new(23)
+ @mock_model.stubs(:find).returns @model_instance
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
+ end
+
+ it 'should return an instance of the model class' do
+ Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
+ end
+
+ it "should pass options all the way through" do
+ @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
+ Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
+ end
+
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
+ end
+
+ it "should use a supported format" do
+ Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
+ text = Marshal.dump(@model_instance)
+ @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
+ Puppet::TestIndirectedFoo.find('bar')
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :name => "foo", :find => nil)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model', :name => "foo")
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
+
+ describe "when searching for model instances over REST" do
+ describe "when matching model instances can be found" do
+ before :each do
+ @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+ @mock_model.stubs(:search).returns @model_instances
+
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
+ @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
+ end
+
+ it 'should return all matching results' do
+ Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
+ end
+
+ it "should pass options all the way through" do
+ @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
+ Puppet::TestIndirectedFoo.search("foo", :one => "two", :three => "four")
+ end
+
+ it 'should return model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.class.should == Puppet::TestIndirectedFoo
+ end
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :name => "foo", :find => nil)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
+
+ describe "when destroying a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:destroy).returns true
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
+ end
+
+ it 'should return success' do
+ Puppet::TestIndirectedFoo.destroy('bar').should == true
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:destroy).returns false
+ end
+
+ it "should return failure" do
+ Puppet::TestIndirectedFoo.destroy('bar').should == false
+ end
+ end
+
+ describe "when an exception is encountered in destroying a model instance" do
+ before :each do
+ @mock_model.stubs(:destroy).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
+
+ describe "when saving a model instance over REST" do
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model.stubs(:save_object).returns @instance
+ @mock_model.stubs(:convert_from).returns @instance
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
+ end
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
- Puppet.settings[:server] = "127.0.0.1"
- Puppet.settings[:masterport] = "34343"
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
- Puppet::SSL::Host.ca_location = :local
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
- Puppet::TestIndirectedFoo.terminus_class = :rest
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
+
+ after :each do
+ @server.unlisten
+ end
+ end
+
+ describe "when using mongrel" do
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
+ before :each do
+ Puppet[:servertype] = 'mongrel'
+ @params = { :port => 34343, :handlers => [ :test_indirected_foo ] }
+
+ # Make sure we never get a cert, since mongrel can't speak ssl
+ Puppet::SSL::Certificate.stubs(:find).returns nil
+
+ # We stub ssl to be off, since mongrel can't speak ssl
+ Net::HTTP.any_instance.stubs(:use_ssl?).returns false
+
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @mock_model = stub('faked model', :name => "foo")
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ # do not trigger the authorization layer
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:check_authorization).returns(true)
end
after do
- Puppet::Network::HttpPool.expire
- Puppet::SSL::Host.ca_location = :none
- Puppet.settings.clear
+ @server.unlisten
end
- describe "when using webrick" do
+ describe "when finding a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @model_instance = Puppet::TestIndirectedFoo.new(23)
+ @mock_model.stubs(:find).returns @model_instance
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
+ end
+
+ it 'should return an instance of the model class' do
+ Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
+ end
+
+ it "should pass options all the way through" do
+ @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
+ Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
+ end
+
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
+ end
+
+ it "should use a supported format" do
+ Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
+ format = stub 'format'
+ text = Marshal.dump(@model_instance)
+ @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
+ Puppet::TestIndirectedFoo.find('bar')
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:find).returns nil
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
before :each do
- Puppet::Util::Cacher.expire
-
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- Puppet[:certname] = '127.0.0.1'
-
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
-
- @params = { :port => 34343, :handlers => [ :test_indirected_foo ], :xmlrpc_handlers => [ :status ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @mock_model = stub('faked model', :name => "foo")
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- # do not trigger the authorization layer
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
- end
-
- describe "when finding a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @model_instance = Puppet::TestIndirectedFoo.new(23)
- @mock_model.stubs(:find).returns @model_instance
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
- end
-
- it "should pass options all the way through" do
- @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
- Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
- end
-
- it 'should set an expiration on model instance' do
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
- end
-
- it "should use a supported format" do
- Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
- text = Marshal.dump(@model_instance)
- @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
- Puppet::TestIndirectedFoo.find('bar')
- end
- end
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :name => "foo", :find => nil)
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
-
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model', :name => "foo")
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when searching for model instances over REST" do
- describe "when matching model instances can be found" do
- before :each do
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
- @mock_model.stubs(:search).returns @model_instances
-
- # Force yaml, because otherwise our mocks can't work correctly
- Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
-
- @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
- end
-
- it 'should return all matching results' do
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
- end
-
- it "should pass options all the way through" do
- @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
- Puppet::TestIndirectedFoo.search("foo", :one => "two", :three => "four")
- end
-
- it 'should return model instances' do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.class.should == Puppet::TestIndirectedFoo
- end
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
- end
- end
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :name => "foo", :find => nil)
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
-
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when destroying a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @mock_model.stubs(:destroy).returns true
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
- end
-
- it 'should return success' do
- Puppet::TestIndirectedFoo.destroy('bar').should == true
- end
- end
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model.stubs(:destroy).returns false
- end
-
- it "should return failure" do
- Puppet::TestIndirectedFoo.destroy('bar').should == false
- end
- end
-
- describe "when an exception is encountered in destroying a model instance" do
- before :each do
- @mock_model.stubs(:destroy).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when saving a model instance over REST" do
- before :each do
- @instance = Puppet::TestIndirectedFoo.new(42)
- @mock_model.stubs(:save_object).returns @instance
- @mock_model.stubs(:convert_from).returns @instance
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
- end
-
- describe "when a successful save can be performed" do
- before :each do
- end
-
- it "should not fail" do
- lambda { @instance.save }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- @instance.save.class.should == Puppet::TestIndirectedFoo
- end
-
- it 'should return a matching instance of the model class' do
- @instance.save.value.should == @instance.value
- end
- end
-
- describe "when a save cannot be completed" do
- before :each do
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
- end
-
- it "should return failure" do
- @instance.save.should == false
- end
- end
-
- describe "when an exception is encountered in performing a save" do
- before :each do
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { @instance.save }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- after :each do
- @server.unlisten
+ @mock_model.stubs(:find).raises(RuntimeError)
end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
end
- describe "when using mongrel" do
- confine "Mongrel is not available" => Puppet.features.mongrel?
+ describe "when searching for model instances over REST" do
+ describe "when matching model instances can be found" do
+ before :each do
+ @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
+ @mock_model.stubs(:search).returns @model_instances
+ @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
+ end
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
+ end
+
+ it 'should return all matching results' do
+ Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
+ end
+
+ it "should pass options all the way through" do
+ @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
+ Puppet::TestIndirectedFoo.search('bar', :one => "two", :three => "four")
+ end
+
+ it 'should return model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.class.should == Puppet::TestIndirectedFoo
+ end
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
+ 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
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:search).returns nil
+ @mock_model.stubs(:render_multiple).returns nil.to_yaml
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.search('bar').should == []
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
before :each do
- Puppet[:servertype] = 'mongrel'
- @params = { :port => 34343, :handlers => [ :test_indirected_foo ] }
+ @mock_model.stubs(:find).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
- # Make sure we never get a cert, since mongrel can't speak ssl
- Puppet::SSL::Certificate.stubs(:find).returns nil
+ describe "when destroying a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:destroy).returns true
+ end
- # We stub ssl to be off, since mongrel can't speak ssl
- Net::HTTP.any_instance.stubs(:use_ssl?).returns false
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
+ end
+
+ it 'should return success' do
+ Puppet::TestIndirectedFoo.destroy('bar').should == true
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model.stubs(:destroy).returns false
+ end
+
+ it "should return failure" do
+ Puppet::TestIndirectedFoo.destroy('bar').should == false
+ end
+ end
+
+ describe "when an exception is encountered in destroying a model instance" do
+ before :each do
+ @mock_model.stubs(:destroy).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
+ end
+ end
+ end
+
+ describe "when saving a model instance over REST" do
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model.stubs(:convert_from).returns @instance
+
+ # LAK:NOTE This stub is necessary to prevent the REST call from calling
+ # REST.save again, thus producing painful infinite recursion.
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
+ end
+
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
+
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
- @server = Puppet::Network::Server.new(@params)
- @server.listen
-
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
- # return.
- @mock_model = stub('faked model', :name => "foo")
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
-
- # do not trigger the authorization layer
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:check_authorization).returns(true)
- end
-
- after do
- @server.unlisten
- end
-
- describe "when finding a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @model_instance = Puppet::TestIndirectedFoo.new(23)
- @mock_model.stubs(:find).returns @model_instance
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
- end
-
- it "should pass options all the way through" do
- @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
- Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
- end
-
- it 'should set an expiration on model instance' do
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
- end
-
- it "should use a supported format" do
- Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
- format = stub 'format'
- text = Marshal.dump(@model_instance)
- @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
- Puppet::TestIndirectedFoo.find('bar')
- end
- end
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model.stubs(:find).returns nil
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
-
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model.stubs(:find).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when searching for model instances over REST" do
- describe "when matching model instances can be found" do
- before :each do
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
-
- # Force yaml, because otherwise our mocks can't work correctly
- Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
-
- @mock_model.stubs(:search).returns @model_instances
- @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
- end
-
- it 'should return all matching results' do
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
- end
-
- it "should pass options all the way through" do
- @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
- Puppet::TestIndirectedFoo.search('bar', :one => "two", :three => "four")
- end
-
- it 'should return model instances' do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.class.should == Puppet::TestIndirectedFoo
- end
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
- 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
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model.stubs(:search).returns nil
- @mock_model.stubs(:render_multiple).returns nil.to_yaml
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.search('bar').should == []
- end
- end
-
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model.stubs(:find).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when destroying a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @mock_model.stubs(:destroy).returns true
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
- end
-
- it 'should return success' do
- Puppet::TestIndirectedFoo.destroy('bar').should == true
- end
- end
-
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model.stubs(:destroy).returns false
- end
-
- it "should return failure" do
- Puppet::TestIndirectedFoo.destroy('bar').should == false
- end
- end
-
- describe "when an exception is encountered in destroying a model instance" do
- before :each do
- @mock_model.stubs(:destroy).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
- end
- end
- end
-
- describe "when saving a model instance over REST" do
- before :each do
- @instance = Puppet::TestIndirectedFoo.new(42)
- @mock_model.stubs(:convert_from).returns @instance
-
- # LAK:NOTE This stub is necessary to prevent the REST call from calling
- # REST.save again, thus producing painful infinite recursion.
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
- end
-
- describe "when a successful save can be performed" do
- before :each do
- end
-
- it "should not fail" do
- lambda { @instance.save }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- @instance.save.class.should == Puppet::TestIndirectedFoo
- end
-
- it 'should return a matching instance of the model class' do
- @instance.save.value.should == @instance.value
- end
- end
-
- describe "when a save cannot be completed" do
- before :each do
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
- end
-
- it "should return failure" do
- @instance.save.should == false
- end
- end
-
- describe "when an exception is encountered in performing a save" do
- before :each do
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { @instance.save }.should raise_error(Net::HTTPError)
- end
- end
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(Net::HTTPError)
end
+ end
end
+ end
end
diff --git a/spec/integration/network/client_spec.rb b/spec/integration/network/client_spec.rb
index 06d145a17..4bf3ad82b 100755
--- a/spec/integration/network/client_spec.rb
+++ b/spec/integration/network/client_spec.rb
@@ -5,15 +5,15 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/client'
describe Puppet::Network::Client do
- %w{ca file report runner status}.each do |name|
- it "should have a #{name} client" do
- Puppet::Network::Client.client(name).should be_instance_of(Class)
- end
+ %w{ca file report runner status}.each do |name|
+ it "should have a #{name} client" do
+ Puppet::Network::Client.client(name).should be_instance_of(Class)
+ end
- [:name, :handler, :drivername].each do |data|
- it "should have a #{data} value for the #{name} client" do
- Puppet::Network::Client.client(name).send(data).should_not be_nil
- end
- end
+ [:name, :handler, :drivername].each do |data|
+ it "should have a #{data} value for the #{name} client" do
+ Puppet::Network::Client.client(name).send(data).should_not be_nil
+ end
end
+ end
end
diff --git a/spec/integration/network/formats_spec.rb b/spec/integration/network/formats_spec.rb
index 35e797706..e6cf28abb 100755
--- a/spec/integration/network/formats_spec.rb
+++ b/spec/integration/network/formats_spec.rb
@@ -5,106 +5,106 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/formats'
class PsonIntTest
- attr_accessor :string
- def ==(other)
- other.class == self.class and string == other.string
- end
-
- def self.from_pson(data)
- new(data[0])
- end
-
- def initialize(string)
- @string = string
- end
-
- def to_pson(*args)
- {
- 'type' => self.class.name,
- 'data' => [@string]
- }.to_pson(*args)
- end
-
- def self.canonical_order(s)
- s.gsub(/\{"data":\[(.*?)\],"type":"PsonIntTest"\}/,'{"type":"PsonIntTest","data":[\1]}')
- end
+ attr_accessor :string
+ def ==(other)
+ other.class == self.class and string == other.string
+ end
+
+ def self.from_pson(data)
+ new(data[0])
+ end
+
+ def initialize(string)
+ @string = string
+ end
+
+ def to_pson(*args)
+ {
+ 'type' => self.class.name,
+ 'data' => [@string]
+ }.to_pson(*args)
+ end
+
+ def self.canonical_order(s)
+ s.gsub(/\{"data":\[(.*?)\],"type":"PsonIntTest"\}/,'{"type":"PsonIntTest","data":[\1]}')
+ end
end
describe Puppet::Network::FormatHandler.format(:s) do
- before do
- @format = Puppet::Network::FormatHandler.format(:s)
- end
+ before do
+ @format = Puppet::Network::FormatHandler.format(:s)
+ end
- it "should support certificates" do
- @format.should be_supported(Puppet::SSL::Certificate)
- end
+ it "should support certificates" do
+ @format.should be_supported(Puppet::SSL::Certificate)
+ end
- it "should not support catalogs" do
- @format.should_not be_supported(Puppet::Resource::Catalog)
- end
+ it "should not support catalogs" do
+ @format.should_not be_supported(Puppet::Resource::Catalog)
+ end
end
describe Puppet::Network::FormatHandler.format(:pson) do
- describe "when pson is absent" do
- confine "'pson' library is present" => (! Puppet.features.pson?)
+ describe "when pson is absent" do
+ confine "'pson' library is present" => (! Puppet.features.pson?)
- before do
- @pson = Puppet::Network::FormatHandler.format(:pson)
- end
+ before do
+ @pson = Puppet::Network::FormatHandler.format(:pson)
+ end
- it "should not be suitable" do
- @pson.should_not be_suitable
- end
+ it "should not be suitable" do
+ @pson.should_not be_suitable
end
+ end
- describe "when pson is available" do
- confine "Missing 'pson' library" => Puppet.features.pson?
+ describe "when pson is available" do
+ confine "Missing 'pson' library" => Puppet.features.pson?
- before do
- @pson = Puppet::Network::FormatHandler.format(:pson)
- end
+ before do
+ @pson = Puppet::Network::FormatHandler.format(:pson)
+ end
- it "should be able to render an instance to pson" do
- instance = PsonIntTest.new("foo")
- PsonIntTest.canonical_order(@pson.render(instance)).should == PsonIntTest.canonical_order('{"type":"PsonIntTest","data":["foo"]}' )
- end
+ it "should be able to render an instance to pson" do
+ instance = PsonIntTest.new("foo")
+ PsonIntTest.canonical_order(@pson.render(instance)).should == PsonIntTest.canonical_order('{"type":"PsonIntTest","data":["foo"]}' )
+ end
- it "should be able to render arrays to pson" do
- @pson.render([1,2]).should == '[1,2]'
- end
+ it "should be able to render arrays to pson" do
+ @pson.render([1,2]).should == '[1,2]'
+ end
- it "should be able to render arrays containing hashes to pson" do
- @pson.render([{"one"=>1},{"two"=>2}]).should == '[{"one":1},{"two":2}]'
- end
+ it "should be able to render arrays containing hashes to pson" do
+ @pson.render([{"one"=>1},{"two"=>2}]).should == '[{"one":1},{"two":2}]'
+ end
- it "should be able to render multiple instances to pson" do
- Puppet.features.add(:pson, :libs => ["pson"])
+ it "should be able to render multiple instances to pson" do
+ Puppet.features.add(:pson, :libs => ["pson"])
- one = PsonIntTest.new("one")
- two = PsonIntTest.new("two")
+ one = PsonIntTest.new("one")
+ two = PsonIntTest.new("two")
- PsonIntTest.canonical_order(@pson.render([one,two])).should == PsonIntTest.canonical_order('[{"type":"PsonIntTest","data":["one"]},{"type":"PsonIntTest","data":["two"]}]')
- end
+ PsonIntTest.canonical_order(@pson.render([one,two])).should == PsonIntTest.canonical_order('[{"type":"PsonIntTest","data":["one"]},{"type":"PsonIntTest","data":["two"]}]')
+ end
- it "should be able to intern pson into an instance" do
- @pson.intern(PsonIntTest, '{"type":"PsonIntTest","data":["foo"]}').should == PsonIntTest.new("foo")
- end
+ it "should be able to intern pson into an instance" do
+ @pson.intern(PsonIntTest, '{"type":"PsonIntTest","data":["foo"]}').should == PsonIntTest.new("foo")
+ end
- it "should be able to intern pson with no class information into an instance" do
- @pson.intern(PsonIntTest, '["foo"]').should == PsonIntTest.new("foo")
- end
+ it "should be able to intern pson with no class information into an instance" do
+ @pson.intern(PsonIntTest, '["foo"]').should == PsonIntTest.new("foo")
+ end
- it "should be able to intern multiple instances from pson" do
- @pson.intern_multiple(PsonIntTest, '[{"type": "PsonIntTest", "data": ["one"]},{"type": "PsonIntTest", "data": ["two"]}]').should == [
- PsonIntTest.new("one"), PsonIntTest.new("two")
- ]
- end
+ it "should be able to intern multiple instances from pson" do
+ @pson.intern_multiple(PsonIntTest, '[{"type": "PsonIntTest", "data": ["one"]},{"type": "PsonIntTest", "data": ["two"]}]').should == [
+ PsonIntTest.new("one"), PsonIntTest.new("two")
+ ]
+ end
- it "should be able to intern multiple instances from pson with no class information" do
- @pson.intern_multiple(PsonIntTest, '[["one"],["two"]]').should == [
- PsonIntTest.new("one"), PsonIntTest.new("two")
- ]
- end
+ it "should be able to intern multiple instances from pson with no class information" do
+ @pson.intern_multiple(PsonIntTest, '[["one"],["two"]]').should == [
+ PsonIntTest.new("one"), PsonIntTest.new("two")
+ ]
end
+ end
end
diff --git a/spec/integration/network/handler_spec.rb b/spec/integration/network/handler_spec.rb
index 1c2e60549..021f1cedb 100755
--- a/spec/integration/network/handler_spec.rb
+++ b/spec/integration/network/handler_spec.rb
@@ -5,21 +5,21 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/client'
describe Puppet::Network::Handler do
- %w{ca filebucket fileserver master report runner status}.each do |name|
- it "should have a #{name} client" do
- Puppet::Network::Handler.handler(name).should be_instance_of(Class)
- end
+ %w{ca filebucket fileserver master report runner status}.each do |name|
+ it "should have a #{name} client" do
+ Puppet::Network::Handler.handler(name).should be_instance_of(Class)
+ end
- it "should have a name" do
- Puppet::Network::Handler.handler(name).name.to_s.downcase.should == name.to_s.downcase
- end
+ it "should have a name" do
+ Puppet::Network::Handler.handler(name).name.to_s.downcase.should == name.to_s.downcase
+ end
- it "should have an interface" do
- Puppet::Network::Handler.handler(name).interface.should_not be_nil
- end
+ it "should have an interface" do
+ Puppet::Network::Handler.handler(name).interface.should_not be_nil
+ end
- it "should have a prefix for the interface" do
- Puppet::Network::Handler.handler(name).interface.prefix.should_not be_nil
- end
+ it "should have a prefix for the interface" do
+ Puppet::Network::Handler.handler(name).interface.prefix.should_not be_nil
end
+ end
end
diff --git a/spec/integration/network/server/mongrel_spec.rb b/spec/integration/network/server/mongrel_spec.rb
index 1365fbd41..cc90773e6 100755
--- a/spec/integration/network/server/mongrel_spec.rb
+++ b/spec/integration/network/server/mongrel_spec.rb
@@ -5,62 +5,62 @@ require 'puppet/network/server'
require 'socket'
describe Puppet::Network::Server do
- describe "when using mongrel" do
- confine "Mongrel is not available" => Puppet.features.mongrel?
+ describe "when using mongrel" do
+ confine "Mongrel is not available" => Puppet.features.mongrel?
- before :each do
- Puppet[:servertype] = 'mongrel'
- Puppet[:server] = '127.0.0.1'
- @params = { :port => 34346, :handlers => [ :node ] }
- @server = Puppet::Network::Server.new(@params)
- end
+ before :each do
+ Puppet[:servertype] = 'mongrel'
+ Puppet[:server] = '127.0.0.1'
+ @params = { :port => 34346, :handlers => [ :node ] }
+ @server = Puppet::Network::Server.new(@params)
+ end
- after { Puppet.settings.clear }
+ after { Puppet.settings.clear }
- describe "before listening" do
- it "should not be reachable at the specified address and port" do
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
- end
- end
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
- describe "when listening" do
- it "should be reachable on the specified address and port" do
- @server.listen
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should_not raise_error
- end
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should_not raise_error
+ end
- it "should default to '127.0.0.1' as its bind address" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
- @server.send(:http_server).expects(:listen).with { |args| args[:address] == "127.0.0.1" }
- @server.listen
- end
+ it "should default to '127.0.0.1' as its bind address" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
+ @server.send(:http_server).expects(:listen).with { |args| args[:address] == "127.0.0.1" }
+ @server.listen
+ end
- it "should use any specified bind address" do
- Puppet[:bindaddress] = "0.0.0.0"
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
- @server.send(:http_server).expects(:listen).with { |args| args[:address] == "0.0.0.0" }
- @server.listen
- end
+ it "should use any specified bind address" do
+ Puppet[:bindaddress] = "0.0.0.0"
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
+ @server.send(:http_server).expects(:listen).with { |args| args[:address] == "0.0.0.0" }
+ @server.listen
+ end
- it "should not allow multiple servers to listen on the same address and port" do
- @server.listen
- @server2 = Puppet::Network::Server.new(@params)
- lambda { @server2.listen }.should raise_error
- end
- end
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params)
+ lambda { @server2.listen }.should raise_error
+ end
+ end
- describe "after unlistening" do
- it "should not be reachable on the port and address assigned" do
- @server.listen
- @server.unlisten
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
- end
- end
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
- after :each do
- @server.unlisten if @server.listening?
- end
+ after :each do
+ @server.unlisten if @server.listening?
end
+ end
end
diff --git a/spec/integration/network/server/webrick_spec.rb b/spec/integration/network/server/webrick_spec.rb
index 50994f119..2809df780 100755
--- a/spec/integration/network/server/webrick_spec.rb
+++ b/spec/integration/network/server/webrick_spec.rb
@@ -6,80 +6,80 @@ require 'puppet/ssl/certificate_authority'
require 'socket'
describe Puppet::Network::Server do
- describe "when using webrick" do
- before :each do
- Puppet[:servertype] = 'webrick'
- Puppet[:server] = '127.0.0.1'
- @params = { :port => 34343, :handlers => [ :node ], :xmlrpc_handlers => [ :status ] }
-
- # Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
-
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
-
- Puppet::SSL::Host.ca_location = :local
-
- ca = Puppet::SSL::CertificateAuthority.new
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
- end
-
- after do
- @tmpfile.delete
- Puppet.settings.clear
-
- system("rm -rf #{@dir}")
-
- Puppet::Util::Cacher.expire
- end
-
- describe "before listening" do
- it "should not be reachable at the specified address and port" do
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error
- end
- end
-
- describe "when listening" do
- it "should be reachable on the specified address and port" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should_not raise_error
- end
-
- it "should default to '0.0.0.0' as its bind address" do
- Puppet.settings.clear
- Puppet[:servertype] = 'webrick'
- Puppet[:bindaddress].should == '0.0.0.0'
- end
-
- it "should use any specified bind address" do
- Puppet[:bindaddress] = "127.0.0.1"
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
- @server.send(:http_server).expects(:listen).with { |args| args[:address] == "127.0.0.1" }
- @server.listen
- end
-
- it "should not allow multiple servers to listen on the same address and port" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- @server2 = Puppet::Network::Server.new(@params.merge(:port => 34343))
- lambda { @server2.listen }.should raise_error
- end
-
- after :each do
- @server.unlisten if @server && @server.listening?
- end
- end
-
- describe "after unlistening" do
- it "should not be reachable on the port and address assigned" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- @server.unlisten
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error(Errno::ECONNREFUSED)
- end
- end
+ describe "when using webrick" do
+ before :each do
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ @params = { :port => 34343, :handlers => [ :node ], :xmlrpc_handlers => [ :status ] }
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+
+ Puppet::SSL::Host.ca_location = :local
+
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ end
+
+ after do
+ @tmpfile.delete
+ Puppet.settings.clear
+
+ system("rm -rf #{@dir}")
+
+ Puppet::Util::Cacher.expire
+ end
+
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error
+ end
+ end
+
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should_not raise_error
+ end
+
+ it "should default to '0.0.0.0' as its bind address" do
+ Puppet.settings.clear
+ Puppet[:servertype] = 'webrick'
+ Puppet[:bindaddress].should == '0.0.0.0'
+ end
+
+ it "should use any specified bind address" do
+ Puppet[:bindaddress] = "127.0.0.1"
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.stubs(:unlisten) # we're breaking listening internally, so we have to keep it from unlistening
+ @server.send(:http_server).expects(:listen).with { |args| args[:address] == "127.0.0.1" }
+ @server.listen
+ end
+
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ lambda { @server2.listen }.should raise_error
+ end
+
+ after :each do
+ @server.unlisten if @server && @server.listening?
+ end
+ end
+
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error(Errno::ECONNREFUSED)
+ end
end
+ end
end
diff --git a/spec/integration/node/environment_spec.rb b/spec/integration/node/environment_spec.rb
index 68dfd93a3..8c5153749 100755
--- a/spec/integration/node/environment_spec.rb
+++ b/spec/integration/node/environment_spec.rb
@@ -5,54 +5,54 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet_spec/files'
describe Puppet::Node::Environment do
- include PuppetSpec::Files
-
- it "should be able to return each module from its environment with the environment, name, and path set correctly" do
- base = tmpfile("env_modules")
- Dir.mkdir(base)
-
- dirs = []
- mods = {}
- %w{1 2}.each do |num|
- dir = File.join(base, "dir#{num}")
- dirs << dir
- Dir.mkdir(dir)
- mod = "mod#{num}"
- moddir = File.join(dir, mod)
- mods[mod] = moddir
- Dir.mkdir(moddir)
- end
-
- environment = Puppet::Node::Environment.new("foo")
- environment.stubs(:modulepath).returns dirs
-
- environment.modules.each do |mod|
- mod.environment.should == environment
- mod.path.should == mods[mod.name]
- end
+ include PuppetSpec::Files
+
+ it "should be able to return each module from its environment with the environment, name, and path set correctly" do
+ base = tmpfile("env_modules")
+ Dir.mkdir(base)
+
+ dirs = []
+ mods = {}
+ %w{1 2}.each do |num|
+ dir = File.join(base, "dir#{num}")
+ dirs << dir
+ Dir.mkdir(dir)
+ mod = "mod#{num}"
+ moddir = File.join(dir, mod)
+ mods[mod] = moddir
+ Dir.mkdir(moddir)
end
- it "should not yield the same module from different module paths" do
- base = tmpfile("env_modules")
- Dir.mkdir(base)
-
- dirs = []
- mods = {}
- %w{1 2}.each do |num|
- dir = File.join(base, "dir#{num}")
- dirs << dir
- Dir.mkdir(dir)
- mod = "mod"
- moddir = File.join(dir, mod)
- mods[mod] = moddir
- Dir.mkdir(moddir)
- end
-
- environment = Puppet::Node::Environment.new("foo")
- environment.stubs(:modulepath).returns dirs
-
- mods = environment.modules
- mods.length.should == 1
- mods[0].path.should == File.join(base, "dir1", "mod")
+ environment = Puppet::Node::Environment.new("foo")
+ environment.stubs(:modulepath).returns dirs
+
+ environment.modules.each do |mod|
+ mod.environment.should == environment
+ mod.path.should == mods[mod.name]
+ end
+ end
+
+ it "should not yield the same module from different module paths" do
+ base = tmpfile("env_modules")
+ Dir.mkdir(base)
+
+ dirs = []
+ mods = {}
+ %w{1 2}.each do |num|
+ dir = File.join(base, "dir#{num}")
+ dirs << dir
+ Dir.mkdir(dir)
+ mod = "mod"
+ moddir = File.join(dir, mod)
+ mods[mod] = moddir
+ Dir.mkdir(moddir)
end
+
+ environment = Puppet::Node::Environment.new("foo")
+ environment.stubs(:modulepath).returns dirs
+
+ mods = environment.modules
+ mods.length.should == 1
+ mods[0].path.should == File.join(base, "dir1", "mod")
+ end
end
diff --git a/spec/integration/node/facts_spec.rb b/spec/integration/node/facts_spec.rb
index 0a4d21ed6..4cc2f4c1f 100755
--- a/spec/integration/node/facts_spec.rb
+++ b/spec/integration/node/facts_spec.rb
@@ -6,42 +6,42 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Facts do
- describe "when using the indirector" do
- after { Puppet::Util::Cacher.expire }
+ describe "when using the indirector" do
+ after { Puppet::Util::Cacher.expire }
- it "should expire any cached node instances when it is saved" do
- Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
+ it "should expire any cached node instances when it is saved" do
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
- Puppet::Node::Facts.indirection.terminus(:yaml).should equal(Puppet::Node::Facts.indirection.terminus(:yaml))
- terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
- terminus.stubs :save
+ Puppet::Node::Facts.indirection.terminus(:yaml).should equal(Puppet::Node::Facts.indirection.terminus(:yaml))
+ terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
+ terminus.stubs :save
- Puppet::Node.expects(:expire).with("me")
+ Puppet::Node.expects(:expire).with("me")
- facts = Puppet::Node::Facts.new("me")
- facts.save
- end
+ facts = Puppet::Node::Facts.new("me")
+ facts.save
+ end
- it "should be able to delegate to the :yaml terminus" do
- Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
+ it "should be able to delegate to the :yaml terminus" do
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
- # Load now, before we stub the exists? method.
- terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
+ # Load now, before we stub the exists? method.
+ terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
- terminus.expects(:path).with("me").returns "/my/yaml/file"
- FileTest.expects(:exist?).with("/my/yaml/file").returns false
+ terminus.expects(:path).with("me").returns "/my/yaml/file"
+ FileTest.expects(:exist?).with("/my/yaml/file").returns false
- Puppet::Node::Facts.find("me").should be_nil
- end
+ Puppet::Node::Facts.find("me").should be_nil
+ end
- it "should be able to delegate to the :facter terminus" do
- Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :facter
+ it "should be able to delegate to the :facter terminus" do
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :facter
- Facter.expects(:to_hash).returns "facter_hash"
- facts = Puppet::Node::Facts.new("me")
- Puppet::Node::Facts.expects(:new).with("me", "facter_hash").returns facts
+ Facter.expects(:to_hash).returns "facter_hash"
+ facts = Puppet::Node::Facts.new("me")
+ Puppet::Node::Facts.expects(:new).with("me", "facter_hash").returns facts
- Puppet::Node::Facts.find("me").should equal(facts)
- end
+ Puppet::Node::Facts.find("me").should equal(facts)
end
+ end
end
diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb
index de95d0e79..c635e7f32 100755
--- a/spec/integration/node_spec.rb
+++ b/spec/integration/node_spec.rb
@@ -8,86 +8,86 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/node'
describe Puppet::Node do
- describe "when delegating indirection calls" do
- before do
- @name = "me"
- @node = Puppet::Node.new(@name)
- end
-
- it "should be able to use the exec terminus" do
- Puppet::Node.indirection.stubs(:terminus_class).returns :exec
-
- # Load now so we can stub
- terminus = Puppet::Node.indirection.terminus(:exec)
-
- terminus.expects(:query).with(@name).returns "myresults"
- terminus.expects(:translate).with(@name, "myresults").returns "translated_results"
- terminus.expects(:create_node).with(@name, "translated_results").returns @node
-
- Puppet::Node.find(@name).should equal(@node)
- end
-
- it "should be able to use the yaml terminus" do
- Puppet::Node.indirection.stubs(:terminus_class).returns :yaml
-
- # Load now, before we stub the exists? method.
- terminus = Puppet::Node.indirection.terminus(:yaml)
-
- terminus.expects(:path).with(@name).returns "/my/yaml/file"
-
- FileTest.expects(:exist?).with("/my/yaml/file").returns false
- Puppet::Node.find(@name).should be_nil
- end
-
- it "should have an ldap terminus" do
- Puppet::Node.indirection.terminus(:ldap).should_not be_nil
- end
-
- it "should be able to use the plain terminus" do
- Puppet::Node.indirection.stubs(:terminus_class).returns :plain
-
- # Load now, before we stub the exists? method.
- Puppet::Node.indirection.terminus(:plain)
-
- Puppet::Node.expects(:new).with(@name).returns @node
-
- Puppet::Node.find(@name).should equal(@node)
- end
-
- describe "and using the memory terminus" do
- before do
- @name = "me"
- @old_terminus = Puppet::Node.indirection.terminus_class
- @terminus = Puppet::Node.indirection.terminus(:memory)
- Puppet::Node.indirection.stubs(:terminus).returns @terminus
- @node = Puppet::Node.new(@name)
- end
-
- it "should find no nodes by default" do
- Puppet::Node.find(@name).should be_nil
- end
-
- it "should be able to find nodes that were previously saved" do
- @node.save
- Puppet::Node.find(@name).should equal(@node)
- end
-
- it "should replace existing saved nodes when a new node with the same name is saved" do
- @node.save
- two = Puppet::Node.new(@name)
- two.save
- Puppet::Node.find(@name).should equal(two)
- end
-
- it "should be able to remove previously saved nodes" do
- @node.save
- Puppet::Node.destroy(@node.name)
- Puppet::Node.find(@name).should be_nil
- end
-
- it "should fail when asked to destroy a node that does not exist" do
- proc { Puppet::Node.destroy(@node) }.should raise_error(ArgumentError)
- end
- end
+ describe "when delegating indirection calls" do
+ before do
+ @name = "me"
+ @node = Puppet::Node.new(@name)
end
+
+ it "should be able to use the exec terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :exec
+
+ # Load now so we can stub
+ terminus = Puppet::Node.indirection.terminus(:exec)
+
+ terminus.expects(:query).with(@name).returns "myresults"
+ terminus.expects(:translate).with(@name, "myresults").returns "translated_results"
+ terminus.expects(:create_node).with(@name, "translated_results").returns @node
+
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ it "should be able to use the yaml terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :yaml
+
+ # Load now, before we stub the exists? method.
+ terminus = Puppet::Node.indirection.terminus(:yaml)
+
+ terminus.expects(:path).with(@name).returns "/my/yaml/file"
+
+ FileTest.expects(:exist?).with("/my/yaml/file").returns false
+ Puppet::Node.find(@name).should be_nil
+ end
+
+ it "should have an ldap terminus" do
+ Puppet::Node.indirection.terminus(:ldap).should_not be_nil
+ end
+
+ it "should be able to use the plain terminus" do
+ Puppet::Node.indirection.stubs(:terminus_class).returns :plain
+
+ # Load now, before we stub the exists? method.
+ Puppet::Node.indirection.terminus(:plain)
+
+ Puppet::Node.expects(:new).with(@name).returns @node
+
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ describe "and using the memory terminus" do
+ before do
+ @name = "me"
+ @old_terminus = Puppet::Node.indirection.terminus_class
+ @terminus = Puppet::Node.indirection.terminus(:memory)
+ Puppet::Node.indirection.stubs(:terminus).returns @terminus
+ @node = Puppet::Node.new(@name)
+ end
+
+ it "should find no nodes by default" do
+ Puppet::Node.find(@name).should be_nil
+ end
+
+ it "should be able to find nodes that were previously saved" do
+ @node.save
+ Puppet::Node.find(@name).should equal(@node)
+ end
+
+ it "should replace existing saved nodes when a new node with the same name is saved" do
+ @node.save
+ two = Puppet::Node.new(@name)
+ two.save
+ Puppet::Node.find(@name).should equal(two)
+ end
+
+ it "should be able to remove previously saved nodes" do
+ @node.save
+ Puppet::Node.destroy(@node.name)
+ Puppet::Node.find(@name).should be_nil
+ end
+
+ it "should fail when asked to destroy a node that does not exist" do
+ proc { Puppet::Node.destroy(@node) }.should raise_error(ArgumentError)
+ end
+ end
+ end
end
diff --git a/spec/integration/parser/collector_spec.rb b/spec/integration/parser/collector_spec.rb
index 4b1279e61..73273c909 100755
--- a/spec/integration/parser/collector_spec.rb
+++ b/spec/integration/parser/collector_spec.rb
@@ -5,34 +5,34 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/parser/collector'
describe Puppet::Parser::Collector do
- before do
- @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")))
+ before do
+ @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")))
- @resource = Puppet::Parser::Resource.new("file", "/tmp/testing", :scope => @scope, :source => "fakesource")
- {:owner => "root", :group => "bin", :mode => "644"}.each do |param, value|
- @resource[param] = value
- end
+ @resource = Puppet::Parser::Resource.new("file", "/tmp/testing", :scope => @scope, :source => "fakesource")
+ {:owner => "root", :group => "bin", :mode => "644"}.each do |param, value|
+ @resource[param] = value
end
+ end
- def query(text)
- code = "File <| #{text} |>"
- parser = Puppet::Parser::Parser.new(@scope.compiler)
- parser.parse(code).hostclass("").code[0].query
- end
+ def query(text)
+ code = "File <| #{text} |>"
+ parser = Puppet::Parser::Parser.new(@scope.compiler)
+ parser.parse(code).hostclass("").code[0].query
+ end
- {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin},
- %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin},
- %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"},
- %{(title == "/tmp/testing" or title == bin) and group == bin}],
- false => [%{title == bin}, %{title == bin or (title == bin and group == bin)},
- %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}]
- }.each do |result, ary|
- ary.each do |string|
- it "should return '#{result}' when collecting resources with '#{string}'" do
- str, code = query(string).evaluate @scope
- code.should be_instance_of(Proc)
- code.call(@resource).should == result
- end
- end
+ {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin},
+ %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin},
+ %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"},
+ %{(title == "/tmp/testing" or title == bin) and group == bin}],
+ false => [%{title == bin}, %{title == bin or (title == bin and group == bin)},
+ %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}]
+ }.each do |result, ary|
+ ary.each do |string|
+ it "should return '#{result}' when collecting resources with '#{string}'" do
+ str, code = query(string).evaluate @scope
+ code.should be_instance_of(Proc)
+ code.call(@resource).should == result
+ end
end
+ end
end
diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb
index 512924f6f..83bbf9500 100755
--- a/spec/integration/parser/compiler_spec.rb
+++ b/spec/integration/parser/compiler_spec.rb
@@ -3,27 +3,27 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Parser::Compiler do
- before :each do
- @node = Puppet::Node.new "testnode"
+ before :each do
+ @node = Puppet::Node.new "testnode"
- @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]'
- @scope = stub 'scope', :resource => @scope_resource, :source => mock("source")
- end
+ @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]'
+ @scope = stub 'scope', :resource => @scope_resource, :source => mock("source")
+ end
- after do
- Puppet.settings.clear
- end
+ after do
+ Puppet.settings.clear
+ end
- it "should be able to determine the configuration version from a local version control repository" do
- # This should always work, because we should always be
- # in the puppet repo when we run this.
- version = %x{git rev-parse HEAD}.chomp
+ it "should be able to determine the configuration version from a local version control repository" do
+ # This should always work, because we should always be
+ # in the puppet repo when we run this.
+ version = %x{git rev-parse HEAD}.chomp
- Puppet.settings[:config_version] = 'git rev-parse HEAD'
+ Puppet.settings[:config_version] = 'git rev-parse HEAD'
- @parser = Puppet::Parser::Parser.new "development"
- @compiler = Puppet::Parser::Compiler.new(@node)
+ @parser = Puppet::Parser::Parser.new "development"
+ @compiler = Puppet::Parser::Compiler.new(@node)
- @compiler.catalog.version.should == version
- end
+ @compiler.catalog.version.should == version
+ end
end
diff --git a/spec/integration/parser/functions/require_spec.rb b/spec/integration/parser/functions/require_spec.rb
index 3d65a50f0..8b3beefe9 100755
--- a/spec/integration/parser/functions/require_spec.rb
+++ b/spec/integration/parser/functions/require_spec.rb
@@ -3,42 +3,42 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe "The require function" do
- before :each do
- @node = Puppet::Node.new("mynode")
- @compiler = Puppet::Parser::Compiler.new(@node)
-
- @compiler.send(:evaluate_main)
- @compiler.catalog.client_version = "0.25"
- @scope = @compiler.topscope
- # preload our functions
- Puppet::Parser::Functions.function(:include)
- Puppet::Parser::Functions.function(:require)
- end
-
- it "should add a dependency between the 'required' class and our class" do
- @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass")
-
- @scope.function_require("requiredclass")
- @scope.resource["require"].should_not be_nil
- ref = @scope.resource["require"].shift
- ref.type.should == "Class"
- ref.title.should == "Requiredclass"
- end
-
- it "should queue relationships between the 'required' class and our classes" do
- @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass1")
- @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass2")
-
- @scope.function_require("requiredclass1")
- @scope.function_require("requiredclass2")
-
- @scope.resource["require"].should_not be_nil
-
- (ref1,ref2) = @scope.resource["require"]
- ref1.type.should == "Class"
- ref1.title.should == "Requiredclass1"
- ref2.type.should == "Class"
- ref2.title.should == "Requiredclass2"
- end
+ before :each do
+ @node = Puppet::Node.new("mynode")
+ @compiler = Puppet::Parser::Compiler.new(@node)
+
+ @compiler.send(:evaluate_main)
+ @compiler.catalog.client_version = "0.25"
+ @scope = @compiler.topscope
+ # preload our functions
+ Puppet::Parser::Functions.function(:include)
+ Puppet::Parser::Functions.function(:require)
+ end
+
+ it "should add a dependency between the 'required' class and our class" do
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass")
+
+ @scope.function_require("requiredclass")
+ @scope.resource["require"].should_not be_nil
+ ref = @scope.resource["require"].shift
+ ref.type.should == "Class"
+ ref.title.should == "Requiredclass"
+ end
+
+ it "should queue relationships between the 'required' class and our classes" do
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass1")
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "requiredclass2")
+
+ @scope.function_require("requiredclass1")
+ @scope.function_require("requiredclass2")
+
+ @scope.resource["require"].should_not be_nil
+
+ (ref1,ref2) = @scope.resource["require"]
+ ref1.type.should == "Class"
+ ref1.title.should == "Requiredclass1"
+ ref2.type.should == "Class"
+ ref2.title.should == "Requiredclass2"
+ end
end
diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb
index ff81758d1..7b85bcacb 100755
--- a/spec/integration/parser/parser_spec.rb
+++ b/spec/integration/parser/parser_spec.rb
@@ -3,111 +3,111 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Parser::Parser do
- module ParseMatcher
- class ParseAs
- def initialize(klass)
- @parser = Puppet::Parser::Parser.new "development"
- @class = klass
- end
-
- def result_instance
- @result.hostclass("").code[0]
- end
-
- def matches?(string)
- @string = string
- @result = @parser.parse(string)
- result_instance.instance_of?(@class)
- end
-
- def description
- "parse as a #{@class}"
- end
-
- def failure_message
- " expected #{@string} to parse as #{@class} but was #{result_instance.class}"
- end
-
- def negative_failure_message
- " expected #{@string} not to parse as #{@class}"
- end
- end
-
- def parse_as(klass)
- ParseAs.new(klass)
- end
-
- class ParseWith
- def initialize(block)
- @parser = Puppet::Parser::Parser.new "development"
- @block = block
- end
-
- def result_instance
- @result.hostclass("").code[0]
- end
-
- def matches?(string)
- @string = string
- @result = @parser.parse(string)
- @block.call(result_instance)
- end
-
- def description
- "parse with the block evaluating to true"
- end
-
- def failure_message
- " expected #{@string} to parse with a true result in the block"
- end
-
- def negative_failure_message
- " expected #{@string} not to parse with a true result in the block"
- end
- end
-
- def parse_with(&block)
- ParseWith.new(block)
- end
+ module ParseMatcher
+ class ParseAs
+ def initialize(klass)
+ @parser = Puppet::Parser::Parser.new "development"
+ @class = klass
+ end
+
+ def result_instance
+ @result.hostclass("").code[0]
+ end
+
+ def matches?(string)
+ @string = string
+ @result = @parser.parse(string)
+ result_instance.instance_of?(@class)
+ end
+
+ def description
+ "parse as a #{@class}"
+ end
+
+ def failure_message
+ " expected #{@string} to parse as #{@class} but was #{result_instance.class}"
+ end
+
+ def negative_failure_message
+ " expected #{@string} not to parse as #{@class}"
+ end
end
- include ParseMatcher
+ def parse_as(klass)
+ ParseAs.new(klass)
+ end
- before :each do
- @resource_type_collection = Puppet::Resource::TypeCollection.new("env")
+ class ParseWith
+ def initialize(block)
@parser = Puppet::Parser::Parser.new "development"
+ @block = block
+ end
+
+ def result_instance
+ @result.hostclass("").code[0]
+ end
+
+ def matches?(string)
+ @string = string
+ @result = @parser.parse(string)
+ @block.call(result_instance)
+ end
+
+ def description
+ "parse with the block evaluating to true"
+ end
+
+ def failure_message
+ " expected #{@string} to parse with a true result in the block"
+ end
+
+ def negative_failure_message
+ " expected #{@string} not to parse with a true result in the block"
+ end
end
- describe "when parsing comments before statement" do
- it "should associate the documentation to the statement AST node" do
- ast = @parser.parse("""
- # comment
- class test {}
- """)
+ def parse_with(&block)
+ ParseWith.new(block)
+ end
+ end
+
+ include ParseMatcher
+
+ before :each do
+ @resource_type_collection = Puppet::Resource::TypeCollection.new("env")
+ @parser = Puppet::Parser::Parser.new "development"
+ end
- ast.hostclass("test").doc.should == "comment\n"
- end
+ describe "when parsing comments before statement" do
+ it "should associate the documentation to the statement AST node" do
+ ast = @parser.parse("""
+ # comment
+ class test {}
+ """)
+
+ ast.hostclass("test").doc.should == "comment\n"
end
+ end
- describe "when parsing" do
- it "should be able to parse normal left to right relationships" do
- "Notify[foo] -> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
- end
+ describe "when parsing" do
+ it "should be able to parse normal left to right relationships" do
+ "Notify[foo] -> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
- it "should be able to parse right to left relationships" do
- "Notify[foo] <- Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
- end
+ it "should be able to parse right to left relationships" do
+ "Notify[foo] <- Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
- it "should be able to parse normal left to right subscriptions" do
- "Notify[foo] ~> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
- end
+ it "should be able to parse normal left to right subscriptions" do
+ "Notify[foo] ~> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
- it "should be able to parse right to left subscriptions" do
- "Notify[foo] <~ Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
- end
+ it "should be able to parse right to left subscriptions" do
+ "Notify[foo] <~ Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
- it "should correctly set the arrow type of a relationship" do
- "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" }
- end
+ it "should correctly set the arrow type of a relationship" do
+ "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" }
end
+ end
end
diff --git a/spec/integration/provider/mailalias/aliases_spec.rb b/spec/integration/provider/mailalias/aliases_spec.rb
index fde0b001f..8106c2cb5 100755
--- a/spec/integration/provider/mailalias/aliases_spec.rb
+++ b/spec/integration/provider/mailalias/aliases_spec.rb
@@ -9,17 +9,17 @@ require 'puppettest/fileparsing'
provider_class = Puppet::Type.type(:mailalias).provider(:aliases)
describe provider_class do
- include PuppetTest
- include PuppetTest::FileParsing
+ include PuppetTest
+ include PuppetTest::FileParsing
- before :each do
- @provider = provider_class
- end
+ before :each do
+ @provider = provider_class
+ end
- # #1560
- PuppetTest.fakedata("data/providers/mailalias/aliases").each { |file|
- it "should be able to parse the examples in #{file}" do
- fakedataparse(file)
- end
- }
+ # #1560
+ PuppetTest.fakedata("data/providers/mailalias/aliases").each { |file|
+ it "should be able to parse the examples in #{file}" do
+ fakedataparse(file)
+ end
+ }
end
diff --git a/spec/integration/provider/package_spec.rb b/spec/integration/provider/package_spec.rb
index 6c854fb3e..736a34e68 100755
--- a/spec/integration/provider/package_spec.rb
+++ b/spec/integration/provider/package_spec.rb
@@ -3,24 +3,24 @@
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
describe "Package Provider" do
- Puppet::Type.type(:package).providers.each do |name|
- provider = Puppet::Type.type(:package).provider(name)
+ Puppet::Type.type(:package).providers.each do |name|
+ provider = Puppet::Type.type(:package).provider(name)
- describe name do
- confine "Provider #{name} is not suitable" => provider.suitable?
+ describe name do
+ confine "Provider #{name} is not suitable" => provider.suitable?
- it "should fail when asked to install an invalid package" do
- pending("This test hangs forever with recent versions of RubyGems") if provider.name == :gem
- pkg = Puppet::Type.newpackage :name => "nosuch#{provider.name}", :provider => provider.name
- lambda { pkg.provider.install }.should raise_error
- end
+ it "should fail when asked to install an invalid package" do
+ pending("This test hangs forever with recent versions of RubyGems") if provider.name == :gem
+ pkg = Puppet::Type.newpackage :name => "nosuch#{provider.name}", :provider => provider.name
+ lambda { pkg.provider.install }.should raise_error
+ end
- it "should be able to get a list of existing packages" do
- provider.instances.each do |package|
- package.should be_instance_of(provider)
- package.properties[:provider].should == provider.name
- end
- end
+ it "should be able to get a list of existing packages" do
+ provider.instances.each do |package|
+ package.should be_instance_of(provider)
+ package.properties[:provider].should == provider.name
end
+ end
end
+ end
end
diff --git a/spec/integration/provider/service/init_spec.rb b/spec/integration/provider/service/init_spec.rb
index e185247cb..d916ab32a 100755
--- a/spec/integration/provider/service/init_spec.rb
+++ b/spec/integration/provider/service/init_spec.rb
@@ -6,27 +6,27 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
provider = Puppet::Type.type(:service).provider(:init)
describe provider do
- describe "when running on FreeBSD" do
- confine "Not running on FreeBSD" => (Facter.value(:operatingsystem) == "FreeBSD")
+ describe "when running on FreeBSD" do
+ confine "Not running on FreeBSD" => (Facter.value(:operatingsystem) == "FreeBSD")
- it "should set its default path to include /etc/init.d and /usr/local/etc/init.d" do
- provider.defpath.should == ["/etc/rc.d", "/usr/local/etc/rc.d"]
- end
+ it "should set its default path to include /etc/init.d and /usr/local/etc/init.d" do
+ provider.defpath.should == ["/etc/rc.d", "/usr/local/etc/rc.d"]
end
+ end
- describe "when running on HP-UX" do
- confine "Not running on HP-UX" => (Facter.value(:operatingsystem) == "HP-UX")
+ describe "when running on HP-UX" do
+ confine "Not running on HP-UX" => (Facter.value(:operatingsystem) == "HP-UX")
- it "should set its default path to include /sbin/init.d" do
- provider.defpath.should == "/sbin/init.d"
- end
+ it "should set its default path to include /sbin/init.d" do
+ provider.defpath.should == "/sbin/init.d"
end
+ end
- describe "when not running on FreeBSD or HP-UX" do
- confine "Running on HP-UX or FreeBSD" => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem)))
+ describe "when not running on FreeBSD or HP-UX" do
+ confine "Running on HP-UX or FreeBSD" => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem)))
- it "should set its default path to include /etc/init.d" do
- provider.defpath.should == "/etc/init.d"
- end
+ it "should set its default path to include /etc/init.d" do
+ provider.defpath.should == "/etc/init.d"
end
+ end
end
diff --git a/spec/integration/reference/providers_spec.rb b/spec/integration/reference/providers_spec.rb
index 79b6ce12d..8b95ca118 100755
--- a/spec/integration/reference/providers_spec.rb
+++ b/spec/integration/reference/providers_spec.rb
@@ -7,11 +7,11 @@ require 'puppet/util/reference'
reference = Puppet::Util::Reference.reference(:providers)
describe reference do
- it "should exist" do
- reference.should_not be_nil
- end
+ it "should exist" do
+ reference.should_not be_nil
+ end
- it "should be able to be rendered as text" do
- lambda { reference.to_text }.should_not raise_error
- end
+ it "should be able to be rendered as text" do
+ lambda { reference.to_text }.should_not raise_error
+ end
end
diff --git a/spec/integration/reports_spec.rb b/spec/integration/reports_spec.rb
index cc4ae8f4c..40e5284e1 100755
--- a/spec/integration/reports_spec.rb
+++ b/spec/integration/reports_spec.rb
@@ -8,11 +8,11 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/reports'
describe Puppet::Reports, " when using report types" do
- before do
- Puppet.settings.stubs(:use)
- end
+ before do
+ Puppet.settings.stubs(:use)
+ end
- it "should load report types as modules" do
- Puppet::Reports.report(:store).should be_instance_of(Module)
- end
+ it "should load report types as modules" do
+ Puppet::Reports.report(:store).should be_instance_of(Module)
+ end
end
diff --git a/spec/integration/resource/catalog_spec.rb b/spec/integration/resource/catalog_spec.rb
index f4004451d..0a3d47a80 100755
--- a/spec/integration/resource/catalog_spec.rb
+++ b/spec/integration/resource/catalog_spec.rb
@@ -6,56 +6,56 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Resource::Catalog do
- describe "when pson is available" do
- confine "PSON library is missing" => Puppet.features.pson?
- it "should support pson" do
- Puppet::Resource::Catalog.supported_formats.should be_include(:pson)
- end
+ describe "when pson is available" do
+ confine "PSON library is missing" => Puppet.features.pson?
+ it "should support pson" do
+ Puppet::Resource::Catalog.supported_formats.should be_include(:pson)
+ end
+ end
+
+ describe "when using the indirector" do
+ after { Puppet::Util::Cacher.expire }
+ before do
+ # This is so the tests work w/out networking.
+ Facter.stubs(:to_hash).returns({"hostname" => "foo.domain.com"})
+ Facter.stubs(:value).returns("eh")
end
-
- describe "when using the indirector" do
- after { Puppet::Util::Cacher.expire }
- before do
- # This is so the tests work w/out networking.
- Facter.stubs(:to_hash).returns({"hostname" => "foo.domain.com"})
- Facter.stubs(:value).returns("eh")
- end
- it "should be able to delegate to the :yaml terminus" do
- Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :yaml
+ it "should be able to delegate to the :yaml terminus" do
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :yaml
- # Load now, before we stub the exists? method.
- terminus = Puppet::Resource::Catalog.indirection.terminus(:yaml)
- terminus.expects(:path).with("me").returns "/my/yaml/file"
+ # Load now, before we stub the exists? method.
+ terminus = Puppet::Resource::Catalog.indirection.terminus(:yaml)
+ terminus.expects(:path).with("me").returns "/my/yaml/file"
- FileTest.expects(:exist?).with("/my/yaml/file").returns false
- Puppet::Resource::Catalog.find("me").should be_nil
- end
+ FileTest.expects(:exist?).with("/my/yaml/file").returns false
+ Puppet::Resource::Catalog.find("me").should be_nil
+ end
- it "should be able to delegate to the :compiler terminus" do
- Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :compiler
+ it "should be able to delegate to the :compiler terminus" do
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :compiler
- # Load now, before we stub the exists? method.
- compiler = Puppet::Resource::Catalog.indirection.terminus(:compiler)
+ # Load now, before we stub the exists? method.
+ compiler = Puppet::Resource::Catalog.indirection.terminus(:compiler)
- node = mock 'node'
- node.stub_everything
+ node = mock 'node'
+ node.stub_everything
- Puppet::Node.expects(:find).returns(node)
- compiler.expects(:compile).with(node).returns nil
+ Puppet::Node.expects(:find).returns(node)
+ compiler.expects(:compile).with(node).returns nil
- Puppet::Resource::Catalog.find("me").should be_nil
- end
+ Puppet::Resource::Catalog.find("me").should be_nil
+ end
- it "should pass provided node information directly to the terminus" do
- terminus = mock 'terminus'
+ it "should pass provided node information directly to the terminus" do
+ terminus = mock 'terminus'
- Puppet::Resource::Catalog.indirection.stubs(:terminus).returns terminus
+ Puppet::Resource::Catalog.indirection.stubs(:terminus).returns terminus
- node = mock 'node'
- terminus.expects(:find).with { |request| request.options[:use_node] == node }
- Puppet::Resource::Catalog.find("me", :use_node => node)
- end
+ node = mock 'node'
+ terminus.expects(:find).with { |request| request.options[:use_node] == node }
+ Puppet::Resource::Catalog.find("me", :use_node => node)
end
+ end
end
diff --git a/spec/integration/resource/type_collection_spec.rb b/spec/integration/resource/type_collection_spec.rb
index da309c6c8..318dd4dd7 100755
--- a/spec/integration/resource/type_collection_spec.rb
+++ b/spec/integration/resource/type_collection_spec.rb
@@ -6,91 +6,91 @@ require 'puppet_spec/files'
require 'puppet/resource/type_collection'
describe Puppet::Resource::TypeCollection do
- describe "when autoloading from modules" do
- include PuppetSpec::Files
+ describe "when autoloading from modules" do
+ include PuppetSpec::Files
- before do
- @dir = tmpfile("autoload_testing")
- Puppet[:modulepath] = @dir
+ before do
+ @dir = tmpfile("autoload_testing")
+ Puppet[:modulepath] = @dir
- FileUtils.mkdir_p @dir
- @code = Puppet::Resource::TypeCollection.new("env")
- Puppet::Node::Environment.new("env").stubs(:known_resource_types).returns @code
- end
+ FileUtils.mkdir_p @dir
+ @code = Puppet::Resource::TypeCollection.new("env")
+ Puppet::Node::Environment.new("env").stubs(:known_resource_types).returns @code
+ end
- # Setup a module.
- def mk_module(name, files = {})
- mdir = File.join(@dir, name)
- mandir = File.join(mdir, "manifests")
- FileUtils.mkdir_p mandir
-
- defs = files.delete(:define)
-
- Dir.chdir(mandir) do
- files.each do |file, classes|
- File.open("#{file}.pp", "w") do |f|
- classes.each { |klass|
- if defs
- f.puts "define #{klass} {}"
- else
- f.puts "class #{klass} {}"
- end
- }
- end
- end
- end
+ # Setup a module.
+ def mk_module(name, files = {})
+ mdir = File.join(@dir, name)
+ mandir = File.join(mdir, "manifests")
+ FileUtils.mkdir_p mandir
+
+ defs = files.delete(:define)
+
+ Dir.chdir(mandir) do
+ files.each do |file, classes|
+ File.open("#{file}.pp", "w") do |f|
+ classes.each { |klass|
+ if defs
+ f.puts "define #{klass} {}"
+ else
+ f.puts "class #{klass} {}"
+ end
+ }
+ end
end
+ end
+ end
- it "should return nil when a class can't be found or loaded" do
- @code.find_hostclass('', 'nosuchclass').should be_nil
- end
+ it "should return nil when a class can't be found or loaded" do
+ @code.find_hostclass('', 'nosuchclass').should be_nil
+ end
- it "should load the module's init file first" do
- name = "simple"
- mk_module(name, :init => [name])
+ it "should load the module's init file first" do
+ name = "simple"
+ mk_module(name, :init => [name])
- @code.find_hostclass("", name).name.should == name
- end
+ @code.find_hostclass("", name).name.should == name
+ end
- it "should load the module's init file even when searching from a different namespace" do
- name = "simple"
- mk_module(name, :init => [name])
+ it "should load the module's init file even when searching from a different namespace" do
+ name = "simple"
+ mk_module(name, :init => [name])
- @code.find_hostclass("other::ns", name).name.should == name
- end
+ @code.find_hostclass("other::ns", name).name.should == name
+ end
- it "should be able to load definitions from the module base file" do
- name = "simpdef"
- mk_module(name, :define => true, :init => [name])
- @code.find_definition("", name).name.should == name
- end
+ it "should be able to load definitions from the module base file" do
+ name = "simpdef"
+ mk_module(name, :define => true, :init => [name])
+ @code.find_definition("", name).name.should == name
+ end
- it "should be able to load qualified classes from the module base file" do
- modname = "both"
- name = "sub"
- mk_module(modname, :init => %w{both both::sub})
+ it "should be able to load qualified classes from the module base file" do
+ modname = "both"
+ name = "sub"
+ mk_module(modname, :init => %w{both both::sub})
- @code.find_hostclass("both", name).name.should == "both::sub"
- end
+ @code.find_hostclass("both", name).name.should == "both::sub"
+ end
- it "should be able load classes from a separate file" do
- modname = "separate"
- name = "sub"
- mk_module(modname, :init => %w{separate}, :sub => %w{separate::sub})
- @code.find_hostclass("separate", name).name.should == "separate::sub"
- end
+ it "should be able load classes from a separate file" do
+ modname = "separate"
+ name = "sub"
+ mk_module(modname, :init => %w{separate}, :sub => %w{separate::sub})
+ @code.find_hostclass("separate", name).name.should == "separate::sub"
+ end
- it "should not fail when loading from a separate file if there is no module file" do
- modname = "alone"
- name = "sub"
- mk_module(modname, :sub => %w{alone::sub})
- lambda { @code.find_hostclass("alone", name) }.should_not raise_error
- end
+ it "should not fail when loading from a separate file if there is no module file" do
+ modname = "alone"
+ name = "sub"
+ mk_module(modname, :sub => %w{alone::sub})
+ lambda { @code.find_hostclass("alone", name) }.should_not raise_error
+ end
- it "should be able to load definitions from their own file" do
- name = "mymod"
- mk_module(name, :define => true, :mydefine => ["mymod::mydefine"])
- @code.find_definition("", "mymod::mydefine").name.should == "mymod::mydefine"
- end
+ it "should be able to load definitions from their own file" do
+ name = "mymod"
+ mk_module(name, :define => true, :mydefine => ["mymod::mydefine"])
+ @code.find_definition("", "mymod::mydefine").name.should == "mymod::mydefine"
end
+ end
end
diff --git a/spec/integration/ssl/certificate_authority_spec.rb b/spec/integration/ssl/certificate_authority_spec.rb
index 5fcbed89e..be82b5fb7 100755
--- a/spec/integration/ssl/certificate_authority_spec.rb
+++ b/spec/integration/ssl/certificate_authority_spec.rb
@@ -9,127 +9,127 @@ require 'puppet/ssl/certificate_authority'
require 'tempfile'
describe Puppet::SSL::CertificateAuthority do
- before do
- # Get a safe temporary file
- file = Tempfile.new("ca_integration_testing")
- @dir = file.path
- file.delete
+ before do
+ # Get a safe temporary file
+ file = Tempfile.new("ca_integration_testing")
+ @dir = file.path
+ file.delete
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
- Puppet::SSL::Host.ca_location = :local
- @ca = Puppet::SSL::CertificateAuthority.new
- end
+ Puppet::SSL::Host.ca_location = :local
+ @ca = Puppet::SSL::CertificateAuthority.new
+ end
- after {
- Puppet::SSL::Host.ca_location = :none
+ after {
+ Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
- Puppet.settings.clear
+ system("rm -rf #{@dir}")
+ Puppet.settings.clear
- Puppet::Util::Cacher.expire
+ Puppet::Util::Cacher.expire
- Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
- }
+ Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
+ }
- it "should create a CA host" do
- @ca.host.should be_ca
- end
+ it "should create a CA host" do
+ @ca.host.should be_ca
+ end
- it "should be able to generate a certificate" do
- @ca.generate_ca_certificate
+ it "should be able to generate a certificate" do
+ @ca.generate_ca_certificate
- @ca.host.certificate.should be_instance_of(Puppet::SSL::Certificate)
- end
+ @ca.host.certificate.should be_instance_of(Puppet::SSL::Certificate)
+ end
- it "should be able to generate a new host certificate" do
- @ca.generate("newhost")
+ it "should be able to generate a new host certificate" do
+ @ca.generate("newhost")
- Puppet::SSL::Certificate.find("newhost").should be_instance_of(Puppet::SSL::Certificate)
- end
+ Puppet::SSL::Certificate.find("newhost").should be_instance_of(Puppet::SSL::Certificate)
+ end
- it "should be able to revoke a host certificate" do
- @ca.generate("newhost")
+ it "should be able to revoke a host certificate" do
+ @ca.generate("newhost")
- @ca.revoke("newhost")
+ @ca.revoke("newhost")
- lambda { @ca.verify("newhost") }.should raise_error
- end
+ lambda { @ca.verify("newhost") }.should raise_error
+ end
- it "should have a CRL" do
- @ca.generate_ca_certificate
- @ca.crl.should_not be_nil
- end
+ it "should have a CRL" do
+ @ca.generate_ca_certificate
+ @ca.crl.should_not be_nil
+ end
- it "should be able to read in a previously created CRL" do
- @ca.generate_ca_certificate
+ it "should be able to read in a previously created CRL" do
+ @ca.generate_ca_certificate
- # Create it to start with.
- @ca.crl
+ # Create it to start with.
+ @ca.crl
- Puppet::SSL::CertificateAuthority.new.crl.should_not be_nil
- end
+ Puppet::SSL::CertificateAuthority.new.crl.should_not be_nil
+ end
- describe "when signing certificates" do
- before do
- @host = Puppet::SSL::Host.new("luke.madstop.com")
+ describe "when signing certificates" do
+ before do
+ @host = Puppet::SSL::Host.new("luke.madstop.com")
- # We have to provide the key, since when we're in :ca_only mode, we can only interact
- # with the CA key.
- key = Puppet::SSL::Key.new(@host.name)
- key.generate
+ # We have to provide the key, since when we're in :ca_only mode, we can only interact
+ # with the CA key.
+ key = Puppet::SSL::Key.new(@host.name)
+ key.generate
- @host.key = key
- @host.generate_certificate_request
+ @host.key = key
+ @host.generate_certificate_request
- path = File.join(Puppet[:requestdir], "luke.madstop.com.pem")
- end
+ path = File.join(Puppet[:requestdir], "luke.madstop.com.pem")
+ end
- it "should be able to sign certificates" do
- @ca.sign("luke.madstop.com")
- end
+ it "should be able to sign certificates" do
+ @ca.sign("luke.madstop.com")
+ end
- it "should save the signed certificate" do
- @ca.sign("luke.madstop.com")
+ it "should save the signed certificate" do
+ @ca.sign("luke.madstop.com")
- Puppet::SSL::Certificate.find("luke.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
- end
+ Puppet::SSL::Certificate.find("luke.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
+ end
- it "should be able to sign multiple certificates" do
- @other = Puppet::SSL::Host.new("other.madstop.com")
- okey = Puppet::SSL::Key.new(@other.name)
- okey.generate
- @other.key = okey
- @other.generate_certificate_request
+ it "should be able to sign multiple certificates" do
+ @other = Puppet::SSL::Host.new("other.madstop.com")
+ okey = Puppet::SSL::Key.new(@other.name)
+ okey.generate
+ @other.key = okey
+ @other.generate_certificate_request
- @ca.sign("luke.madstop.com")
- @ca.sign("other.madstop.com")
+ @ca.sign("luke.madstop.com")
+ @ca.sign("other.madstop.com")
- Puppet::SSL::Certificate.find("other.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
- Puppet::SSL::Certificate.find("luke.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
- end
+ Puppet::SSL::Certificate.find("other.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
+ Puppet::SSL::Certificate.find("luke.madstop.com").should be_instance_of(Puppet::SSL::Certificate)
+ end
- it "should save the signed certificate to the :signeddir" do
- @ca.sign("luke.madstop.com")
+ it "should save the signed certificate to the :signeddir" do
+ @ca.sign("luke.madstop.com")
- client_cert = File.join(Puppet[:signeddir], "luke.madstop.com.pem")
- File.read(client_cert).should == Puppet::SSL::Certificate.find("luke.madstop.com").content.to_s
- end
+ client_cert = File.join(Puppet[:signeddir], "luke.madstop.com.pem")
+ File.read(client_cert).should == Puppet::SSL::Certificate.find("luke.madstop.com").content.to_s
+ end
- it "should save valid certificates" do
- @ca.sign("luke.madstop.com")
+ it "should save valid certificates" do
+ @ca.sign("luke.madstop.com")
- ssl = %x{which openssl}
+ ssl = %x{which openssl}
- unless ssl
- pending "No ssl available"
- else
- ca_cert = Puppet[:cacert]
- client_cert = File.join(Puppet[:signeddir], "luke.madstop.com.pem")
- output = %x{openssl verify -CAfile #{ca_cert} #{client_cert}}
- $CHILD_STATUS.should == 0
- end
- end
+ unless ssl
+ pending "No ssl available"
+ else
+ ca_cert = Puppet[:cacert]
+ client_cert = File.join(Puppet[:signeddir], "luke.madstop.com.pem")
+ output = %x{openssl verify -CAfile #{ca_cert} #{client_cert}}
+ $CHILD_STATUS.should == 0
+ end
end
+ end
end
diff --git a/spec/integration/ssl/certificate_request_spec.rb b/spec/integration/ssl/certificate_request_spec.rb
index 5266ba606..365ecce38 100755
--- a/spec/integration/ssl/certificate_request_spec.rb
+++ b/spec/integration/ssl/certificate_request_spec.rb
@@ -9,53 +9,53 @@ require 'puppet/ssl/certificate_request'
require 'tempfile'
describe Puppet::SSL::CertificateRequest do
- before do
- # Get a safe temporary file
- file = Tempfile.new("csr_integration_testing")
- @dir = file.path
- file.delete
+ before do
+ # Get a safe temporary file
+ file = Tempfile.new("csr_integration_testing")
+ @dir = file.path
+ file.delete
- Dir.mkdir(@dir)
+ Dir.mkdir(@dir)
- Puppet.settings.clear
+ Puppet.settings.clear
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
- Puppet::SSL::Host.ca_location = :none
+ Puppet::SSL::Host.ca_location = :none
- @csr = Puppet::SSL::CertificateRequest.new("luke.madstop.com")
+ @csr = Puppet::SSL::CertificateRequest.new("luke.madstop.com")
- @key = OpenSSL::PKey::RSA.new(512)
- end
+ @key = OpenSSL::PKey::RSA.new(512)
+ end
- after do
- system("rm -rf #{@dir}")
- Puppet.settings.clear
+ after do
+ system("rm -rf #{@dir}")
+ Puppet.settings.clear
- # This is necessary so the terminus instances don't lie around.
- Puppet::Util::Cacher.expire
- end
+ # This is necessary so the terminus instances don't lie around.
+ Puppet::Util::Cacher.expire
+ end
- it "should be able to generate CSRs" do
- @csr.generate(@key)
- end
+ it "should be able to generate CSRs" do
+ @csr.generate(@key)
+ end
- it "should be able to save CSRs" do
- @csr.save
- end
+ it "should be able to save CSRs" do
+ @csr.save
+ end
- it "should be able to find saved certificate requests via the Indirector" do
- @csr.generate(@key)
- @csr.save
+ it "should be able to find saved certificate requests via the Indirector" do
+ @csr.generate(@key)
+ @csr.save
- Puppet::SSL::CertificateRequest.find("luke.madstop.com").should be_instance_of(Puppet::SSL::CertificateRequest)
- end
+ Puppet::SSL::CertificateRequest.find("luke.madstop.com").should be_instance_of(Puppet::SSL::CertificateRequest)
+ end
- it "should save the completely CSR when saving" do
- @csr.generate(@key)
- @csr.save
+ it "should save the completely CSR when saving" do
+ @csr.generate(@key)
+ @csr.save
- Puppet::SSL::CertificateRequest.find("luke.madstop.com").content.to_s.should == @csr.content.to_s
- end
+ Puppet::SSL::CertificateRequest.find("luke.madstop.com").content.to_s.should == @csr.content.to_s
+ end
end
diff --git a/spec/integration/ssl/certificate_revocation_list_spec.rb b/spec/integration/ssl/certificate_revocation_list_spec.rb
index 6328ae420..127654ce3 100755
--- a/spec/integration/ssl/certificate_revocation_list_spec.rb
+++ b/spec/integration/ssl/certificate_revocation_list_spec.rb
@@ -9,34 +9,34 @@ require 'puppet/ssl/certificate_revocation_list'
require 'tempfile'
describe Puppet::SSL::CertificateRevocationList do
- before do
- # Get a safe temporary file
- file = Tempfile.new("ca_integration_testing")
- @dir = file.path
- file.delete
+ before do
+ # Get a safe temporary file
+ file = Tempfile.new("ca_integration_testing")
+ @dir = file.path
+ file.delete
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
- Puppet::SSL::Host.ca_location = :local
- end
+ Puppet::SSL::Host.ca_location = :local
+ end
- after {
- Puppet::SSL::Host.ca_location = :none
+ after {
+ Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
- Puppet.settings.clear
+ system("rm -rf #{@dir}")
+ Puppet.settings.clear
- # This is necessary so the terminus instances don't lie around.
- Puppet::Util::Cacher.expire
- }
+ # This is necessary so the terminus instances don't lie around.
+ Puppet::Util::Cacher.expire
+ }
- it "should be able to read in written out CRLs with no revoked certificates" do
- ca = Puppet::SSL::CertificateAuthority.new
+ it "should be able to read in written out CRLs with no revoked certificates" do
+ ca = Puppet::SSL::CertificateAuthority.new
- raise "CRL not created" unless FileTest.exist?(Puppet[:hostcrl])
+ raise "CRL not created" unless FileTest.exist?(Puppet[:hostcrl])
- crl = Puppet::SSL::CertificateRevocationList.new("crl_int_testing")
- crl.read(Puppet[:hostcrl])
- end
+ crl = Puppet::SSL::CertificateRevocationList.new("crl_int_testing")
+ crl.read(Puppet[:hostcrl])
+ end
end
diff --git a/spec/integration/ssl/host_spec.rb b/spec/integration/ssl/host_spec.rb
index 5f2f1e5a4..9b4152e83 100755
--- a/spec/integration/ssl/host_spec.rb
+++ b/spec/integration/ssl/host_spec.rb
@@ -9,82 +9,82 @@ require 'puppet/ssl/host'
require 'tempfile'
describe Puppet::SSL::Host do
- before do
- # Get a safe temporary file
- file = Tempfile.new("host_integration_testing")
- @dir = file.path
- file.delete
+ before do
+ # Get a safe temporary file
+ file = Tempfile.new("host_integration_testing")
+ @dir = file.path
+ file.delete
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
- Puppet::SSL::Host.ca_location = :local
+ Puppet::SSL::Host.ca_location = :local
- @host = Puppet::SSL::Host.new("luke.madstop.com")
- @ca = Puppet::SSL::CertificateAuthority.new
- end
+ @host = Puppet::SSL::Host.new("luke.madstop.com")
+ @ca = Puppet::SSL::CertificateAuthority.new
+ end
- after {
- Puppet::SSL::Host.ca_location = :none
+ after {
+ Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
- Puppet.settings.clear
- Puppet::Util::Cacher.expire
- }
+ system("rm -rf #{@dir}")
+ Puppet.settings.clear
+ Puppet::Util::Cacher.expire
+ }
- it "should be considered a CA host if its name is equal to 'ca'" do
- Puppet::SSL::Host.new(Puppet::SSL::CA_NAME).should be_ca
- end
+ it "should be considered a CA host if its name is equal to 'ca'" do
+ Puppet::SSL::Host.new(Puppet::SSL::CA_NAME).should be_ca
+ end
- describe "when managing its key" do
- it "should be able to generate and save a key" do
- @host.generate_key
- end
+ describe "when managing its key" do
+ it "should be able to generate and save a key" do
+ @host.generate_key
+ end
- it "should save the key such that the Indirector can find it" do
- @host.generate_key
+ it "should save the key such that the Indirector can find it" do
+ @host.generate_key
- Puppet::SSL::Key.find(@host.name).content.to_s.should == @host.key.to_s
- end
+ Puppet::SSL::Key.find(@host.name).content.to_s.should == @host.key.to_s
+ end
- it "should save the private key into the :privatekeydir" do
- @host.generate_key
- File.read(File.join(Puppet.settings[:privatekeydir], "luke.madstop.com.pem")).should == @host.key.to_s
- end
+ it "should save the private key into the :privatekeydir" do
+ @host.generate_key
+ File.read(File.join(Puppet.settings[:privatekeydir], "luke.madstop.com.pem")).should == @host.key.to_s
end
+ end
- describe "when managing its certificate request" do
- it "should be able to generate and save a certificate request" do
- @host.generate_certificate_request
- end
+ describe "when managing its certificate request" do
+ it "should be able to generate and save a certificate request" do
+ @host.generate_certificate_request
+ end
- it "should save the certificate request such that the Indirector can find it" do
- @host.generate_certificate_request
+ it "should save the certificate request such that the Indirector can find it" do
+ @host.generate_certificate_request
- Puppet::SSL::CertificateRequest.find(@host.name).content.to_s.should == @host.certificate_request.to_s
- end
+ Puppet::SSL::CertificateRequest.find(@host.name).content.to_s.should == @host.certificate_request.to_s
+ end
- it "should save the private certificate request into the :privatekeydir" do
- @host.generate_certificate_request
- File.read(File.join(Puppet.settings[:requestdir], "luke.madstop.com.pem")).should == @host.certificate_request.to_s
- end
+ it "should save the private certificate request into the :privatekeydir" do
+ @host.generate_certificate_request
+ File.read(File.join(Puppet.settings[:requestdir], "luke.madstop.com.pem")).should == @host.certificate_request.to_s
end
+ end
- describe "when the CA host" do
- it "should never store its key in the :privatekeydir" do
- Puppet.settings.use(:main, :ssl, :ca)
- @ca = Puppet::SSL::Host.new(Puppet::SSL::Host.ca_name)
- @ca.generate_key
+ describe "when the CA host" do
+ it "should never store its key in the :privatekeydir" do
+ Puppet.settings.use(:main, :ssl, :ca)
+ @ca = Puppet::SSL::Host.new(Puppet::SSL::Host.ca_name)
+ @ca.generate_key
- FileTest.should_not be_exist(File.join(Puppet[:privatekeydir], "ca.pem"))
- end
+ FileTest.should_not be_exist(File.join(Puppet[:privatekeydir], "ca.pem"))
end
+ end
- it "should pass the verification of its own SSL store" do
- @host.generate
- @ca = Puppet::SSL::CertificateAuthority.new
- @ca.sign(@host.name)
+ it "should pass the verification of its own SSL store" do
+ @host.generate
+ @ca = Puppet::SSL::CertificateAuthority.new
+ @ca.sign(@host.name)
- @host.ssl_store.verify(@host.certificate.content).should be_true
- end
+ @host.ssl_store.verify(@host.certificate.content).should be_true
+ end
end
diff --git a/spec/integration/transaction/report_spec.rb b/spec/integration/transaction/report_spec.rb
index b704e56b8..eed7acaa9 100755
--- a/spec/integration/transaction/report_spec.rb
+++ b/spec/integration/transaction/report_spec.rb
@@ -6,24 +6,24 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Transaction::Report do
- describe "when using the indirector" do
- after do
- Puppet::Util::Cacher.expire
- Puppet.settings.stubs(:use)
- end
+ describe "when using the indirector" do
+ after do
+ Puppet::Util::Cacher.expire
+ Puppet.settings.stubs(:use)
+ end
- it "should be able to delegate to the :processor terminus" do
- Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor
+ it "should be able to delegate to the :processor terminus" do
+ Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor
- terminus = Puppet::Transaction::Report.indirection.terminus(:processor)
+ terminus = Puppet::Transaction::Report.indirection.terminus(:processor)
- Facter.stubs(:value).returns "host.domain.com"
+ Facter.stubs(:value).returns "host.domain.com"
- report = Puppet::Transaction::Report.new
+ report = Puppet::Transaction::Report.new
- terminus.expects(:process).with(report)
+ terminus.expects(:process).with(report)
- report.save
- end
+ report.save
end
+ end
end
diff --git a/spec/integration/transaction_spec.rb b/spec/integration/transaction_spec.rb
index 1b8d7ecfd..d5478d7a7 100755
--- a/spec/integration/transaction_spec.rb
+++ b/spec/integration/transaction_spec.rb
@@ -7,278 +7,278 @@ require 'puppet/transaction'
require 'puppet_spec/files'
describe Puppet::Transaction do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- before do
- Puppet::Util::Storage.stubs(:store)
- end
+ before do
+ Puppet::Util::Storage.stubs(:store)
+ end
- def mk_catalog(*resources)
- catalog = Puppet::Resource::Catalog.new(Puppet::Node.new("mynode"))
- resources.each { |res| catalog.add_resource res }
- catalog
- end
+ def mk_catalog(*resources)
+ catalog = Puppet::Resource::Catalog.new(Puppet::Node.new("mynode"))
+ resources.each { |res| catalog.add_resource res }
+ catalog
+ end
- it "should not apply generated resources if the parent resource fails" do
- catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
- catalog.add_resource resource
+ it "should not apply generated resources if the parent resource fails" do
+ catalog = Puppet::Resource::Catalog.new
+ resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ catalog.add_resource resource
- child_resource = Puppet::Type.type(:file).new :path => "/foo/bar/baz", :backup => false
+ child_resource = Puppet::Type.type(:file).new :path => "/foo/bar/baz", :backup => false
- resource.expects(:eval_generate).returns([child_resource])
+ resource.expects(:eval_generate).returns([child_resource])
- transaction = Puppet::Transaction.new(catalog)
+ transaction = Puppet::Transaction.new(catalog)
- resource.expects(:retrieve).raises "this is a failure"
- resource.stubs(:err)
+ resource.expects(:retrieve).raises "this is a failure"
+ resource.stubs(:err)
- child_resource.expects(:retrieve).never
+ child_resource.expects(:retrieve).never
- transaction.evaluate
- end
+ transaction.evaluate
+ end
- it "should not apply virtual resources" do
- catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
- resource.virtual = true
- catalog.add_resource resource
+ it "should not apply virtual resources" do
+ catalog = Puppet::Resource::Catalog.new
+ resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource.virtual = true
+ catalog.add_resource resource
- transaction = Puppet::Transaction.new(catalog)
+ transaction = Puppet::Transaction.new(catalog)
- resource.expects(:evaluate).never
+ resource.expects(:evaluate).never
- transaction.evaluate
- end
+ transaction.evaluate
+ end
- it "should apply exported resources" do
- catalog = Puppet::Resource::Catalog.new
- path = tmpfile("exported_files")
- resource = Puppet::Type.type(:file).new :path => path, :backup => false, :ensure => :file
- resource.exported = true
- catalog.add_resource resource
+ it "should apply exported resources" do
+ catalog = Puppet::Resource::Catalog.new
+ path = tmpfile("exported_files")
+ resource = Puppet::Type.type(:file).new :path => path, :backup => false, :ensure => :file
+ resource.exported = true
+ catalog.add_resource resource
- catalog.apply
- FileTest.should be_exist(path)
- end
+ catalog.apply
+ FileTest.should be_exist(path)
+ end
- it "should not apply virtual exported resources" do
- catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
- resource.exported = true
- resource.virtual = true
- catalog.add_resource resource
+ it "should not apply virtual exported resources" do
+ catalog = Puppet::Resource::Catalog.new
+ resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource.exported = true
+ resource.virtual = true
+ catalog.add_resource resource
- transaction = Puppet::Transaction.new(catalog)
+ transaction = Puppet::Transaction.new(catalog)
- resource.expects(:evaluate).never
+ resource.expects(:evaluate).never
- transaction.evaluate
- end
+ transaction.evaluate
+ end
- # Verify that one component requiring another causes the contained
- # resources in the requiring component to get refreshed.
- it "should propagate events from a contained resource through its container to its dependent container's contained resources" do
- transaction = nil
- file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present
- execfile = File.join(tmpdir("exec_event"), "exectestingness2")
- exec = Puppet::Type.type(:exec).new :command => "touch #{execfile}", :path => ENV['PATH']
- catalog = mk_catalog(file)
+ # Verify that one component requiring another causes the contained
+ # resources in the requiring component to get refreshed.
+ it "should propagate events from a contained resource through its container to its dependent container's contained resources" do
+ transaction = nil
+ file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present
+ execfile = File.join(tmpdir("exec_event"), "exectestingness2")
+ exec = Puppet::Type.type(:exec).new :command => "touch #{execfile}", :path => ENV['PATH']
+ catalog = mk_catalog(file)
- fcomp = Puppet::Type.type(:component).new(:name => "Foo[file]")
- catalog.add_resource fcomp
- catalog.add_edge(fcomp, file)
+ fcomp = Puppet::Type.type(:component).new(:name => "Foo[file]")
+ catalog.add_resource fcomp
+ catalog.add_edge(fcomp, file)
- ecomp = Puppet::Type.type(:component).new(:name => "Foo[exec]")
- catalog.add_resource ecomp
- catalog.add_resource exec
- catalog.add_edge(ecomp, exec)
+ ecomp = Puppet::Type.type(:component).new(:name => "Foo[exec]")
+ catalog.add_resource ecomp
+ catalog.add_resource exec
+ catalog.add_edge(ecomp, exec)
- ecomp[:subscribe] = Puppet::Resource.new(:foo, "file")
- exec[:refreshonly] = true
+ ecomp[:subscribe] = Puppet::Resource.new(:foo, "file")
+ exec[:refreshonly] = true
- exec.expects(:refresh)
- catalog.apply
- end
+ exec.expects(:refresh)
+ catalog.apply
+ end
- # Make sure that multiple subscriptions get triggered.
- it "should propagate events to all dependent resources" do
- path = tmpfile("path")
- file1 = tmpfile("file1")
- file2 = tmpfile("file2")
+ # Make sure that multiple subscriptions get triggered.
+ it "should propagate events to all dependent resources" do
+ path = tmpfile("path")
+ file1 = tmpfile("file1")
+ file2 = tmpfile("file2")
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :path => path,
+ :path => path,
- :ensure => "file"
- )
+ :ensure => "file"
+ )
- exec1 = Puppet::Type.type(:exec).new(
+ exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch #{file1}",
- :refreshonly => true,
+ :path => ENV["PATH"],
+ :command => "touch #{file1}",
+ :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
+ :subscribe => Puppet::Resource.new(:file, path)
+ )
- exec2 = Puppet::Type.type(:exec).new(
+ exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch #{file2}",
- :refreshonly => true,
+ :path => ENV["PATH"],
+ :command => "touch #{file2}",
+ :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
+ :subscribe => Puppet::Resource.new(:file, path)
+ )
- catalog = mk_catalog(file, exec1, exec2)
- catalog.apply
- FileTest.should be_exist(file1)
- FileTest.should be_exist(file2)
- end
+ catalog = mk_catalog(file, exec1, exec2)
+ catalog.apply
+ FileTest.should be_exist(file1)
+ FileTest.should be_exist(file2)
+ end
- it "should not let one failed refresh result in other refreshes failing" do
- path = tmpfile("path")
- newfile = tmpfile("file")
+ it "should not let one failed refresh result in other refreshes failing" do
+ path = tmpfile("path")
+ newfile = tmpfile("file")
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :path => path,
+ :path => path,
- :ensure => "file"
- )
+ :ensure => "file"
+ )
- exec1 = Puppet::Type.type(:exec).new(
+ exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch /this/cannot/possibly/exist",
- :logoutput => true,
- :refreshonly => true,
- :subscribe => file,
+ :path => ENV["PATH"],
+ :command => "touch /this/cannot/possibly/exist",
+ :logoutput => true,
+ :refreshonly => true,
+ :subscribe => file,
- :title => "one"
- )
+ :title => "one"
+ )
- exec2 = Puppet::Type.type(:exec).new(
+ exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch #{newfile}",
- :logoutput => true,
- :refreshonly => true,
- :subscribe => [file, exec1],
+ :path => ENV["PATH"],
+ :command => "touch #{newfile}",
+ :logoutput => true,
+ :refreshonly => true,
+ :subscribe => [file, exec1],
- :title => "two"
- )
+ :title => "two"
+ )
- exec1.stubs(:err)
+ exec1.stubs(:err)
- catalog = mk_catalog(file, exec1, exec2)
- catalog.apply
- FileTest.should be_exists(newfile)
- end
+ catalog = mk_catalog(file, exec1, exec2)
+ catalog.apply
+ FileTest.should be_exists(newfile)
+ end
- it "should still trigger skipped resources" do
- catalog = mk_catalog
- catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules)
+ it "should still trigger skipped resources" do
+ catalog = mk_catalog
+ catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules)
- Puppet[:ignoreschedules] = false
+ Puppet[:ignoreschedules] = false
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :name => tmpfile("file"),
+ :name => tmpfile("file"),
- :ensure => "file",
- :backup => false
- )
+ :ensure => "file",
+ :backup => false
+ )
- fname = tmpfile("exec")
+ fname = tmpfile("exec")
- exec = Puppet::Type.type(:exec).new(
+ exec = Puppet::Type.type(:exec).new(
- :name => "touch #{fname}",
- :path => "/usr/bin:/bin",
- :schedule => "monthly",
+ :name => "touch #{fname}",
+ :path => "/usr/bin:/bin",
+ :schedule => "monthly",
- :subscribe => Puppet::Resource.new("file", file.name)
- )
+ :subscribe => Puppet::Resource.new("file", file.name)
+ )
- catalog.add_resource(file, exec)
+ catalog.add_resource(file, exec)
- # Run it once
- catalog.apply
- FileTest.should be_exists(fname)
+ # Run it once
+ catalog.apply
+ FileTest.should be_exists(fname)
- # Now remove it, so it can get created again
- File.unlink(fname)
+ # Now remove it, so it can get created again
+ File.unlink(fname)
- file[:content] = "some content"
+ file[:content] = "some content"
- catalog.apply
- FileTest.should be_exists(fname)
+ catalog.apply
+ FileTest.should be_exists(fname)
- # Now remove it, so it can get created again
- File.unlink(fname)
+ # Now remove it, so it can get created again
+ File.unlink(fname)
- # And tag our exec
- exec.tag("testrun")
+ # And tag our exec
+ exec.tag("testrun")
- # And our file, so it runs
- file.tag("norun")
+ # And our file, so it runs
+ file.tag("norun")
- Puppet[:tags] = "norun"
+ Puppet[:tags] = "norun"
- file[:content] = "totally different content"
+ file[:content] = "totally different content"
- catalog.apply
- FileTest.should be_exists(fname)
- end
+ catalog.apply
+ FileTest.should be_exists(fname)
+ end
- it "should not attempt to evaluate resources with failed dependencies" do
+ it "should not attempt to evaluate resources with failed dependencies" do
- exec = Puppet::Type.type(:exec).new(
+ exec = Puppet::Type.type(:exec).new(
- :command => "/bin/mkdir /this/path/cannot/possibly/exit",
+ :command => "/bin/mkdir /this/path/cannot/possibly/exit",
- :title => "mkdir"
- )
+ :title => "mkdir"
+ )
- file1 = Puppet::Type.type(:file).new(
+ file1 = Puppet::Type.type(:file).new(
- :title => "file1",
- :path => tmpfile("file1"),
+ :title => "file1",
+ :path => tmpfile("file1"),
- :require => exec,
- :ensure => :file
- )
+ :require => exec,
+ :ensure => :file
+ )
- file2 = Puppet::Type.type(:file).new(
+ file2 = Puppet::Type.type(:file).new(
- :title => "file2",
- :path => tmpfile("file2"),
+ :title => "file2",
+ :path => tmpfile("file2"),
- :require => file1,
- :ensure => :file
- )
+ :require => file1,
+ :ensure => :file
+ )
- catalog = mk_catalog(exec, file1, file2)
- catalog.apply
+ catalog = mk_catalog(exec, file1, file2)
+ catalog.apply
- FileTest.should_not be_exists(file1[:path])
- FileTest.should_not be_exists(file2[:path])
- end
+ FileTest.should_not be_exists(file1[:path])
+ FileTest.should_not be_exists(file2[:path])
+ end
- # #801 -- resources only checked in noop should be rescheduled immediately.
- it "should immediately reschedule noop resources" do
- Puppet::Type.type(:schedule).mkdefaultschedules
- resource = Puppet::Type.type(:notify).new(:name => "mymessage", :noop => true)
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource resource
+ # #801 -- resources only checked in noop should be rescheduled immediately.
+ it "should immediately reschedule noop resources" do
+ Puppet::Type.type(:schedule).mkdefaultschedules
+ resource = Puppet::Type.type(:notify).new(:name => "mymessage", :noop => true)
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource resource
- trans = catalog.apply
+ trans = catalog.apply
- trans.resource_harness.should be_scheduled(trans.resource_status(resource), resource)
- end
+ trans.resource_harness.should be_scheduled(trans.resource_status(resource), resource)
+ end
end
diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb
index 8ecf42b6f..4b91e5ef9 100755
--- a/spec/integration/type/file_spec.rb
+++ b/spec/integration/type/file_spec.rb
@@ -5,502 +5,502 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet_spec/files'
describe Puppet::Type.type(:file) do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- before do
- # stub this to not try to create state.yaml
- Puppet::Util::Storage.stubs(:store)
- end
+ before do
+ # stub this to not try to create state.yaml
+ Puppet::Util::Storage.stubs(:store)
+ end
- it "should not attempt to manage files that do not exist if no means of creating the file is specified" do
- file = Puppet::Type.type(:file).new :path => "/my/file", :mode => "755"
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ it "should not attempt to manage files that do not exist if no means of creating the file is specified" do
+ file = Puppet::Type.type(:file).new :path => "/my/file", :mode => "755"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- file.parameter(:mode).expects(:retrieve).never
+ file.parameter(:mode).expects(:retrieve).never
- transaction = Puppet::Transaction.new(catalog)
- transaction.resource_harness.evaluate(file).should_not be_failed
- end
+ transaction = Puppet::Transaction.new(catalog)
+ transaction.resource_harness.evaluate(file).should_not be_failed
+ end
- describe "when writing files" do
- it "should backup files to a filebucket when one is configured" do
- bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo"
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file, bucket
+ describe "when writing files" do
+ it "should backup files to a filebucket when one is configured" do
+ bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
+ file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file, bucket
- File.open(file[:path], "w") { |f| f.puts "bar" }
+ File.open(file[:path], "w") { |f| f.puts "bar" }
- md5 = Digest::MD5.hexdigest(File.read(file[:path]))
+ md5 = Digest::MD5.hexdigest(File.read(file[:path]))
- catalog.apply
+ catalog.apply
- bucket.bucket.getfile(md5).should == "bar\n"
- end
+ bucket.bucket.getfile(md5).should == "bar\n"
+ end
- it "should backup files in the local directory when a backup string is provided" do
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo"
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ it "should backup files in the local directory when a backup string is provided" do
+ file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- File.open(file[:path], "w") { |f| f.puts "bar" }
+ File.open(file[:path], "w") { |f| f.puts "bar" }
- catalog.apply
+ catalog.apply
- backup = file[:path] + ".bak"
- FileTest.should be_exist(backup)
- File.read(backup).should == "bar\n"
- end
+ backup = file[:path] + ".bak"
+ FileTest.should be_exist(backup)
+ File.read(backup).should == "bar\n"
+ end
- it "should fail if no backup can be performed" do
- dir = tmpfile("backups")
- Dir.mkdir(dir)
- path = File.join(dir, "testfile")
- file = Puppet::Type.type(:file).new :path => path, :backup => ".bak", :content => "foo"
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ it "should fail if no backup can be performed" do
+ dir = tmpfile("backups")
+ Dir.mkdir(dir)
+ path = File.join(dir, "testfile")
+ file = Puppet::Type.type(:file).new :path => path, :backup => ".bak", :content => "foo"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- File.open(file[:path], "w") { |f| f.puts "bar" }
+ File.open(file[:path], "w") { |f| f.puts "bar" }
- # Create a directory where the backup should be so that writing to it fails
- Dir.mkdir(File.join(dir, "testfile.bak"))
+ # Create a directory where the backup should be so that writing to it fails
+ Dir.mkdir(File.join(dir, "testfile.bak"))
- Puppet::Util::Log.stubs(:newmessage)
+ Puppet::Util::Log.stubs(:newmessage)
- catalog.apply
+ catalog.apply
- File.read(file[:path]).should == "bar\n"
- end
+ File.read(file[:path]).should == "bar\n"
+ end
- it "should not backup symlinks" do
- link = tmpfile("link")
- dest1 = tmpfile("dest1")
- dest2 = tmpfile("dest2")
- bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
- file = Puppet::Type.type(:file).new :path => link, :target => dest2, :ensure => :link, :backup => "mybucket"
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file, bucket
+ it "should not backup symlinks" do
+ link = tmpfile("link")
+ dest1 = tmpfile("dest1")
+ dest2 = tmpfile("dest2")
+ bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
+ file = Puppet::Type.type(:file).new :path => link, :target => dest2, :ensure => :link, :backup => "mybucket"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file, bucket
- File.open(dest1, "w") { |f| f.puts "whatever" }
- File.symlink(dest1, link)
+ File.open(dest1, "w") { |f| f.puts "whatever" }
+ File.symlink(dest1, link)
- md5 = Digest::MD5.hexdigest(File.read(file[:path]))
+ md5 = Digest::MD5.hexdigest(File.read(file[:path]))
- catalog.apply
+ catalog.apply
- File.readlink(link).should == dest2
- Find.find(bucket[:path]) { |f| File.file?(f) }.should be_nil
- end
+ File.readlink(link).should == dest2
+ Find.find(bucket[:path]) { |f| File.file?(f) }.should be_nil
+ end
- it "should backup directories to the local filesystem by copying the whole directory" do
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo", :force => true
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ it "should backup directories to the local filesystem by copying the whole directory" do
+ file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo", :force => true
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- Dir.mkdir(file[:path])
- otherfile = File.join(file[:path], "foo")
- File.open(otherfile, "w") { |f| f.print "yay" }
+ Dir.mkdir(file[:path])
+ otherfile = File.join(file[:path], "foo")
+ File.open(otherfile, "w") { |f| f.print "yay" }
- catalog.apply
+ catalog.apply
- backup = file[:path] + ".bak"
- FileTest.should be_directory(backup)
- File.read(File.join(backup, "foo")).should == "yay"
- end
+ backup = file[:path] + ".bak"
+ FileTest.should be_directory(backup)
+ File.read(File.join(backup, "foo")).should == "yay"
+ end
- it "should backup directories to filebuckets by backing up each file separately" do
- bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file, bucket
+ it "should backup directories to filebuckets by backing up each file separately" do
+ bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
+ file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file, bucket
- Dir.mkdir(file[:path])
- foofile = File.join(file[:path], "foo")
- barfile = File.join(file[:path], "bar")
- File.open(foofile, "w") { |f| f.print "fooyay" }
- File.open(barfile, "w") { |f| f.print "baryay" }
+ Dir.mkdir(file[:path])
+ foofile = File.join(file[:path], "foo")
+ barfile = File.join(file[:path], "bar")
+ File.open(foofile, "w") { |f| f.print "fooyay" }
+ File.open(barfile, "w") { |f| f.print "baryay" }
- foomd5 = Digest::MD5.hexdigest(File.read(foofile))
- barmd5 = Digest::MD5.hexdigest(File.read(barfile))
+ foomd5 = Digest::MD5.hexdigest(File.read(foofile))
+ barmd5 = Digest::MD5.hexdigest(File.read(barfile))
- catalog.apply
+ catalog.apply
- bucket.bucket.getfile(foomd5).should == "fooyay"
- bucket.bucket.getfile(barmd5).should == "baryay"
- end
+ bucket.bucket.getfile(foomd5).should == "fooyay"
+ bucket.bucket.getfile(barmd5).should == "baryay"
+ end
- it "should propagate failures encountered when renaming the temporary file" do
- file = Puppet::Type.type(:file).new :path => tmpfile("fail_rename"), :content => "foo"
- file.stubs(:remove_existing) # because it tries to make a backup
+ it "should propagate failures encountered when renaming the temporary file" do
+ file = Puppet::Type.type(:file).new :path => tmpfile("fail_rename"), :content => "foo"
+ file.stubs(:remove_existing) # because it tries to make a backup
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- File.open(file[:path], "w") { |f| f.print "bar" }
+ File.open(file[:path], "w") { |f| f.print "bar" }
- File.expects(:rename).raises ArgumentError
+ File.expects(:rename).raises ArgumentError
- lambda { file.write(:content) }.should raise_error(Puppet::Error)
- File.read(file[:path]).should == "bar"
- end
+ lambda { file.write(:content) }.should raise_error(Puppet::Error)
+ File.read(file[:path]).should == "bar"
end
-
- describe "when recursing" do
- def build_path(dir)
- Dir.mkdir(dir)
- File.chmod(0750, dir)
-
- @dirs = [dir]
- @files = []
-
- %w{one two}.each do |subdir|
- fdir = File.join(dir, subdir)
- Dir.mkdir(fdir)
- File.chmod(0750, fdir)
- @dirs << fdir
-
- %w{three}.each do |file|
- ffile = File.join(fdir, file)
- @files << ffile
- File.open(ffile, "w") { |f| f.puts "test #{file}" }
- File.chmod(0640, ffile)
- end
- end
+ end
+
+ describe "when recursing" do
+ def build_path(dir)
+ Dir.mkdir(dir)
+ File.chmod(0750, dir)
+
+ @dirs = [dir]
+ @files = []
+
+ %w{one two}.each do |subdir|
+ fdir = File.join(dir, subdir)
+ Dir.mkdir(fdir)
+ File.chmod(0750, fdir)
+ @dirs << fdir
+
+ %w{three}.each do |file|
+ ffile = File.join(fdir, file)
+ @files << ffile
+ File.open(ffile, "w") { |f| f.puts "test #{file}" }
+ File.chmod(0640, ffile)
end
+ end
+ end
- it "should be able to recurse over a nonexistent file" do
- @path = tmpfile("file_integration_tests")
+ it "should be able to recurse over a nonexistent file" do
+ @path = tmpfile("file_integration_tests")
- @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @file
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @file
- lambda { @file.eval_generate }.should_not raise_error
- end
+ lambda { @file.eval_generate }.should_not raise_error
+ end
- it "should be able to recursively set properties on existing files" do
- @path = tmpfile("file_integration_tests")
+ it "should be able to recursively set properties on existing files" do
+ @path = tmpfile("file_integration_tests")
- build_path(@path)
+ build_path(@path)
- @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @file
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @file
- @catalog.apply
+ @catalog.apply
- @dirs.each do |path|
- (File.stat(path).mode & 007777).should == 0755
- end
+ @dirs.each do |path|
+ (File.stat(path).mode & 007777).should == 0755
+ end
- @files.each do |path|
- (File.stat(path).mode & 007777).should == 0644
- end
- end
+ @files.each do |path|
+ (File.stat(path).mode & 007777).should == 0644
+ end
+ end
- it "should be able to recursively make links to other files" do
- source = tmpfile("file_link_integration_source")
+ it "should be able to recursively make links to other files" do
+ source = tmpfile("file_link_integration_source")
- build_path(source)
+ build_path(source)
- dest = tmpfile("file_link_integration_dest")
+ dest = tmpfile("file_link_integration_dest")
- @file = Puppet::Type::File.new(:name => dest, :target => source, :recurse => true, :ensure => :link, :backup => false)
+ @file = Puppet::Type::File.new(:name => dest, :target => source, :recurse => true, :ensure => :link, :backup => false)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @file
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @file
- @catalog.apply
+ @catalog.apply
- @dirs.each do |path|
- link_path = path.sub(source, dest)
+ @dirs.each do |path|
+ link_path = path.sub(source, dest)
- File.lstat(link_path).should be_directory
- end
+ File.lstat(link_path).should be_directory
+ end
- @files.each do |path|
- link_path = path.sub(source, dest)
+ @files.each do |path|
+ link_path = path.sub(source, dest)
- File.lstat(link_path).ftype.should == "link"
- end
- end
+ File.lstat(link_path).ftype.should == "link"
+ end
+ end
- it "should be able to recursively copy files" do
- source = tmpfile("file_source_integration_source")
+ it "should be able to recursively copy files" do
+ source = tmpfile("file_source_integration_source")
- build_path(source)
+ build_path(source)
- dest = tmpfile("file_source_integration_dest")
+ dest = tmpfile("file_source_integration_dest")
- @file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true, :backup => false)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @file
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @file
- @catalog.apply
+ @catalog.apply
- @dirs.each do |path|
- newpath = path.sub(source, dest)
+ @dirs.each do |path|
+ newpath = path.sub(source, dest)
- File.lstat(newpath).should be_directory
- end
+ File.lstat(newpath).should be_directory
+ end
- @files.each do |path|
- newpath = path.sub(source, dest)
+ @files.each do |path|
+ newpath = path.sub(source, dest)
- File.lstat(newpath).ftype.should == "file"
- end
- end
+ File.lstat(newpath).ftype.should == "file"
+ end
+ end
- it "should not recursively manage files managed by a more specific explicit file" do
- dir = tmpfile("recursion_vs_explicit_1")
+ it "should not recursively manage files managed by a more specific explicit file" do
+ dir = tmpfile("recursion_vs_explicit_1")
- subdir = File.join(dir, "subdir")
- file = File.join(subdir, "file")
+ subdir = File.join(dir, "subdir")
+ file = File.join(subdir, "file")
- FileUtils.mkdir_p(subdir)
- File.open(file, "w") { |f| f.puts "" }
+ FileUtils.mkdir_p(subdir)
+ File.open(file, "w") { |f| f.puts "" }
- base = Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
- sub = Puppet::Type::File.new(:name => subdir, :recurse => true, :backup => false, :mode => "644")
+ base = Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
+ sub = Puppet::Type::File.new(:name => subdir, :recurse => true, :backup => false, :mode => "644")
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource base
- @catalog.add_resource sub
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource base
+ @catalog.add_resource sub
- @catalog.apply
+ @catalog.apply
- (File.stat(file).mode & 007777).should == 0644
- end
+ (File.stat(file).mode & 007777).should == 0644
+ end
- it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file" do
- dir = tmpfile("recursion_vs_explicit_2")
+ it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file" do
+ dir = tmpfile("recursion_vs_explicit_2")
- managed = File.join(dir, "file")
- generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
+ managed = File.join(dir, "file")
+ generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
- FileUtils.mkdir_p(dir)
- File.open(managed, "w") { |f| f.puts "" }
- File.open(generated, "w") { |f| f.puts "" }
+ FileUtils.mkdir_p(dir)
+ File.open(managed, "w") { |f| f.puts "" }
+ File.open(generated, "w") { |f| f.puts "" }
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
- @catalog.add_resource Puppet::Type::File.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
+ @catalog.add_resource Puppet::Type::File.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
- @catalog.apply
+ @catalog.apply
- (File.stat(generated).mode & 007777).should == 0755
- end
+ (File.stat(generated).mode & 007777).should == 0755
end
+ end
- describe "when generating resources" do
- before do
- @source = tmpfile("generating_in_catalog_source")
+ describe "when generating resources" do
+ before do
+ @source = tmpfile("generating_in_catalog_source")
- @dest = tmpfile("generating_in_catalog_dest")
+ @dest = tmpfile("generating_in_catalog_dest")
- Dir.mkdir(@source)
+ Dir.mkdir(@source)
- s1 = File.join(@source, "one")
- s2 = File.join(@source, "two")
+ s1 = File.join(@source, "one")
+ s2 = File.join(@source, "two")
- File.open(s1, "w") { |f| f.puts "uno" }
- File.open(s2, "w") { |f| f.puts "dos" }
+ File.open(s1, "w") { |f| f.puts "uno" }
+ File.open(s2, "w") { |f| f.puts "dos" }
- @file = Puppet::Type::File.new(:name => @dest, :source => @source, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(:name => @dest, :source => @source, :recurse => true, :backup => false)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @file
- end
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @file
+ end
- it "should add each generated resource to the catalog" do
- @catalog.apply do |trans|
- @catalog.resource(:file, File.join(@dest, "one")).should be_instance_of(@file.class)
- @catalog.resource(:file, File.join(@dest, "two")).should be_instance_of(@file.class)
- end
- end
+ it "should add each generated resource to the catalog" do
+ @catalog.apply do |trans|
+ @catalog.resource(:file, File.join(@dest, "one")).should be_instance_of(@file.class)
+ @catalog.resource(:file, File.join(@dest, "two")).should be_instance_of(@file.class)
+ end
+ end
- it "should have an edge to each resource in the relationship graph" do
- @catalog.apply do |trans|
- one = @catalog.resource(:file, File.join(@dest, "one"))
- @catalog.relationship_graph.should be_edge(@file, one)
+ it "should have an edge to each resource in the relationship graph" do
+ @catalog.apply do |trans|
+ one = @catalog.resource(:file, File.join(@dest, "one"))
+ @catalog.relationship_graph.should be_edge(@file, one)
- two = @catalog.resource(:file, File.join(@dest, "two"))
- @catalog.relationship_graph.should be_edge(@file, two)
- end
- end
+ two = @catalog.resource(:file, File.join(@dest, "two"))
+ @catalog.relationship_graph.should be_edge(@file, two)
+ end
end
+ end
- describe "when copying files" do
- # Ticket #285.
- it "should be able to copy files with pound signs in their names" do
- source = tmpfile("filewith#signs")
+ describe "when copying files" do
+ # Ticket #285.
+ it "should be able to copy files with pound signs in their names" do
+ source = tmpfile("filewith#signs")
- dest = tmpfile("destwith#signs")
+ dest = tmpfile("destwith#signs")
- File.open(source, "w") { |f| f.print "foo" }
+ File.open(source, "w") { |f| f.print "foo" }
- file = Puppet::Type::File.new(:name => dest, :source => source)
+ file = Puppet::Type::File.new(:name => dest, :source => source)
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- catalog.apply
+ catalog.apply
- File.read(dest).should == "foo"
- end
+ File.read(dest).should == "foo"
+ end
- it "should be able to copy files with spaces in their names" do
- source = tmpfile("filewith spaces")
+ it "should be able to copy files with spaces in their names" do
+ source = tmpfile("filewith spaces")
- dest = tmpfile("destwith spaces")
+ dest = tmpfile("destwith spaces")
- File.open(source, "w") { |f| f.print "foo" }
- File.chmod(0755, source)
+ File.open(source, "w") { |f| f.print "foo" }
+ File.chmod(0755, source)
- file = Puppet::Type::File.new(:path => dest, :source => source)
+ file = Puppet::Type::File.new(:path => dest, :source => source)
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
- catalog.apply
+ catalog.apply
- File.read(dest).should == "foo"
- (File.stat(dest).mode & 007777).should == 0755
- end
+ File.read(dest).should == "foo"
+ (File.stat(dest).mode & 007777).should == 0755
+ end
- it "should be able to copy individual files even if recurse has been specified" do
- source = tmpfile("source")
- dest = tmpfile("dest")
+ it "should be able to copy individual files even if recurse has been specified" do
+ source = tmpfile("source")
+ dest = tmpfile("dest")
- File.open(source, "w") { |f| f.print "foo" }
+ File.open(source, "w") { |f| f.print "foo" }
- file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true)
+ file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true)
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
- catalog.apply
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
+ catalog.apply
- File.read(dest).should == "foo"
- end
+ File.read(dest).should == "foo"
end
+ end
- it "should be able to create files when 'content' is specified but 'ensure' is not" do
- dest = tmpfile("files_with_content")
+ it "should be able to create files when 'content' is specified but 'ensure' is not" do
+ dest = tmpfile("files_with_content")
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :name => dest,
+ :name => dest,
- :content => "this is some content, yo"
- )
+ :content => "this is some content, yo"
+ )
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
- catalog.apply
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
+ catalog.apply
- File.read(dest).should == "this is some content, yo"
- end
+ File.read(dest).should == "this is some content, yo"
+ end
- it "should create files with content if both 'content' and 'ensure' are set" do
- dest = tmpfile("files_with_content")
+ it "should create files with content if both 'content' and 'ensure' are set" do
+ dest = tmpfile("files_with_content")
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :name => dest,
- :ensure => "file",
+ :name => dest,
+ :ensure => "file",
- :content => "this is some content, yo"
- )
+ :content => "this is some content, yo"
+ )
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
- catalog.apply
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
+ catalog.apply
- File.read(dest).should == "this is some content, yo"
- end
+ File.read(dest).should == "this is some content, yo"
+ end
- it "should delete files with sources but that are set for deletion" do
- dest = tmpfile("dest_source_with_ensure")
- source = tmpfile("source_source_with_ensure")
- File.open(source, "w") { |f| f.puts "yay" }
- File.open(dest, "w") { |f| f.puts "boo" }
+ it "should delete files with sources but that are set for deletion" do
+ dest = tmpfile("dest_source_with_ensure")
+ source = tmpfile("source_source_with_ensure")
+ File.open(source, "w") { |f| f.puts "yay" }
+ File.open(dest, "w") { |f| f.puts "boo" }
- file = Puppet::Type.type(:file).new(
+ file = Puppet::Type.type(:file).new(
- :name => dest,
- :ensure => :absent,
- :source => source,
+ :name => dest,
+ :ensure => :absent,
+ :source => source,
- :backup => false
- )
+ :backup => false
+ )
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource file
- catalog.apply
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file
+ catalog.apply
- File.should_not be_exist(dest)
- end
+ File.should_not be_exist(dest)
+ end
- describe "when purging files" do
- before do
- @sourcedir = tmpfile("purge_source")
- @destdir = tmpfile("purge_dest")
- Dir.mkdir(@sourcedir)
- Dir.mkdir(@destdir)
- @sourcefile = File.join(@sourcedir, "sourcefile")
- @copiedfile = File.join(@destdir, "sourcefile")
- @localfile = File.join(@destdir, "localfile")
- @purgee = File.join(@destdir, "to_be_purged")
- File.open(@localfile, "w") { |f| f.puts "rahtest" }
- File.open(@sourcefile, "w") { |f| f.puts "funtest" }
- # this file should get removed
- File.open(@purgee, "w") { |f| f.puts "footest" }
-
-
- @lfobj = Puppet::Type.newfile(
+ describe "when purging files" do
+ before do
+ @sourcedir = tmpfile("purge_source")
+ @destdir = tmpfile("purge_dest")
+ Dir.mkdir(@sourcedir)
+ Dir.mkdir(@destdir)
+ @sourcefile = File.join(@sourcedir, "sourcefile")
+ @copiedfile = File.join(@destdir, "sourcefile")
+ @localfile = File.join(@destdir, "localfile")
+ @purgee = File.join(@destdir, "to_be_purged")
+ File.open(@localfile, "w") { |f| f.puts "rahtest" }
+ File.open(@sourcefile, "w") { |f| f.puts "funtest" }
+ # this file should get removed
+ File.open(@purgee, "w") { |f| f.puts "footest" }
+
+
+ @lfobj = Puppet::Type.newfile(
- :title => "localfile",
- :path => @localfile,
- :content => "rahtest\n",
- :ensure => :file,
+ :title => "localfile",
+ :path => @localfile,
+ :content => "rahtest\n",
+ :ensure => :file,
- :backup => false
- )
+ :backup => false
+ )
- @destobj = Puppet::Type.newfile(
- :title => "destdir", :path => @destdir,
- :source => @sourcedir,
- :backup => false,
- :purge => true,
+ @destobj = Puppet::Type.newfile(
+ :title => "destdir", :path => @destdir,
+ :source => @sourcedir,
+ :backup => false,
+ :purge => true,
- :recurse => true)
+ :recurse => true)
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @lfobj, @destobj
- end
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @lfobj, @destobj
+ end
- it "should still copy remote files" do
- @catalog.apply
- FileTest.should be_exist(@copiedfile)
- end
+ it "should still copy remote files" do
+ @catalog.apply
+ FileTest.should be_exist(@copiedfile)
+ end
- it "should not purge managed, local files" do
- @catalog.apply
- FileTest.should be_exist(@localfile)
- end
+ it "should not purge managed, local files" do
+ @catalog.apply
+ FileTest.should be_exist(@localfile)
+ end
- it "should purge files that are neither remote nor otherwise managed" do
- @catalog.apply
- FileTest.should_not be_exist(@purgee)
- end
+ it "should purge files that are neither remote nor otherwise managed" do
+ @catalog.apply
+ FileTest.should_not be_exist(@purgee)
end
+ end
end
diff --git a/spec/integration/type/package_spec.rb b/spec/integration/type/package_spec.rb
index 4ba928559..c89c18ba1 100755
--- a/spec/integration/type/package_spec.rb
+++ b/spec/integration/type/package_spec.rb
@@ -3,23 +3,23 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Type.type(:package), "when choosing a default package provider" do
- before do
- # the default provider is cached.
- Puppet::Type.type(:package).defaultprovider = nil
- end
+ before do
+ # the default provider is cached.
+ Puppet::Type.type(:package).defaultprovider = nil
+ end
- def provider_name(os)
- {"Ubuntu" => :apt, "Debian" => :apt, "Darwin" => :pkgdmg, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os]
- end
+ def provider_name(os)
+ {"Ubuntu" => :apt, "Debian" => :apt, "Darwin" => :pkgdmg, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os]
+ end
- it "should have a default provider" do
- Puppet::Type.type(:package).defaultprovider.should_not be_nil
- end
+ it "should have a default provider" do
+ Puppet::Type.type(:package).defaultprovider.should_not be_nil
+ end
- it "should choose the correct provider each platform" do
- unless default_provider = provider_name(Facter.value(:operatingsystem))
- pending("No default provider specified in this test for #{Facter.value(:operatingsystem)}")
- end
- Puppet::Type.type(:package).defaultprovider.name.should == default_provider
+ it "should choose the correct provider each platform" do
+ unless default_provider = provider_name(Facter.value(:operatingsystem))
+ pending("No default provider specified in this test for #{Facter.value(:operatingsystem)}")
end
+ Puppet::Type.type(:package).defaultprovider.name.should == default_provider
+ end
end
diff --git a/spec/integration/type/tidy_spec.rb b/spec/integration/type/tidy_spec.rb
index 732e7dcf8..429ba4c57 100755
--- a/spec/integration/type/tidy_spec.rb
+++ b/spec/integration/type/tidy_spec.rb
@@ -6,27 +6,27 @@ require 'puppet_spec/files'
require 'puppet/file_bucket/dipper'
describe Puppet::Type.type(:tidy) do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- before do
- Puppet::Util::Storage.stubs(:store)
- end
+ before do
+ Puppet::Util::Storage.stubs(:store)
+ end
- # Testing #355.
- it "should be able to remove dead links" do
- dir = tmpfile("tidy_link_testing")
- link = File.join(dir, "link")
- target = tmpfile("no_such_file_tidy_link_testing")
- Dir.mkdir(dir)
- File.symlink(target, link)
+ # Testing #355.
+ it "should be able to remove dead links" do
+ dir = tmpfile("tidy_link_testing")
+ link = File.join(dir, "link")
+ target = tmpfile("no_such_file_tidy_link_testing")
+ Dir.mkdir(dir)
+ File.symlink(target, link)
- tidy = Puppet::Type.type(:tidy).new :path => dir, :recurse => true
+ tidy = Puppet::Type.type(:tidy).new :path => dir, :recurse => true
- catalog = Puppet::Resource::Catalog.new
- catalog.add_resource(tidy)
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource(tidy)
- catalog.apply
+ catalog.apply
- FileTest.should_not be_symlink(link)
- end
+ FileTest.should_not be_symlink(link)
+ end
end
diff --git a/spec/integration/type_spec.rb b/spec/integration/type_spec.rb
index 78e8947ec..957dfe344 100755
--- a/spec/integration/type_spec.rb
+++ b/spec/integration/type_spec.rb
@@ -5,18 +5,18 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/type'
describe Puppet::Type do
- it "should not lose its provider list when it is reloaded" do
- type = Puppet::Type.newtype(:integration_test) do
- newparam(:name) {}
- end
-
- provider = type.provide(:myprovider) {}
+ it "should not lose its provider list when it is reloaded" do
+ type = Puppet::Type.newtype(:integration_test) do
+ newparam(:name) {}
+ end
- # reload it
- type = Puppet::Type.newtype(:integration_test) do
- newparam(:name) {}
- end
+ provider = type.provide(:myprovider) {}
- type.provider(:myprovider).should equal(provider)
+ # reload it
+ type = Puppet::Type.newtype(:integration_test) do
+ newparam(:name) {}
end
+
+ type.provider(:myprovider).should equal(provider)
+ end
end
diff --git a/spec/integration/util/autoload_spec.rb b/spec/integration/util/autoload_spec.rb
index ab1ff74b0..8a5d66232 100755
--- a/spec/integration/util/autoload_spec.rb
+++ b/spec/integration/util/autoload_spec.rb
@@ -6,109 +6,109 @@ require 'puppet/util/autoload'
require 'fileutils'
class AutoloadIntegrator
- @things = []
- def self.newthing(name)
- @things << name
- end
-
- def self.thing?(name)
- @things.include? name
- end
-
- def self.clear
- @things.clear
- end
+ @things = []
+ def self.newthing(name)
+ @things << name
+ end
+
+ def self.thing?(name)
+ @things.include? name
+ end
+
+ def self.clear
+ @things.clear
+ end
end
require 'puppet_spec/files'
describe Puppet::Util::Autoload do
- include PuppetSpec::Files
-
- def with_file(name, *path)
- path = File.join(*path)
- # Now create a file to load
- File.open(path, "w") { |f|
- f.puts "\nAutoloadIntegrator.newthing(:#{name.to_s})\n"
- }
- yield
- File.delete(path)
- end
-
- def with_loader(name, path)
- dir = tmpfile(name + path)
- $LOAD_PATH << dir
- Dir.mkdir(dir)
- rbdir = File.join(dir, path.to_s)
- Dir.mkdir(rbdir)
- loader = Puppet::Util::Autoload.new(name, path)
- yield rbdir, loader
- Dir.rmdir(rbdir)
- Dir.rmdir(dir)
- $LOAD_PATH.pop
- AutoloadIntegrator.clear
- end
-
- it "should make instances available by the loading class" do
- loader = Puppet::Util::Autoload.new("foo", "bar")
- Puppet::Util::Autoload["foo"].should == loader
- end
-
- it "should not fail when asked to load a missing file" do
- Puppet::Util::Autoload.new("foo", "bar").load(:eh).should be_false
- end
-
- it "should load and return true when it successfully loads a file" do
- with_loader("foo", "bar") { |dir,loader|
- with_file(:mything, dir, "mything.rb") {
- loader.load(:mything).should be_true
- loader.should be_loaded(:mything)
- AutoloadIntegrator.should be_thing(:mything)
- }
- }
- end
-
- it "should consider a file loaded when asked for the name without an extension" do
- with_loader("foo", "bar") { |dir,loader|
- with_file(:noext, dir, "noext.rb") {
- loader.load(:noext)
- loader.should be_loaded(:noext)
- }
- }
- end
-
- it "should consider a file loaded when asked for the name with an extension" do
- with_loader("foo", "bar") { |dir,loader|
- with_file(:noext, dir, "withext.rb") {
- loader.load(:withext)
- loader.should be_loaded("withext.rb")
- }
- }
- end
-
- it "should register the fact that the instance is loaded with the Autoload base class" do
- with_loader("foo", "bar") { |dir,loader|
- with_file(:baseload, dir, "baseload.rb") {
- loader.load(:baseload)
- Puppet::Util::Autoload.should be_loaded("bar/withext.rb")
- }
- }
- end
-
- it "should be able to load files directly from modules" do
- modulepath = tmpfile("autoload_module_testing")
- libdir = File.join(modulepath, "mymod", "lib", "foo")
- FileUtils.mkdir_p(libdir)
-
- file = File.join(libdir, "plugin.rb")
-
- Puppet[:modulepath] = modulepath
-
- with_loader("foo", "foo") do |dir, loader|
- with_file(:plugin, file.split("/")) do
- loader.load(:plugin)
- loader.should be_loaded("plugin.rb")
- end
- end
+ include PuppetSpec::Files
+
+ def with_file(name, *path)
+ path = File.join(*path)
+ # Now create a file to load
+ File.open(path, "w") { |f|
+ f.puts "\nAutoloadIntegrator.newthing(:#{name.to_s})\n"
+ }
+ yield
+ File.delete(path)
+ end
+
+ def with_loader(name, path)
+ dir = tmpfile(name + path)
+ $LOAD_PATH << dir
+ Dir.mkdir(dir)
+ rbdir = File.join(dir, path.to_s)
+ Dir.mkdir(rbdir)
+ loader = Puppet::Util::Autoload.new(name, path)
+ yield rbdir, loader
+ Dir.rmdir(rbdir)
+ Dir.rmdir(dir)
+ $LOAD_PATH.pop
+ AutoloadIntegrator.clear
+ end
+
+ it "should make instances available by the loading class" do
+ loader = Puppet::Util::Autoload.new("foo", "bar")
+ Puppet::Util::Autoload["foo"].should == loader
+ end
+
+ it "should not fail when asked to load a missing file" do
+ Puppet::Util::Autoload.new("foo", "bar").load(:eh).should be_false
+ end
+
+ it "should load and return true when it successfully loads a file" do
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:mything, dir, "mything.rb") {
+ loader.load(:mything).should be_true
+ loader.should be_loaded(:mything)
+ AutoloadIntegrator.should be_thing(:mything)
+ }
+ }
+ end
+
+ it "should consider a file loaded when asked for the name without an extension" do
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:noext, dir, "noext.rb") {
+ loader.load(:noext)
+ loader.should be_loaded(:noext)
+ }
+ }
+ end
+
+ it "should consider a file loaded when asked for the name with an extension" do
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:noext, dir, "withext.rb") {
+ loader.load(:withext)
+ loader.should be_loaded("withext.rb")
+ }
+ }
+ end
+
+ it "should register the fact that the instance is loaded with the Autoload base class" do
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:baseload, dir, "baseload.rb") {
+ loader.load(:baseload)
+ Puppet::Util::Autoload.should be_loaded("bar/withext.rb")
+ }
+ }
+ end
+
+ it "should be able to load files directly from modules" do
+ modulepath = tmpfile("autoload_module_testing")
+ libdir = File.join(modulepath, "mymod", "lib", "foo")
+ FileUtils.mkdir_p(libdir)
+
+ file = File.join(libdir, "plugin.rb")
+
+ Puppet[:modulepath] = modulepath
+
+ with_loader("foo", "foo") do |dir, loader|
+ with_file(:plugin, file.split("/")) do
+ loader.load(:plugin)
+ loader.should be_loaded("plugin.rb")
+ end
end
+ end
end
diff --git a/spec/integration/util/feature_spec.rb b/spec/integration/util/feature_spec.rb
index b2adbd026..f1ada9057 100755
--- a/spec/integration/util/feature_spec.rb
+++ b/spec/integration/util/feature_spec.rb
@@ -6,49 +6,49 @@ require 'puppet/util/feature'
require 'puppet_spec/files'
describe Puppet::Util::Feature do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- it "should be able to load features from disk" do
- libdir = tmpfile("feature_lib")
- Dir.mkdir(libdir)
+ it "should be able to load features from disk" do
+ libdir = tmpfile("feature_lib")
+ Dir.mkdir(libdir)
- $LOAD_PATH << libdir
+ $LOAD_PATH << libdir
- $features = Puppet::Util::Feature.new("feature_lib")
+ $features = Puppet::Util::Feature.new("feature_lib")
- Dir.mkdir(File.join(libdir, "feature_lib"))
+ Dir.mkdir(File.join(libdir, "feature_lib"))
- File.open(File.join(libdir, "feature_lib", "able_to_load.rb"), "w") do |f|
- f.puts "$features.add(:able_to_load) { true }"
- end
+ File.open(File.join(libdir, "feature_lib", "able_to_load.rb"), "w") do |f|
+ f.puts "$features.add(:able_to_load) { true }"
+ end
- $features.should be_able_to_load
+ $features.should be_able_to_load
+ end
+
+ # TODO: Make this a spec test or remove it.
+ def test_dynamic_loading
+ $features = @features
+ cleanup { $features = nil }
+ # Now create a feature and make sure it loads.
+ FileUtils.mkdir_p(@path)
+ nope = File.join(@path, "nope.rb")
+ File.open(nope, "w") { |f|
+ f.puts "$features.add(:nope, :libs => %w{nosuchlib})"
+ }
+ assert_nothing_raised("Failed to autoload features") do
+ assert(! @features.nope?, "'nope' returned true")
end
- # TODO: Make this a spec test or remove it.
- def test_dynamic_loading
- $features = @features
- cleanup { $features = nil }
- # Now create a feature and make sure it loads.
- FileUtils.mkdir_p(@path)
- nope = File.join(@path, "nope.rb")
- File.open(nope, "w") { |f|
- f.puts "$features.add(:nope, :libs => %w{nosuchlib})"
- }
- assert_nothing_raised("Failed to autoload features") do
- assert(! @features.nope?, "'nope' returned true")
- end
-
- # First make sure "yep?" returns false
- assert_nothing_raised("Missing feature threw an exception") do
- assert(! @features.notyep?, "'notyep' returned true before definition")
- end
-
- yep = File.join(@path, "yep.rb")
- File.open(yep, "w") { |f|
- f.puts "$features.add(:yep, :libs => %w{puppet})"
- }
-
- assert(@features.yep?, "false 'yep' is apparently cached or feature could not be loaded")
+ # First make sure "yep?" returns false
+ assert_nothing_raised("Missing feature threw an exception") do
+ assert(! @features.notyep?, "'notyep' returned true before definition")
end
+
+ yep = File.join(@path, "yep.rb")
+ File.open(yep, "w") { |f|
+ f.puts "$features.add(:yep, :libs => %w{puppet})"
+ }
+
+ assert(@features.yep?, "false 'yep' is apparently cached or feature could not be loaded")
+ end
end
diff --git a/spec/integration/util/file_locking_spec.rb b/spec/integration/util/file_locking_spec.rb
index e584f9ef1..20c61d3d5 100755
--- a/spec/integration/util/file_locking_spec.rb
+++ b/spec/integration/util/file_locking_spec.rb
@@ -5,33 +5,33 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
require 'puppet/util/file_locking'
describe Puppet::Util::FileLocking do
- it "should be able to keep file corruption from happening when there are multiple writers" do
- file = Tempfile.new("puppetspec")
- filepath = file.path
- file.close!()
- file = filepath
- data = {:a => :b, :c => "A string", :d => "another string", :e => %w{an array of strings}}
- File.open(file, "w") { |f| f.puts YAML.dump(data) }
+ it "should be able to keep file corruption from happening when there are multiple writers" do
+ file = Tempfile.new("puppetspec")
+ filepath = file.path
+ file.close!()
+ file = filepath
+ data = {:a => :b, :c => "A string", :d => "another string", :e => %w{an array of strings}}
+ File.open(file, "w") { |f| f.puts YAML.dump(data) }
- threads = []
- sync = Sync.new
- 9.times { |a|
- threads << Thread.new {
- 9.times { |b|
- sync.synchronize(Sync::SH) {
- Puppet::Util::FileLocking.readlock(file) { |f|
- YAML.load(f.read).should == data
- }
- }
- sleep 0.01
- sync.synchronize(Sync::EX) {
- Puppet::Util::FileLocking.writelock(file) { |f|
- f.puts YAML.dump(data)
- }
- }
- }
+ threads = []
+ sync = Sync.new
+ 9.times { |a|
+ threads << Thread.new {
+ 9.times { |b|
+ sync.synchronize(Sync::SH) {
+ Puppet::Util::FileLocking.readlock(file) { |f|
+ YAML.load(f.read).should == data
}
+ }
+ sleep 0.01
+ sync.synchronize(Sync::EX) {
+ Puppet::Util::FileLocking.writelock(file) { |f|
+ f.puts YAML.dump(data)
+ }
+ }
}
- threads.each { |th| th.join }
- end
+ }
+ }
+ threads.each { |th| th.join }
+ end
end
diff --git a/spec/integration/util/rdoc/parser_spec.rb b/spec/integration/util/rdoc/parser_spec.rb
index 01bcb644b..7d3b0ec3e 100755
--- a/spec/integration/util/rdoc/parser_spec.rb
+++ b/spec/integration/util/rdoc/parser_spec.rb
@@ -10,50 +10,50 @@ require 'rdoc/options'
require 'rdoc/rdoc'
describe RDoc::Parser do
- require 'puppet_spec/files'
- include PuppetSpec::Files
-
- before :each do
- tmpdir = tmpfile('rdoc_parser_tmp')
- Dir.mkdir(tmpdir)
- @parsedfile = File.join(tmpdir, 'init.pp')
-
- File.open(@parsedfile, 'w') do |f|
- f.puts '# comment'
- f.puts 'class ::test {}'
- end
-
- @top_level = stub_everything 'toplevel', :file_relative_name => @parsedfile
- @module = stub_everything 'module'
- @puppet_top_level = RDoc::PuppetTopLevel.new(@top_level)
- RDoc::PuppetTopLevel.stubs(:new).returns(@puppet_top_level)
- @puppet_top_level.expects(:add_module).returns(@module)
- @parser = RDoc::Parser.new(@top_level, @parsedfile, nil, Options.instance, RDoc::Stats.new)
- end
+ require 'puppet_spec/files'
+ include PuppetSpec::Files
- after(:each) do
- File.unlink(@parsedfile)
- end
+ before :each do
+ tmpdir = tmpfile('rdoc_parser_tmp')
+ Dir.mkdir(tmpdir)
+ @parsedfile = File.join(tmpdir, 'init.pp')
- def get_test_class(toplevel)
- # toplevel -> main -> test
- toplevel.classes[0].classes[0]
+ File.open(@parsedfile, 'w') do |f|
+ f.puts '# comment'
+ f.puts 'class ::test {}'
end
- it "should parse to RDoc data structure" do
- @parser.expects(:document_class).with { |n,k,c| n == "::test" and k.is_a?(Puppet::Resource::Type) }
- @parser.scan
- end
-
- it "should get a PuppetClass for the main class" do
- @parser.scan.classes[0].should be_a(RDoc::PuppetClass)
- end
-
- it "should produce a PuppetClass whose name is test" do
- get_test_class(@parser.scan).name.should == "test"
- end
-
- it "should produce a PuppetClass whose comment is 'comment'" do
- get_test_class(@parser.scan).comment.should == "comment\n"
- end
+ @top_level = stub_everything 'toplevel', :file_relative_name => @parsedfile
+ @module = stub_everything 'module'
+ @puppet_top_level = RDoc::PuppetTopLevel.new(@top_level)
+ RDoc::PuppetTopLevel.stubs(:new).returns(@puppet_top_level)
+ @puppet_top_level.expects(:add_module).returns(@module)
+ @parser = RDoc::Parser.new(@top_level, @parsedfile, nil, Options.instance, RDoc::Stats.new)
+ end
+
+ after(:each) do
+ File.unlink(@parsedfile)
+ end
+
+ def get_test_class(toplevel)
+ # toplevel -> main -> test
+ toplevel.classes[0].classes[0]
+ end
+
+ it "should parse to RDoc data structure" do
+ @parser.expects(:document_class).with { |n,k,c| n == "::test" and k.is_a?(Puppet::Resource::Type) }
+ @parser.scan
+ end
+
+ it "should get a PuppetClass for the main class" do
+ @parser.scan.classes[0].should be_a(RDoc::PuppetClass)
+ end
+
+ it "should produce a PuppetClass whose name is test" do
+ get_test_class(@parser.scan).name.should == "test"
+ end
+
+ it "should produce a PuppetClass whose comment is 'comment'" do
+ get_test_class(@parser.scan).comment.should == "comment\n"
+ end
end
diff --git a/spec/integration/util/settings_spec.rb b/spec/integration/util/settings_spec.rb
index 536eab643..27acd90ee 100755
--- a/spec/integration/util/settings_spec.rb
+++ b/spec/integration/util/settings_spec.rb
@@ -5,26 +5,26 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet_spec/files'
describe Puppet::Util::Settings do
- include PuppetSpec::Files
+ include PuppetSpec::Files
- def minimal_default_settings
- { :noop => {:default => false, :desc => "noop"} }
- end
+ def minimal_default_settings
+ { :noop => {:default => false, :desc => "noop"} }
+ end
- it "should be able to make needed directories" do
- settings = Puppet::Util::Settings.new
- settings.setdefaults :main, minimal_default_settings.update( :maindir => [tmpfile("main"), "a"] )
- settings.use(:main)
+ it "should be able to make needed directories" do
+ settings = Puppet::Util::Settings.new
+ settings.setdefaults :main, minimal_default_settings.update( :maindir => [tmpfile("main"), "a"] )
+ settings.use(:main)
- File.should be_directory(settings[:maindir])
- end
+ File.should be_directory(settings[:maindir])
+ end
- it "should make its directories with the corret modes" do
- settings = Puppet::Util::Settings.new
- settings.setdefaults :main, minimal_default_settings.update( :maindir => {:default => tmpfile("main"), :desc => "a", :mode => 0750} )
+ it "should make its directories with the corret modes" do
+ settings = Puppet::Util::Settings.new
+ settings.setdefaults :main, minimal_default_settings.update( :maindir => {:default => tmpfile("main"), :desc => "a", :mode => 0750} )
- settings.use(:main)
+ settings.use(:main)
- (File.stat(settings[:maindir]).mode & 007777).should == 0750
- end
+ (File.stat(settings[:maindir]).mode & 007777).should == 0750
+ end
end