Add support for testing the catalogue for a defined host
This commit is contained in:
parent
a3fff45164
commit
a1b5ebe25d
10
README.md
10
README.md
|
@ -28,8 +28,12 @@ structure and naming convention.
|
|||
| +-- <define_name>_spec.rb
|
||||
|
|
||||
+-- functions
|
||||
| |
|
||||
| +-- <function_name>_spec.rb
|
||||
|
|
||||
+-- hosts
|
||||
|
|
||||
+-- <function_name>_spec.rb
|
||||
+-- <host_name>_spec.rb
|
||||
|
||||
## Example groups
|
||||
|
||||
|
@ -49,6 +53,10 @@ end
|
|||
describe 'myfunction', :type => :puppet_function do
|
||||
...
|
||||
end
|
||||
|
||||
describe 'myhost.example.com', :type => :host do
|
||||
...
|
||||
end
|
||||
```
|
||||
|
||||
## Defined Types & Classes
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'rspec-puppet/support'
|
|||
require 'rspec-puppet/example/define_example_group'
|
||||
require 'rspec-puppet/example/class_example_group'
|
||||
require 'rspec-puppet/example/function_example_group'
|
||||
require 'rspec-puppet/example/host_example_group'
|
||||
|
||||
RSpec::configure do |c|
|
||||
def c.escaped_path(*parts)
|
||||
|
@ -19,4 +20,8 @@ RSpec::configure do |c|
|
|||
c.include RSpec::Puppet::FunctionExampleGroup, :type => :puppet_function, :example_group => {
|
||||
:file_path => c.escaped_path(%w[spec functions])
|
||||
}
|
||||
|
||||
c.include RSpec::Puppet::HostExampleGroup, :type => :host, :example_group => {
|
||||
:file_path => c.escaped_path(%w[spec hosts])
|
||||
}
|
||||
end
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
module RSpec::Puppet
|
||||
module HostExampleGroup
|
||||
include RSpec::Puppet::ManifestMatchers
|
||||
include RSpec::Puppet::Support
|
||||
|
||||
def subject
|
||||
@catalogue ||= catalogue
|
||||
end
|
||||
|
||||
def catalogue
|
||||
Puppet[:modulepath] = self.respond_to?(:module_path) ? module_path : RSpec.configuration.module_path
|
||||
Puppet[:manifestdir] = self.respond_to?(:manifest_dir) ? manifest_dir : RSpec.configuration.manifest_dir
|
||||
Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest
|
||||
Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir
|
||||
Puppet[:code] = ""
|
||||
|
||||
nodename = self.class.top_level_description.downcase
|
||||
|
||||
facts_val = {
|
||||
'hostname' => nodename.split('.').first,
|
||||
'fqdn' => nodename,
|
||||
'domain' => nodename.split('.').last,
|
||||
}
|
||||
facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
|
||||
|
||||
build_catalog(nodename, facts_val)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|||
'lib/rspec-puppet/example/class_example_group.rb',
|
||||
'lib/rspec-puppet/example/define_example_group.rb',
|
||||
'lib/rspec-puppet/example/function_example_group.rb',
|
||||
'lib/rspec-puppet/example/host_example_group.rb',
|
||||
'lib/rspec-puppet/example.rb',
|
||||
'lib/rspec-puppet/matchers/create_generic.rb',
|
||||
'lib/rspec-puppet/matchers/create_resource.rb',
|
||||
|
@ -26,8 +27,11 @@ Gem::Specification.new do |s|
|
|||
'spec/classes/sysctl_common_spec.rb',
|
||||
'spec/defines/sysctl_before_spec.rb',
|
||||
'spec/defines/sysctl_spec.rb',
|
||||
'spec/fixtures/boolean/manifests/init.pp',
|
||||
'spec/fixtures/sysctl/manifests/init.pp',
|
||||
'spec/hosts/foo_spec.rb',
|
||||
'spec/hosts/testhost_spec.rb',
|
||||
'spec/fixtures/manifests/site.pp',
|
||||
'spec/fixtures/modules/boolean/manifests/init.pp',
|
||||
'spec/fixtures/modules/sysctl/manifests/init.pp',
|
||||
'spec/functions/split_spec.rb',
|
||||
'spec/spec_helper.rb',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
node default {
|
||||
notify { 'test': }
|
||||
}
|
||||
|
||||
node /testhost/ {
|
||||
include sysctl::common
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'foo.example.com' do
|
||||
it { should_not include_class('sysctl::common') }
|
||||
it { should contain_notify('test') }
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'testhost' do
|
||||
it { should include_class('sysctl::common') }
|
||||
end
|
Loading…
Reference in New Issue