diff options
| author | Dominic Maraglia <dominic@puppetlabs.com> | 2011-08-03 15:43:20 -0700 |
|---|---|---|
| committer | Dominic Maraglia <dominic@puppetlabs.com> | 2011-08-03 15:43:20 -0700 |
| commit | e45f08bf1fef8842554ca0d8cb6fb13711e888e7 (patch) | |
| tree | 9bb476a0fe381d53060abc1f1c240cf1291b2ee4 /spec/unit/node | |
| parent | a97c86e7d01384aa06f5d4d69da427fc355aebe7 (diff) | |
| parent | c833fde370d43023f52c8f2e11fd77e720d0f577 (diff) | |
Merge branch 'master' of github.com:puppetlabs/puppet
Diffstat (limited to 'spec/unit/node')
| -rwxr-xr-x | spec/unit/node/environment_spec.rb | 49 | ||||
| -rwxr-xr-x | spec/unit/node/facts_spec.rb | 18 |
2 files changed, 32 insertions, 35 deletions
diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index d1badfa3a..78d383440 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -1,6 +1,8 @@ #!/usr/bin/env rspec require 'spec_helper' +require 'tmpdir' + require 'puppet/node/environment' require 'puppet/util/execution' @@ -10,10 +12,6 @@ describe Puppet::Node::Environment do Puppet::Node::Environment.clear end - it "should include the Cacher module" do - Puppet::Node::Environment.ancestors.should be_include(Puppet::Util::Cacher) - end - it "should use the filetimeout for the ttl for the modulepath" do Puppet::Node::Environment.attr_ttl(:modulepath).should == Integer(Puppet[:filetimeout]) end @@ -22,10 +20,6 @@ describe Puppet::Node::Environment do Puppet::Node::Environment.attr_ttl(:modules).should == Integer(Puppet[:filetimeout]) end - it "should use the filetimeout for the ttl for the manifestdir" do - Puppet::Node::Environment.attr_ttl(:manifestdir).should == Integer(Puppet[:filetimeout]) - end - it "should use the default environment if no name is provided while initializing an environment" do Puppet.settings.expects(:value).with(:environment).returns("one") Puppet::Node::Environment.new.name.should == :one @@ -109,27 +103,15 @@ describe Puppet::Node::Environment do end end - [:modulepath, :manifestdir].each do |setting| - it "should validate the #{setting} directories" do - path = %w{/one /two}.join(File::PATH_SEPARATOR) - - env = Puppet::Node::Environment.new("testing") - env.stubs(:[]).with(setting).returns path - - env.expects(:validate_dirs).with(%w{/one /two}) - - env.send(setting) - end + it "should validate the modulepath directories" do + real_file = tmpdir('moduledir') + path = %W[/one /two #{real_file}].join(File::PATH_SEPARATOR) - it "should return the validated dirs for #{setting}" do - path = %w{/one /two}.join(File::PATH_SEPARATOR) + Puppet[:modulepath] = path - env = Puppet::Node::Environment.new("testing") - env.stubs(:[]).with(setting).returns path - env.stubs(:validate_dirs).returns %w{/one /two} + env = Puppet::Node::Environment.new("testing") - env.send(setting).should == %w{/one /two} - end + env.modulepath.should == [real_file] end it "should prefix the value of the 'PUPPETLIB' environment variable to the module path if present" do @@ -144,21 +126,26 @@ describe Puppet::Node::Environment do end describe "when validating modulepath or manifestdir directories" do + before :each do + @path_one = make_absolute('/one') + @path_two = make_absolute('/two') + end + it "should not return non-directories" do env = Puppet::Node::Environment.new("testing") - FileTest.expects(:directory?).with("/one").returns true - FileTest.expects(:directory?).with("/two").returns false + FileTest.expects(:directory?).with(@path_one).returns true + FileTest.expects(:directory?).with(@path_two).returns false - env.validate_dirs(%w{/one /two}).should == %w{/one} + env.validate_dirs([@path_one, @path_two]).should == [@path_one] end it "should use the current working directory to fully-qualify unqualified paths" do FileTest.stubs(:directory?).returns true env = Puppet::Node::Environment.new("testing") - two = File.join(Dir.getwd, "two") - env.validate_dirs(%w{/one two}).should == ["/one", two] + two = File.expand_path(File.join(Dir.getwd, "two")) + env.validate_dirs([@path_one, 'two']).should == [@path_one, two] end end diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb index efaa76e12..b3a0f92dd 100755 --- a/spec/unit/node/facts_spec.rb +++ b/spec/unit/node/facts_spec.rb @@ -68,10 +68,6 @@ describe Puppet::Node::Facts, "when indirecting" do before do @indirection = stub 'indirection', :request => mock('request'), :name => :facts - # We have to clear the cache so that the facts ask for our indirection stub, - # instead of anything that might be cached. - Puppet::Util::Cacher.expire - @facts = Puppet::Node::Facts.new("me", "one" => "two") end @@ -128,6 +124,20 @@ describe Puppet::Node::Facts, "when indirecting" do result['timestamp'].should == facts.timestamp.to_s result['expiration'].should == facts.expiration.to_s end + + it "should not include nil values" do + facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3}) + pson = PSON.parse(facts.to_pson) + pson.should_not be_include("expiration") + end + + it "should be able to handle nil values" do + pson = %Q({"name": "foo", "values": {"a": "1", "b": "2", "c": "3"}}) + format = Puppet::Network::FormatHandler.format('pson') + facts = format.intern(Puppet::Node::Facts,pson) + facts.name.should == 'foo' + facts.expiration.should be_nil + end end end end |
