rspec-puppet-maestrodev 0.1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ module RSpec::Puppet
2
+ module Support
3
+
4
+ @@cache = {}
5
+
6
+ protected
7
+ def build_catalog_without_cache(nodename, facts_val, code)
8
+ if Integer(Puppet.version.split('.').first) >= 3
9
+ Puppet.initialize_settings
10
+ end
11
+
12
+ Puppet[:code] = code
13
+
14
+ node_obj = Puppet::Node.new(nodename)
15
+
16
+ node_obj.merge(facts_val)
17
+
18
+ # trying to be compatible with 2.7 as well as 2.6
19
+ if Puppet::Resource::Catalog.respond_to? :find
20
+ Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
21
+ else
22
+ Puppet::Resource::Catalog.indirection.find(node_obj.name, :use_node => node_obj)
23
+ end
24
+ end
25
+
26
+ public
27
+ def build_catalog *args
28
+ @@cache[args] ||= self.build_catalog_without_cache(*args)
29
+ end
30
+
31
+ def munge_facts(facts)
32
+ output = {}
33
+ facts.keys.each { |key| output[key.to_s] = facts[key] }
34
+ output
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rspec-puppet-maestrodev'
3
+ s.version = '0.1.5.1'
4
+ s.homepage = 'https://github.com/rodjek/rspec-puppet/'
5
+ s.summary = 'RSpec tests for your Puppet manifests'
6
+ s.description = 'RSpec tests for your Puppet manifests'
7
+
8
+ s.executables = ['rspec-puppet-init']
9
+
10
+ s.files = [
11
+ 'bin/rspec-puppet-init',
12
+ 'lib/rspec-puppet/example/class_example_group.rb',
13
+ 'lib/rspec-puppet/example/define_example_group.rb',
14
+ 'lib/rspec-puppet/example/function_example_group.rb',
15
+ 'lib/rspec-puppet/example/host_example_group.rb',
16
+ 'lib/rspec-puppet/example.rb',
17
+ 'lib/rspec-puppet/matchers/create_generic.rb',
18
+ 'lib/rspec-puppet/matchers/create_resource.rb',
19
+ 'lib/rspec-puppet/matchers/include_class.rb',
20
+ 'lib/rspec-puppet/matchers/run.rb',
21
+ 'lib/rspec-puppet/matchers.rb',
22
+ 'lib/rspec-puppet/setup.rb',
23
+ 'lib/rspec-puppet/support.rb',
24
+ 'lib/rspec-puppet.rb',
25
+ 'LICENSE',
26
+ 'Rakefile',
27
+ 'README.md',
28
+ 'rspec-puppet.gemspec',
29
+ 'spec/classes/boolean_regexp_spec.rb',
30
+ 'spec/classes/boolean_spec.rb',
31
+ 'spec/classes/sysctl_common_spec.rb',
32
+ 'spec/defines/sysctl_before_spec.rb',
33
+ 'spec/defines/sysctl_spec.rb',
34
+ 'spec/hosts/foo_spec.rb',
35
+ 'spec/hosts/testhost_spec.rb',
36
+ 'spec/fixtures/manifests/site.pp',
37
+ 'spec/fixtures/modules/boolean/manifests/init.pp',
38
+ 'spec/fixtures/modules/sysctl/manifests/init.pp',
39
+ 'spec/functions/split_spec.rb',
40
+ 'spec/spec_helper.rb',
41
+ ]
42
+
43
+ s.add_dependency 'rspec'
44
+
45
+ s.authors = ['Tim Sharpe']
46
+ s.email = 'tim@sharpe.id.au'
47
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'boolean' do
4
+ let(:title) { 'bool.testing' }
5
+ let(:params) { { :bool => false } }
6
+ let(:message_re) { /bool is false/ }
7
+
8
+ it { should create_notify("bool testing").with_message(message_re) }
9
+ it { should_not create_notify("bool testing").with_message(/true/) }
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ if Puppet::PUPPETVERSION !~ /0\.2/
4
+ describe 'boolean' do
5
+ let(:title) { 'bool.testing' }
6
+ let(:params) { { :bool => false } }
7
+
8
+ it { should create_notify("bool testing")\
9
+ .with_message("This will print when \$bool is false.") }
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sysctl::common' do
4
+ it { should contain_exec('sysctl/reload') \
5
+ .with_command('/sbin/sysctl -p /etc/sysctl.conf').with_returns([0, 2]) }
6
+ it { should_not create_augeas('foo') }
7
+ describe 'when using with to specify a hash of parameters' do
8
+ it 'should fail if the parameter is not contained in the resource' do
9
+ expect do
10
+ subject.should contain_exec('sysctl/reload').with('foo' => 'bar')
11
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
12
+ end
13
+ it 'should pass if the parameters are contained in the resource' do
14
+ subject.should contain_exec('sysctl/reload').with(
15
+ 'refreshonly' => 'true',
16
+ 'returns' => [0, 2]
17
+ )
18
+ end
19
+ end
20
+ describe 'when using without to specify parameter name(s)' do
21
+ it 'should pass if the parameter name is not contained in the resource' do
22
+ subject.should contain_exec('sysctl/reload').without('foo')
23
+ end
24
+ it 'should pass if the parameter names are not contained in the resource' do
25
+ subject.should contain_exec('sysctl/reload').without(['foo', 'bar'])
26
+ end
27
+ it 'should fail if any of the parameter names are contained in the resource' do
28
+ expect do
29
+ subject.should contain_exec('sysctl/reload').without(['foo', 'returns'])
30
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
31
+ end
32
+ end
33
+ end
34
+
35
+ describe 'sysctl::common' do
36
+ let(:params) { { :test_param => "yes" } }
37
+
38
+ it { should create_class("sysctl::common")\
39
+ .with_test_param("yes") }
40
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sysctl::before' do
4
+ let(:title) { 'sysctl::before' }
5
+ let(:params) { { :value => "title" } }
6
+
7
+ it "Should raise an error about needing the sysctl::common class" do
8
+ expect { should create_notify("message-title")\
9
+ .with_message("This should print if the class is here first.") }\
10
+ .to raise_error(Puppet::Error, /Could not find resource 'Class\[Sysctl::Common\]/)
11
+ end
12
+ end
13
+
14
+ describe 'sysctl::before' do
15
+ let(:title) { 'test define' }
16
+ let(:pre_condition) { 'class {"sysctl::common":}' }
17
+ let(:params) { { :value => "title" } }
18
+
19
+ it { should create_resource("sysctl::before", 'test define')\
20
+ .with_param(:value, "title") }
21
+
22
+ it { should include_class("sysctl::common") }
23
+
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sysctl' do
4
+ let(:title) { 'vm.swappiness' }
5
+ let(:params) { {:value => '60'} }
6
+
7
+ it { should include_class('sysctl::common') }
8
+ it { should create_augeas('sysctl/vm.swappiness') \
9
+ .with_context('/files/etc/sysctl.conf') \
10
+ .with_changes("set vm.swappiness '60'") \
11
+ .with_onlyif("match vm.swappiness[.='60'] size == 0") \
12
+ .with_notify('Exec[sysctl/reload]')\
13
+ .without_foo }
14
+ end
@@ -0,0 +1,7 @@
1
+ node default {
2
+ notify { 'test': }
3
+ }
4
+
5
+ node /testhost/ {
6
+ include sysctl::common
7
+ }
@@ -0,0 +1,12 @@
1
+ class boolean($bool) {
2
+ $real_bool = $bool ? {
3
+ true => false,
4
+ false => true,
5
+ }
6
+
7
+ if ($real_bool) {
8
+ notify {"bool testing":
9
+ message => "This will print when \$bool is false."
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,39 @@
1
+ class sysctl::common ($test_param = 'yes') {
2
+ exec { 'sysctl/reload':
3
+ command => '/sbin/sysctl -p /etc/sysctl.conf',
4
+ refreshonly => true,
5
+ returns => [0, 2],
6
+ }
7
+ }
8
+
9
+ define sysctl($value) {
10
+ include sysctl::common
11
+
12
+ augeas { "sysctl/${name}":
13
+ context => '/files/etc/sysctl.conf',
14
+ changes => "set ${name} '${value}'",
15
+ onlyif => "match ${name}[.='${value}'] size == 0",
16
+ notify => Exec['sysctl/reload'],
17
+ }
18
+ }
19
+
20
+ class boolean($bool) {
21
+ $real_bool = $bool ? {
22
+ true => false,
23
+ false => true,
24
+ }
25
+
26
+ if ($real_bool) {
27
+ notify {"bool testing":
28
+ message => "This will print when \$bool is false."
29
+ }
30
+ }
31
+ }
32
+
33
+ define sysctl::before($value) {
34
+ Class['sysctl::common'] -> Sysctl::Before[$name]
35
+
36
+ notify {"message-${name}":
37
+ message => "This should print if the class is here first."
38
+ }
39
+ }
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'split' do
4
+ it { should run.with_params('aoeu', 'o').and_return(['a', 'eu']) }
5
+ it { should run.with_params('foo').and_raise_error(Puppet::ParseError) }
6
+ it { should_not run.with_params('foo').and_raise_error(Puppet::DevError) }
7
+
8
+ it 'something' do
9
+ if Integer(Puppet.version.split('.').first) >= 3
10
+ expected_error = ArgumentError
11
+ else
12
+ expected_error = Puppet::ParseError
13
+ end
14
+
15
+ expect { subject.call('foo') }.to raise_error(expected_error)
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'foo.example.com' do
4
+ it { should_not include_class('sysctl::common') }
5
+ it { should contain_notify('test') }
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'testhost' do
4
+ it { should include_class('sysctl::common') }
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec-puppet'
2
+
3
+ RSpec.configure do |c|
4
+ c.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules')
5
+ c.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests')
6
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-puppet-maestrodev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Sharpe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70235609484660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70235609484660
25
+ description: RSpec tests for your Puppet manifests
26
+ email: tim@sharpe.id.au
27
+ executables:
28
+ - rspec-puppet-init
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - bin/rspec-puppet-init
33
+ - lib/rspec-puppet/example/class_example_group.rb
34
+ - lib/rspec-puppet/example/define_example_group.rb
35
+ - lib/rspec-puppet/example/function_example_group.rb
36
+ - lib/rspec-puppet/example/host_example_group.rb
37
+ - lib/rspec-puppet/example.rb
38
+ - lib/rspec-puppet/matchers/create_generic.rb
39
+ - lib/rspec-puppet/matchers/create_resource.rb
40
+ - lib/rspec-puppet/matchers/include_class.rb
41
+ - lib/rspec-puppet/matchers/run.rb
42
+ - lib/rspec-puppet/matchers.rb
43
+ - lib/rspec-puppet/setup.rb
44
+ - lib/rspec-puppet/support.rb
45
+ - lib/rspec-puppet.rb
46
+ - LICENSE
47
+ - Rakefile
48
+ - README.md
49
+ - rspec-puppet.gemspec
50
+ - spec/classes/boolean_regexp_spec.rb
51
+ - spec/classes/boolean_spec.rb
52
+ - spec/classes/sysctl_common_spec.rb
53
+ - spec/defines/sysctl_before_spec.rb
54
+ - spec/defines/sysctl_spec.rb
55
+ - spec/hosts/foo_spec.rb
56
+ - spec/hosts/testhost_spec.rb
57
+ - spec/fixtures/manifests/site.pp
58
+ - spec/fixtures/modules/boolean/manifests/init.pp
59
+ - spec/fixtures/modules/sysctl/manifests/init.pp
60
+ - spec/functions/split_spec.rb
61
+ - spec/spec_helper.rb
62
+ homepage: https://github.com/rodjek/rspec-puppet/
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.9
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: RSpec tests for your Puppet manifests
86
+ test_files: []