summaryrefslogtreecommitdiffstats
path: root/spec/integration/util
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration/util')
-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
5 files changed, 219 insertions, 219 deletions
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