puppet-retrospec 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +281 -49
- data/VERSION +1 -1
- data/lib/retrospec/helpers.rb +8 -11
- data/lib/retrospec/puppet_module.rb +10 -2
- data/lib/retrospec/templates/acceptance_spec_test.erb +1 -1
- data/lib/retrospec/templates/{fixtures_file.erb → module_files/.fixtures.yml} +0 -0
- data/lib/retrospec/templates/module_files/.gitignore.erb +8 -0
- data/lib/retrospec/templates/{travis.yml.erb → module_files/.travis.yml} +0 -0
- data/lib/retrospec/templates/module_files/Gemfile +29 -0
- data/lib/retrospec/templates/{rakefile.erb → module_files/Rakefile} +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-59-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-64-x64-pe.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-64-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-66-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-607-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-70rc1-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-73-i386.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-73-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/default.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/fedora-18-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/sles-11sp1-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/ubuntu-server-10044-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/ubuntu-server-12042-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/ubuntu-server-1310-x64.yml +0 -0
- data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/ubuntu-server-1404-x64.yml +0 -0
- data/lib/retrospec/templates/{shared_context.erb → module_files/spec/shared_contexts.rb} +2 -1
- data/lib/retrospec/templates/{spec_helper_file.erb → module_files/spec/spec_helper.rb} +1 -1
- data/lib/retrospec/templates/{spec_helper_acceptance.rb.erb → module_files/spec/spec_helper_acceptance.rb} +0 -0
- data/lib/retrospec/templates/resource_spec_file.erb +1 -1
- data/lib/retrospec.rb +25 -49
- data/puppet-retrospec.gemspec +28 -26
- data/spec/unit/puppet-retrospec_spec.rb +60 -41
- metadata +54 -52
- data/lib/retrospec/templates/gemfile.erb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b8a2d188fa0d01a182d58443a8ff7c109e67228
|
4
|
+
data.tar.gz: 2e63276ab8d5b814a386615df85233191d9af9f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4bab8bfad24ac10fc8b362e4ca7445075912d876d2bb9e2b2147f1f1e91ae44a65ac8cf50c3324766f30c5e9c39cebf7a4de1c5a2e4570c8d6a2daf03d77922
|
7
|
+
data.tar.gz: 34a74fce6aa0cdb20acf9088e6c843076d209c813413eee0813566a4fa89ffa2458f8dcb11f477c984ae5651d1902699bc97e80d8ceea1f616c3caedc8f7660b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 0.6.1
|
2
|
+
* gh-12 - allow new templates to be easily added without changing code
|
3
|
+
* gh-8 - tests are not created when manifest is invalid
|
4
|
+
* updated README based on apache example
|
5
|
+
* updated templates to fix minor errors
|
6
|
+
|
7
|
+
## 0.6.0
|
8
|
+
Initial release that was deemed worthy.
|
9
|
+
|
10
|
+
|
data/README.md
CHANGED
@@ -3,12 +3,32 @@ Puppet-Retrospec
|
|
3
3
|
|
4
4
|
Generates puppet rspec test code based on the classes and defines inside the manifests directory. Aims to reduce some of the boilerplate coding with default test patterns.
|
5
5
|
|
6
|
-
Retrospec makes it dead simple to get started with puppet unit testing. When you run retrospec will scan you puppet manifests
|
6
|
+
Retrospec makes it dead simple to get started with puppet unit testing. When you run retrospec, retrospec will scan you puppet manifests
|
7
7
|
and actually write some very basic rspec-puppet test code. Thus this gem will retrofit your existing puppet module
|
8
8
|
with everything needed to get going with puppet unit testing.
|
9
9
|
|
10
10
|
The project was named retrospec because there are many times when you need to retrofit your module with spec tests.
|
11
11
|
|
12
|
+
Table of Contents
|
13
|
+
=================
|
14
|
+
|
15
|
+
* [Build Status](#build-status)
|
16
|
+
* [Install](#install)
|
17
|
+
* [How to use](#how-to-use)
|
18
|
+
* [Example](#example)
|
19
|
+
* [About the test suite](#about-the-test-suite)
|
20
|
+
* [How Does it do this](#how-does-it-do-this)
|
21
|
+
* [Overriding the templates](#overriding-the-templates)
|
22
|
+
* [Adding New Templates](#adding-new-templates)
|
23
|
+
* [Beaker Testing](#beaker-testing)
|
24
|
+
* [Troubleshooting](#troubleshooting)
|
25
|
+
* [Running Tests](#running-tests)
|
26
|
+
* [Understanding Variable Resolution](#understanding-variable-resolution)
|
27
|
+
* [Todo](#todo)
|
28
|
+
* [Support](#support)
|
29
|
+
|
30
|
+
Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
31
|
+
|
12
32
|
Build Status
|
13
33
|
============
|
14
34
|
[![Build Status](https://travis-ci.org/logicminds/puppet-retrospec.png)](https://travis-ci.org/logicminds/puppet-retrospec)
|
@@ -37,51 +57,101 @@ Example
|
|
37
57
|
======================
|
38
58
|
|
39
59
|
Below you can see that it creates files for every resource in the tomcat module in addition to other files
|
40
|
-
that you need for unit testing puppet code.
|
60
|
+
that you need for unit testing puppet code. Rspec-puppet best practices says to put definitions in a defines folder
|
61
|
+
and classes in a classes folder since it infers what kind of resource it is based on this convention. Retrospec sets up
|
62
|
+
this scaffolding for you.
|
41
63
|
|
42
64
|
```shell
|
43
|
-
$ ls
|
44
|
-
CHANGELOG.md CONTRIBUTING.md LICENSE README.md Rakefile checksums.json examples manifests metadata.json
|
45
65
|
$ pwd
|
46
|
-
/Users/cosman/
|
66
|
+
/Users/cosman/github/puppetlabs-apache
|
47
67
|
$ retrospec
|
48
|
-
+ /Users/cosman/
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
+ /Users/cosman/github/puppetlabs-apache/Gemfile
|
69
|
+
+ /Users/cosman/github/puppetlabs-apache/Rakefile
|
70
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/
|
71
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/shared_contexts.rb
|
72
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/spec_helper.rb
|
73
|
+
+ /Users/cosman/github/puppetlabs-apache/.fixtures.yml
|
74
|
+
+ /Users/cosman/github/puppetlabs-apache/.gitignore
|
75
|
+
+ /Users/cosman/github/puppetlabs-apache/.travis.yml
|
76
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/
|
77
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/default_mods_spec.rb
|
78
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/dev_spec.rb
|
79
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/apache_spec.rb
|
80
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/
|
81
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/alias_spec.rb
|
82
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/auth_basic_spec.rb
|
83
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/auth_kerb_spec.rb
|
84
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/autoindex_spec.rb
|
85
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cache_spec.rb
|
86
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cgi_spec.rb
|
87
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cgid_spec.rb
|
88
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_spec.rb
|
89
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_fs_spec.rb
|
90
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_svn_spec.rb
|
91
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/deflate_spec.rb
|
92
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dev_spec.rb
|
93
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dir_spec.rb
|
94
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/disk_cache_spec.rb
|
95
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/fcgid_spec.rb
|
96
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/headers_spec.rb
|
97
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/info_spec.rb
|
98
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/itk_spec.rb
|
99
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/ldap_spec.rb
|
100
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mime_spec.rb
|
101
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mime_magic_spec.rb
|
102
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mpm_event_spec.rb
|
103
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/negotiation_spec.rb
|
104
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/passenger_spec.rb
|
105
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/perl_spec.rb
|
106
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/php_spec.rb
|
107
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/prefork_spec.rb
|
108
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_spec.rb
|
109
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_balancer_spec.rb
|
110
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_html_spec.rb
|
111
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_http_spec.rb
|
112
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/python_spec.rb
|
113
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/reqtimeout_spec.rb
|
114
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/rewrite_spec.rb
|
115
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/setenvif_spec.rb
|
116
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/ssl_spec.rb
|
117
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/status_spec.rb
|
118
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/suphp_spec.rb
|
119
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/userdir_spec.rb
|
120
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/vhost_alias_spec.rb
|
121
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/worker_spec.rb
|
122
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/wsgi_spec.rb
|
123
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/xsendfile_spec.rb
|
124
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/params_spec.rb
|
125
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/php_spec.rb
|
126
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/proxy_spec.rb
|
127
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/python_spec.rb
|
128
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/service_spec.rb
|
129
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/classes/ssl_spec.rb
|
130
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/
|
131
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/balancer_spec.rb
|
132
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/balancermember_spec.rb
|
133
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/default_mods/
|
134
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/default_mods/load_spec.rb
|
135
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/listen_spec.rb
|
136
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/mod_spec.rb
|
137
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/namevirtualhost_spec.rb
|
138
|
+
+ /Users/cosman/github/puppetlabs-apache/spec/defines/vhost_spec.rb
|
71
139
|
|
72
140
|
```
|
73
141
|
|
74
|
-
Looking at the file we can see that it did a lot of work for us. Retrospec generate
|
142
|
+
Looking at the file we can see that it did a lot of work for us. Retrospec generate many tests automatically.
|
75
143
|
However the variable resolution isn't perfect so you will need to manually resolve some variables. This doesn't produce
|
76
|
-
100% coverage but all you did was
|
77
|
-
Below is the
|
144
|
+
100% coverage but all you did was pressed enter to produce all this anyways.
|
145
|
+
Below is the classes/apache_spec.rb file. Notice that while Retrospec created all these files, you still need to do more work.
|
146
|
+
Retrospec is only here to setup your module for testing, which might save you several hours each time you create a module.
|
147
|
+
|
78
148
|
|
79
149
|
```ruby
|
80
150
|
require 'spec_helper'
|
81
151
|
require 'shared_contexts'
|
82
152
|
|
83
|
-
describe '
|
84
|
-
# by default the hiera integration uses
|
153
|
+
describe 'apache' do
|
154
|
+
# by default the hiera integration uses hiera data from the shared_contexts.rb file
|
85
155
|
# but basically to mock hiera you first need to add a key/value pair
|
86
156
|
# to the specific context in the spec/shared_contexts.rb file
|
87
157
|
# Note: you can only use a single hiera context per describe/context block
|
@@ -100,32 +170,148 @@ describe 'tomcat' do
|
|
100
170
|
# while all required parameters will require you to add a value
|
101
171
|
let(:params) do
|
102
172
|
{
|
103
|
-
#:
|
104
|
-
#:
|
105
|
-
#:
|
106
|
-
#:
|
107
|
-
#:
|
108
|
-
#:
|
109
|
-
#:
|
173
|
+
#:default_mods => true,
|
174
|
+
#:default_vhost => true,
|
175
|
+
#:default_ssl_vhost => false,
|
176
|
+
#:default_ssl_cert => $apache::params::default_ssl_cert,
|
177
|
+
#:default_ssl_key => $apache::params::default_ssl_key,
|
178
|
+
#:default_ssl_chain => undef,
|
179
|
+
#:default_ssl_ca => undef,
|
180
|
+
#:default_ssl_crl_path => undef,
|
181
|
+
#:default_ssl_crl => undef,
|
182
|
+
#:service_enable => true,
|
183
|
+
#:purge_configs => true,
|
184
|
+
#:purge_vdir => false,
|
185
|
+
#:serveradmin => "root@localhost",
|
186
|
+
#:sendfile => false,
|
187
|
+
#:error_documents => false,
|
188
|
+
#:httpd_dir => $apache::params::httpd_dir,
|
189
|
+
#:confd_dir => $apache::params::confd_dir,
|
190
|
+
#:vhost_dir => $apache::params::vhost_dir,
|
191
|
+
#:vhost_enable_dir => $apache::params::vhost_enable_dir,
|
192
|
+
#:mod_dir => $apache::params::mod_dir,
|
193
|
+
#:mod_enable_dir => $apache::params::mod_enable_dir,
|
194
|
+
#:mpm_module => $apache::params::mpm_module,
|
195
|
+
#:conf_template => $apache::params::conf_template,
|
196
|
+
#:servername => $apache::params::servername,
|
197
|
+
#:user => $apache::params::user,
|
198
|
+
#:group => $apache::params::group,
|
199
|
+
#:keepalive => $apache::params::keepalive,
|
200
|
+
#:keepalive_timeout => $apache::params::keepalive_timeout,
|
201
|
+
#:logroot => $apache::params::logroot,
|
202
|
+
#:ports_file => $apache::params::ports_file,
|
203
|
+
#:server_tokens => "OS",
|
204
|
+
#:server_signature => "On",
|
110
205
|
}
|
111
206
|
end
|
112
207
|
# add these two lines in a single test block to enable puppet and hiera debug mode
|
113
208
|
# Puppet::Util::Log.level = :debug
|
114
209
|
# Puppet::Util::Log.newdestination(:console)
|
115
210
|
it do
|
116
|
-
|
117
|
-
with({"ensure"=>"
|
118
|
-
"
|
119
|
-
"
|
211
|
+
is_expected.to contain_package('httpd').
|
212
|
+
with({"ensure"=>"installed",
|
213
|
+
"name"=>"$apache::params::apache_name",
|
214
|
+
"notify"=>"Class[Apache::Service]"})
|
120
215
|
end
|
121
216
|
it do
|
122
|
-
|
217
|
+
is_expected.to contain_group('$apache::params::group').
|
123
218
|
with({"ensure"=>"present",
|
124
|
-
"
|
219
|
+
"require"=>"Package[httpd]"})
|
220
|
+
end
|
221
|
+
it do
|
222
|
+
is_expected.to contain_user('$apache::params::user').
|
223
|
+
with({"ensure"=>"present",
|
224
|
+
"gid"=>"$apache::params::group",
|
225
|
+
"require"=>"Package[httpd]"})
|
226
|
+
end
|
227
|
+
it do
|
228
|
+
is_expected.to contain_class('apache::service').
|
229
|
+
with({"service_enable"=>"true"})
|
230
|
+
end
|
231
|
+
it do
|
232
|
+
is_expected.to contain_exec('mkdir $apache::params::confd_dir').
|
233
|
+
with({"creates"=>"$apache::params::confd_dir",
|
234
|
+
"require"=>"Package[httpd]"})
|
235
|
+
end
|
236
|
+
it do
|
237
|
+
is_expected.to contain_file('$apache::params::confd_dir').
|
238
|
+
with({"ensure"=>"directory",
|
239
|
+
"recurse"=>"true",
|
240
|
+
"purge"=>"$purge_confd",
|
241
|
+
"notify"=>"Class[Apache::Service]",
|
242
|
+
"require"=>"Package[httpd]"})
|
243
|
+
end
|
244
|
+
it do
|
245
|
+
is_expected.to contain_concat('$apache::params::ports_file').
|
246
|
+
with({"owner"=>"root",
|
247
|
+
"group"=>"root",
|
248
|
+
"mode"=>"0644",
|
249
|
+
"notify"=>"Class[Apache::Service]",
|
250
|
+
"require"=>"Package[httpd]"})
|
251
|
+
end
|
252
|
+
it do
|
253
|
+
is_expected.to contain_concat__fragment('Apache ports header').
|
254
|
+
with({"target"=>"$apache::params::ports_file",
|
255
|
+
"content"=>"template(apache/ports_header.erb)"})
|
256
|
+
end
|
257
|
+
it do
|
258
|
+
is_expected.to contain_exec('mkdir $apache::params::mod_dir').
|
259
|
+
with({"creates"=>"$apache::params::mod_dir",
|
260
|
+
"require"=>"Package[httpd]"})
|
261
|
+
end
|
262
|
+
it do
|
263
|
+
is_expected.to contain_file('$apache::params::mod_dir').
|
264
|
+
with({"ensure"=>"directory",
|
265
|
+
"recurse"=>"true",
|
266
|
+
"purge"=>"true",
|
267
|
+
"notify"=>"Class[Apache::Service]",
|
268
|
+
"require"=>"Package[httpd]"})
|
269
|
+
end
|
270
|
+
it do
|
271
|
+
is_expected.to contain_exec('mkdir $apache::params::mod_enable_dir').
|
272
|
+
with({"creates"=>"$apache::params::mod_enable_dir",
|
273
|
+
"require"=>"Package[httpd]"})
|
274
|
+
end
|
275
|
+
it do
|
276
|
+
is_expected.to contain_file('$apache::params::mod_enable_dir').
|
277
|
+
with({"ensure"=>"directory",
|
278
|
+
"recurse"=>"true",
|
279
|
+
"purge"=>"true",
|
280
|
+
"notify"=>"Class[Apache::Service]",
|
281
|
+
"require"=>"Package[httpd]"})
|
282
|
+
end
|
283
|
+
it do
|
284
|
+
is_expected.to contain_exec('mkdir $apache::params::vhost_dir').
|
285
|
+
with({"creates"=>"$apache::params::vhost_dir",
|
286
|
+
"require"=>"Package[httpd]"})
|
287
|
+
end
|
288
|
+
it do
|
289
|
+
is_expected.to contain_file('$apache::params::vhost_dir').
|
290
|
+
with({"ensure"=>"directory",
|
291
|
+
"recurse"=>"true",
|
292
|
+
"purge"=>"true",
|
293
|
+
"notify"=>"Class[Apache::Service]",
|
294
|
+
"require"=>"Package[httpd]"})
|
295
|
+
end
|
296
|
+
it do
|
297
|
+
is_expected.to contain_exec('mkdir $vhost_load_dir').
|
298
|
+
with({"creates"=>"$vhost_load_dir",
|
299
|
+
"require"=>"Package[httpd]"})
|
300
|
+
end
|
301
|
+
it do
|
302
|
+
is_expected.to contain_file('$apache::params::vhost_enable_dir').
|
303
|
+
with({"ensure"=>"directory",
|
304
|
+
"recurse"=>"true",
|
305
|
+
"purge"=>"true",
|
306
|
+
"notify"=>"Class[Apache::Service]",
|
307
|
+
"require"=>"Package[httpd]"})
|
125
308
|
end
|
126
309
|
it do
|
127
|
-
|
128
|
-
with({"ensure"=>"
|
310
|
+
is_expected.to contain_file('$apache::params::conf_dir/$apache::params::conf_file').
|
311
|
+
with({"ensure"=>"file",
|
312
|
+
"content"=>"template($conf_template)",
|
313
|
+
"notify"=>"Class[Apache::Service]",
|
314
|
+
"require"=>"Package[httpd]"})
|
129
315
|
end
|
130
316
|
end
|
131
317
|
|
@@ -182,7 +368,7 @@ template option when running retrospec.
|
|
182
368
|
|
183
369
|
Setting the `--enable-user-templates` option will tell retrospec to use the default user template location.
|
184
370
|
|
185
|
-
The default location for the templates when using this variable is ~/.puppet_retrospec_templates
|
371
|
+
The default user location for the templates when using this variable is ~/.puppet_retrospec_templates
|
186
372
|
|
187
373
|
If you wish to override ~/.puppet_retrospec_templates location you can use the following option
|
188
374
|
`--template-dir`
|
@@ -192,6 +378,37 @@ If you set the `--template-dir` option you are not required to set the set `--en
|
|
192
378
|
Example:
|
193
379
|
`--template-dir=~/my_templates`
|
194
380
|
|
381
|
+
Adding New Templates
|
382
|
+
======================
|
383
|
+
Should you ever need to add new templates or normal files of any kind retrospec will automatically render and copy the template file
|
384
|
+
to the module path if you place a file inside the templates/module_files directory. The cool thing about this feature
|
385
|
+
is that retrospec will recursively create the same directory structure you make inside the module_files directory inside your
|
386
|
+
module. Files do not need to end in .erb will still be rendered as a erb template.
|
387
|
+
|
388
|
+
This follows the convention over configuration pattern so no directory name or filename is required when running retrospec.
|
389
|
+
Just put the template file in the directory where you want it (under module_files) and name it exactly how you want it to appear in the module and retrospec
|
390
|
+
will take care of the rest. Please note that any file ending in .erb will have this extension automatically removed.
|
391
|
+
|
392
|
+
Example:
|
393
|
+
|
394
|
+
```shell
|
395
|
+
templates/
|
396
|
+
├── acceptance_spec_test.erb
|
397
|
+
├── module_files
|
398
|
+
│ ├── Gemfile
|
399
|
+
│ ├── Rakefile
|
400
|
+
│ └── spec
|
401
|
+
│ ├── acceptance
|
402
|
+
│ │ └── nodesets
|
403
|
+
│ │ ├── centos-59-x64.yml
|
404
|
+
│ │ ├── centos-64-x64-pe.yml
|
405
|
+
│ │ └── ubuntu-server-1404-x64.yml
|
406
|
+
│ ├── shared_contexts.rb
|
407
|
+
│ ├── spec_helper.rb
|
408
|
+
│ └── spec_helper_acceptance.rb
|
409
|
+
└── resource_spec_file.erb
|
410
|
+
```
|
411
|
+
|
195
412
|
Beaker Testing
|
196
413
|
=================
|
197
414
|
Beaker is Puppetlabs acceptance testing framework that you use to test puppet code on real machines. Beaker is fairly new
|
@@ -203,6 +420,9 @@ acceptance tests are not created. However at a later time they will be enabled
|
|
203
420
|
|
204
421
|
`--enable-beaker-tests`
|
205
422
|
|
423
|
+
I am no expert in Beaker so if you see an issue with the templates, acceptance_spec_helper or other workflow, please issue
|
424
|
+
a PR.
|
425
|
+
|
206
426
|
Troubleshooting
|
207
427
|
===============
|
208
428
|
If you see the following, this error means that you need to add a fixture to the fixtures file.
|
@@ -219,6 +439,18 @@ See [fixtures doc](https://github.com/puppetlabs/puppetlabs_spec_helper#using-fi
|
|
219
439
|
# ./spec/defines/instance/source_spec.rb:34:in `block (2 levels) in <top (required)>'
|
220
440
|
```
|
221
441
|
|
442
|
+
If you see something like the following, this means your current module is using a much older version of Rspec. Retrospec
|
443
|
+
using Rspec 3 syntax so you need to update your rspec version. If you have tests that using older rspec syntax, take a look
|
444
|
+
at [transpec](https://github.com/yujinakayama/transpec)
|
445
|
+
|
446
|
+
```shell
|
447
|
+
103) apache::vhost
|
448
|
+
Failure/Error: is_expected.to contain_file('').
|
449
|
+
NameError:
|
450
|
+
undefined local variable or method `is_expected' for #<RSpec::Core::ExampleGroup::Nested_59:0x007ff9eaab75e8>
|
451
|
+
# ./spec/defines/vhost_spec.rb:103:in `block (2 levels) in <top (required)>'
|
452
|
+
|
453
|
+
```
|
222
454
|
Running Tests
|
223
455
|
=============
|
224
456
|
Puppet-retrospec tests its code against real modules downloaded directly from puppet forge.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/lib/retrospec/helpers.rb
CHANGED
@@ -80,10 +80,6 @@ class Helpers
|
|
80
80
|
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
83
|
def self.safe_copy_file(src, dest)
|
88
84
|
if File.exists?(dest) and not File.zero?(dest)
|
89
85
|
$stderr.puts "!! #{dest} already exists"
|
@@ -109,18 +105,19 @@ class Helpers
|
|
109
105
|
end
|
110
106
|
end
|
111
107
|
|
112
|
-
def self.safe_create_file(
|
113
|
-
if File.exists?
|
114
|
-
old_content = File.read(
|
108
|
+
def self.safe_create_file(filepath, content)
|
109
|
+
if File.exists? filepath
|
110
|
+
old_content = File.read(filepath)
|
115
111
|
# if we did a better comparison of content we could be smarter about when we create files
|
116
|
-
if old_content != content or not File.zero?(
|
117
|
-
$stderr.puts "!! #{
|
112
|
+
if old_content != content or not File.zero?(filepath)
|
113
|
+
$stderr.puts "!! #{filepath} already exists and differs from template"
|
118
114
|
end
|
119
115
|
else
|
120
|
-
File.
|
116
|
+
safe_mkdir(File.dirname(filepath)) unless File.exists? File.dirname(filepath)
|
117
|
+
File.open(filepath, 'w') do |f|
|
121
118
|
f.puts content
|
122
119
|
end
|
123
|
-
puts " + #{
|
120
|
+
puts " + #{filepath}"
|
124
121
|
end
|
125
122
|
end
|
126
123
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'singleton'
|
2
|
-
|
2
|
+
require 'puppet/face'
|
3
3
|
module Utilities
|
4
4
|
class PuppetModule
|
5
5
|
attr_writer :module_path
|
@@ -72,6 +72,15 @@ module Utilities
|
|
72
72
|
else
|
73
73
|
files = Dir.glob("#{manifest_dir}/**/*.pp")
|
74
74
|
warn "No puppet manifest files found at #{manifest_dir}" if files.length < 1
|
75
|
+
# validate the manifest files, because if one files doesn't work it affects everything
|
76
|
+
files.each do |file|
|
77
|
+
begin
|
78
|
+
Puppet::Face[:parser, '0.0.1'].validate(file)
|
79
|
+
rescue SystemExit => e
|
80
|
+
puts "Manifest file: #{file} has parser errors, please fix and re-check using\n puppet parser validate #{file}"
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
end
|
75
84
|
end
|
76
85
|
dir
|
77
86
|
end
|
@@ -160,4 +169,3 @@ module Utilities
|
|
160
169
|
end
|
161
170
|
end
|
162
171
|
end
|
163
|
-
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "rake"
|
5
|
+
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.3'
|
6
|
+
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
|
7
|
+
gem "puppetlabs_spec_helper"
|
8
|
+
gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
|
9
|
+
gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
|
10
|
+
<%- if enable_beaker_tests? -%>
|
11
|
+
gem "beaker", :git => 'https://github.com/puppetlabs/beaker.git'
|
12
|
+
gem "beaker-rspec", :git => 'https://github.com/puppetlabs/beaker-rspec.git'
|
13
|
+
gem "vagrant-wrapper"
|
14
|
+
gem 'serverspec'
|
15
|
+
<%- end -%>
|
16
|
+
# there seems to be a bug with puppet-blacksmith and metadata-json-lint
|
17
|
+
# removing metadata for now
|
18
|
+
gem "metadata-json-lint"
|
19
|
+
gem 'puppet-syntax'
|
20
|
+
gem 'puppet-lint'
|
21
|
+
end
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem "travis"
|
25
|
+
gem "travis-lint"
|
26
|
+
gem "puppet-blacksmith"
|
27
|
+
gem "guard-rake"
|
28
|
+
end
|
29
|
+
|
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-59-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-64-x64-pe.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-64-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/centos-66-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-607-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-70rc1-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-73-i386.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/debian-73-x64.yml
RENAMED
File without changes
|
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/fedora-18-x64.yml
RENAMED
File without changes
|
data/lib/retrospec/templates/{nodesets → module_files/spec/acceptance/nodesets}/sles-11sp1-x64.yml
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,7 +5,7 @@ require 'hiera-puppet-helper'
|
|
5
5
|
# I only assume its data, but it could be anything
|
6
6
|
hiera_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..','data', 'hiera.yaml'))
|
7
7
|
|
8
|
-
#
|
8
|
+
# hiera_config and hiera_data are mutually exclusive contexts.
|
9
9
|
|
10
10
|
shared_context :hiera do
|
11
11
|
# example only,
|
@@ -29,6 +29,7 @@ shared_context :windows_hiera do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
# you cannot use this in addition to any of the hiera_data contexts above
|
32
33
|
shared_context :real_hiera_data do
|
33
34
|
let(:hiera_config) do
|
34
35
|
hirea_config_file
|
File without changes
|