rspec-system-puppet 0.3.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +161 -1
  2. data/rspec-system-puppet.gemspec +2 -2
  3. metadata +7 -7
data/README.md CHANGED
@@ -1,3 +1,163 @@
1
1
  # rspec-system-puppet
2
2
 
3
- `rspec-system-puppet` is a Puppet plugin for [rspec-system](https://rubygems.org/gems/rspec-system).
3
+ `rspec-system-puppet` is a Puppet plugin for [rspec-system](https://rubygems.org/gems/rspec-system). The goal here is to provide a series of helpers for performing proper system tests on Puppet related modules such as:
4
+
5
+ * Pure Puppet DSL content, classes and defined resources
6
+ * Ruby based plugins: facts, functions, faces, types and providers
7
+
8
+ ## Relation to rspec-puppet
9
+
10
+ While unit testing using [rspec-puppet](https://rubygems.org/gems/rspec-puppet) is extremely useful for testing your content based on comparing input of parameters, facts etc. with the desired catalog output, it doesn't however do a real test. This library is meant to augment the rspec-puppet test suite, and is designed specifically to work with it. In fact I suggest running both these tests in parallel with rspec-puppet, as rspec-puppet is always going to execute basic tests faster - especially tests that don't need a real run like comparing template output with desired output, or fine-detailed items like expected property values and logical blocks.
11
+
12
+ ## Quick Start
13
+
14
+ Recommended to be installed first:
15
+
16
+ * Vagrant 1.1.5 or greater
17
+ * VirtualBox 4.2.10 or greater
18
+ * RVM or RBenv (current instructions are based on RVM however)
19
+
20
+ In your existing Puppet module project, create a `.nodeset.yml` with the following contents:
21
+
22
+ ---
23
+ default_set: 'centos-64-x64'
24
+ sets:
25
+ 'centos-59-x64':
26
+ nodes:
27
+ "main.foo.vm":
28
+ prefab: 'centos-59-x64'
29
+ 'centos-64-x64':
30
+ nodes:
31
+ "main.foo.vm":
32
+ prefab: 'centos-64-x64'
33
+ 'fedora-18-x64':
34
+ nodes:
35
+ "main.foo.vm":
36
+ prefab: 'fedora-18-x64'
37
+ 'debian-607-x64':
38
+ nodes:
39
+ "main.foo.vm":
40
+ prefab: 'debian-607-x64'
41
+ 'debian-70rc1-x64':
42
+ nodes:
43
+ "main.foo.vm":
44
+ prefab: 'debian-70rc1-x64'
45
+ 'ubuntu-server-10044-x64':
46
+ nodes:
47
+ "main.foo.vm":
48
+ prefab: 'ubuntu-server-10044-x64'
49
+ 'ubuntu-server-12042-x64':
50
+ nodes:
51
+ "main.foo.vm":
52
+ prefab: 'ubuntu-server-12042-x64'
53
+
54
+ Make sure you have a `Gemfile` like the one below, this includes `rspec-puppet` test content as well:
55
+
56
+ source 'https://rubygems.org'
57
+
58
+ group :development, :test do
59
+ gem 'rake'
60
+ gem 'puppetlabs_spec_helper', :require => false
61
+ gem 'rspec-system-puppet', '~>0.3.1'
62
+ gem 'puppet-lint', '~> 0.3.2'
63
+ end
64
+
65
+ if puppetversion = ENV['PUPPET_GEM_VERSION']
66
+ gem 'puppet', puppetversion, :require => false
67
+ else
68
+ gem 'puppet', :require => false
69
+ end
70
+
71
+ Create a `Rakefile` like so:
72
+
73
+ require 'rubygems'
74
+ require 'bundler/setup'
75
+
76
+ Bundler.require :default
77
+
78
+ require 'rspec/core/rake_task'
79
+ require 'puppetlabs_spec_helper/rake_tasks'
80
+ require 'rspec-system/rake_task'
81
+
82
+ task :default do
83
+ sh %{rake -T}
84
+ end
85
+
86
+ You will need a spec helper for your tests to `require`. So create the file `spec/spec_helper_system.rb`:
87
+
88
+ require 'rspec-system/spec_helper'
89
+ require 'rspec-system-puppet/helpers'
90
+
91
+ RSpec.configure do |c|
92
+ # Project root for the firewall code
93
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
94
+
95
+ # Enable colour in Jenkins
96
+ c.tty = true
97
+
98
+ # This is where we 'setup' the nodes before running our tests
99
+ c.system_setup_block = proc do
100
+ # TODO: find a better way of importing this into this namespace
101
+ include RSpecSystemPuppet::Helpers
102
+
103
+ # Install puppet
104
+ puppet_install
105
+ puppet_master_install
106
+
107
+ # Replace mymodule with your module name
108
+ puppet_module_install(:source => proj_root, :module_name => 'mymodule')
109
+ end
110
+ end
111
+
112
+ Now if you are using rspec-puppet, I advise you to seperate the location of your system and unit tests:
113
+
114
+ * spec/system - system tests
115
+ * spec/unit - rspec-puppet and other unit tests
116
+
117
+ And create your first system tests in say `spec/system/basic_spec.rb` (make sure it has the _spec.rb suffix!):
118
+
119
+ require 'spec_helper_system'
120
+ describe 'basic tests:' do
121
+ # Here we create the var 'pp' to be later tested
122
+ let(pp) do
123
+ pp = <<-EOS
124
+ class { 'mymodule': }
125
+ EOS
126
+ end
127
+
128
+ it 'my class should work with no errors' do
129
+ # Run it once and make sure it doesn't bail with errors
130
+ puppet_apply(pp) do |r|
131
+ r[:exit_code].should_not eq(1)
132
+ end
133
+ end
134
+
135
+ it 'my class should be idempotent' do
136
+ # Run it again and make sure no changes occurred this time, proving idempotency
137
+ puppet_apply(pp) do |r|
138
+ r[:exit_code].should == 0
139
+ end
140
+ end
141
+ end
142
+
143
+ Now start by creating a gemset environment for your run:
144
+
145
+ # rvm --create --ruby-version use ruby-1.9.3@mymodule
146
+
147
+ Then grab the gemset bundle:
148
+
149
+ # bundle update
150
+
151
+ Now you should be able to do:
152
+
153
+ # rake spec:system
154
+
155
+ ## Further Information
156
+
157
+ * [API Documentation](http://rubydoc.info/gems/rspec-system-puppet/) - this provides the Ruby API docs for the Puppet Helpers. In particular look at the [Helpers](http://rubydoc.info/gems/rspec-system-puppet/RSpecSystemPuppet/Helpers) sub-class.
158
+ * [rspec-system docs](http://rubydoc.info/gems/rspec-system) - This is the main library rspec-system-puppet utilises, and should provide more in-depth instructions on doing more complex stuff than what this gem alone provides.
159
+ * [puppetlabs-firewall](http://github.com/puppetlabs/puppetlabs-firewall) - If you want to see the library in action this module is the primary guinea pig for rspec-system-puppet and should give you some ideas on writing tests of your own. Look under `spec/system` for the tests.
160
+
161
+ ## CI Integration
162
+
163
+ For now consult the documentation for [rspec-system](http://rubygems.org/gems/rspec-system) for more details.
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system-puppet"
5
- s.version = "0.3.4"
5
+ s.version = "1.0.0"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["ken@bob.sh"]
8
8
  s.homepage = "https://github.com/kbarber/rspec-system-puppet"
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
 
17
17
  # Dependencies
18
18
  s.required_ruby_version = '>= 1.8.7'
19
- s.add_runtime_dependency "rspec-system", '~> 0.3.0'
19
+ s.add_runtime_dependency "rspec-system", '~> 1.0.0'
20
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-system-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 3
9
- - 4
10
- version: 0.3.4
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Barber
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 19
28
+ hash: 23
29
29
  segments:
30
+ - 1
30
31
  - 0
31
- - 3
32
32
  - 0
33
- version: 0.3.0
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  description: