Added modules
This commit is contained in:
parent
c53c931217
commit
59ec520742
646 changed files with 35182 additions and 0 deletions
32
modules/stdlib/spec/unit/facter/facter_dot_d_spec.rb
Executable file
32
modules/stdlib/spec/unit/facter/facter_dot_d_spec.rb
Executable file
|
@ -0,0 +1,32 @@
|
|||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
require 'facter/facter_dot_d'
|
||||
|
||||
describe Facter::Util::DotD do
|
||||
|
||||
context 'returns a simple fact' do
|
||||
before :each do
|
||||
Facter.stubs(:version).returns('1.6.1')
|
||||
subject.stubs(:entries).returns(['/etc/facter/facts.d/fake_fact.txt'])
|
||||
File.stubs(:readlines).with('/etc/facter/facts.d/fake_fact.txt').returns(['fake_fact=fake fact'])
|
||||
subject.create
|
||||
end
|
||||
|
||||
it 'should return successfully' do
|
||||
Facter.fact(:fake_fact).value.should == 'fake fact'
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns a fact with equals signs' do
|
||||
before :each do
|
||||
Facter.stubs(:version).returns('1.6.1')
|
||||
subject.stubs(:entries).returns(['/etc/facter/facts.d/foo.txt'])
|
||||
File.stubs(:readlines).with('/etc/facter/facts.d/foo.txt').returns(['foo=1+1=2'])
|
||||
subject.create
|
||||
end
|
||||
|
||||
it 'should return successfully' do
|
||||
Facter.fact(:foo).value.should == '1+1=2'
|
||||
end
|
||||
end
|
||||
end
|
76
modules/stdlib/spec/unit/facter/pe_version_spec.rb
Executable file
76
modules/stdlib/spec/unit/facter/pe_version_spec.rb
Executable file
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env rspec
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe "PE Version specs" do
|
||||
before :each do
|
||||
# Explicitly load the pe_version.rb file which contains generated facts
|
||||
# that cannot be automatically loaded. Puppet 2.x implements
|
||||
# Facter.collection.load while Facter 1.x markes Facter.collection.load as
|
||||
# a private method.
|
||||
if Facter.collection.respond_to? :load
|
||||
Facter.collection.load(:pe_version)
|
||||
else
|
||||
Facter.collection.loader.load(:pe_version)
|
||||
end
|
||||
end
|
||||
|
||||
context "If PE is installed" do
|
||||
%w{ 2.6.1 2.10.300 }.each do |version|
|
||||
puppetversion = "2.7.19 (Puppet Enterprise #{version})"
|
||||
context "puppetversion => #{puppetversion}" do
|
||||
before :each do
|
||||
Facter.fact(:puppetversion).stubs(:value).returns(puppetversion)
|
||||
end
|
||||
|
||||
(major,minor,patch) = version.split(".")
|
||||
|
||||
it "Should return true" do
|
||||
Facter.fact(:is_pe).value.should == true
|
||||
end
|
||||
|
||||
it "Should have a version of #{version}" do
|
||||
Facter.fact(:pe_version).value.should == version
|
||||
end
|
||||
|
||||
it "Should have a major version of #{major}" do
|
||||
Facter.fact(:pe_major_version).value.should == major
|
||||
end
|
||||
|
||||
it "Should have a minor version of #{minor}" do
|
||||
Facter.fact(:pe_minor_version).value.should == minor
|
||||
end
|
||||
|
||||
it "Should have a patch version of #{patch}" do
|
||||
Facter.fact(:pe_patch_version).value.should == patch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "When PE is not installed" do
|
||||
before :each do
|
||||
Facter.fact(:puppetversion).stubs(:value).returns("2.7.19")
|
||||
end
|
||||
|
||||
it "is_pe is false" do
|
||||
Facter.fact(:is_pe).value.should == false
|
||||
end
|
||||
|
||||
it "pe_version is nil" do
|
||||
Facter.fact(:pe_version).value.should be_nil
|
||||
end
|
||||
|
||||
it "pe_major_version is nil" do
|
||||
Facter.fact(:pe_major_version).value.should be_nil
|
||||
end
|
||||
|
||||
it "pe_minor_version is nil" do
|
||||
Facter.fact(:pe_minor_version).value.should be_nil
|
||||
end
|
||||
|
||||
it "Should have a patch version" do
|
||||
Facter.fact(:pe_patch_version).value.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
52
modules/stdlib/spec/unit/facter/root_home_spec.rb
Executable file
52
modules/stdlib/spec/unit/facter/root_home_spec.rb
Executable file
|
@ -0,0 +1,52 @@
|
|||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
require 'facter/root_home'
|
||||
|
||||
describe Facter::Util::RootHome do
|
||||
context "solaris" do
|
||||
let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
|
||||
let(:expected_root_home) { "/" }
|
||||
|
||||
it "should return /" do
|
||||
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
||||
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
||||
end
|
||||
end
|
||||
context "linux" do
|
||||
let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
|
||||
let(:expected_root_home) { "/root" }
|
||||
|
||||
it "should return /root" do
|
||||
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
||||
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
||||
end
|
||||
end
|
||||
context "windows" do
|
||||
before :each do
|
||||
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
|
||||
end
|
||||
it "should be nil on windows" do
|
||||
Facter::Util::RootHome.get_root_home.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'root_home', :type => :fact do
|
||||
before { Facter.clear }
|
||||
after { Facter.clear }
|
||||
|
||||
context "macosx" do
|
||||
before do
|
||||
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
||||
Facter.fact(:osfamily).stubs(:value).returns("Darwin")
|
||||
end
|
||||
let(:expected_root_home) { "/var/root" }
|
||||
sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
|
||||
|
||||
it "should return /var/root" do
|
||||
Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
|
||||
Facter.fact(:root_home).value.should == expected_root_home
|
||||
end
|
||||
end
|
||||
|
||||
end
|
36
modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
Executable file
36
modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
Executable file
|
@ -0,0 +1,36 @@
|
|||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
require 'facter/util/puppet_settings'
|
||||
|
||||
describe Facter::Util::PuppetSettings do
|
||||
|
||||
describe "#with_puppet" do
|
||||
context "Without Puppet loaded" do
|
||||
before(:each) do
|
||||
Module.expects(:const_get).with("Puppet").raises(NameError)
|
||||
end
|
||||
|
||||
it 'should be nil' do
|
||||
subject.with_puppet { Puppet[:vardir] }.should be_nil
|
||||
end
|
||||
it 'should not yield to the block' do
|
||||
Puppet.expects(:[]).never
|
||||
subject.with_puppet { Puppet[:vardir] }.should be_nil
|
||||
end
|
||||
end
|
||||
context "With Puppet loaded" do
|
||||
module Puppet; end
|
||||
let(:vardir) { "/var/lib/puppet" }
|
||||
|
||||
before :each do
|
||||
Puppet.expects(:[]).with(:vardir).returns vardir
|
||||
end
|
||||
it 'should yield to the block' do
|
||||
subject.with_puppet { Puppet[:vardir] }
|
||||
end
|
||||
it 'should return the nodes vardir' do
|
||||
subject.with_puppet { Puppet[:vardir] }.should eq vardir
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue