puppet-retrospec 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/retrospec.rb +4 -75
- data/lib/retrospec/module_utilities.rb +80 -0
- data/puppet-retrospec.gemspec +4 -3
- data/spec/unit/puppet-retrospec_spec.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b5058097bcc5d5c96332495e617db07cea74805
|
4
|
+
data.tar.gz: 0a8f3072a91d5f72ff391c90d920336af8daa5d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c44aa9a6c8db80d14842a06662722da2a0d35c5bc1da46b843e61a71dff7222e1d13e14af74393d008ace304c9811e8e16f4b61cb8929090cd89dc61ace9200a
|
7
|
+
data.tar.gz: db3a54af5802009798cda488a5649e47ccf8678627e3d32f5fe064a2967108e6de90107ff61f98dfd26b7d0f04839da97f8b57d8d06a5b0f2e7a13015ce6d2e9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/retrospec.rb
CHANGED
@@ -5,11 +5,12 @@ require 'fileutils'
|
|
5
5
|
require 'retrospec/resource'
|
6
6
|
require 'retrospec/conditional'
|
7
7
|
require 'retrospec/variable_store'
|
8
|
+
require 'retrospec/module_utilities'
|
8
9
|
|
9
10
|
class Retrospec
|
11
|
+
include PuppetModule::Utilities
|
12
|
+
|
10
13
|
attr_reader :module_path
|
11
|
-
attr_reader :tmp_module_path
|
12
|
-
attr_accessor :module_name
|
13
14
|
attr_reader :template_dir
|
14
15
|
|
15
16
|
# module path is the relative or absolute path to the module that should retro fitted
|
@@ -27,7 +28,7 @@ class Retrospec
|
|
27
28
|
end
|
28
29
|
@enable_beaker_tests = opts[:enable_beaker_tests]
|
29
30
|
@module_path = validate_module_dir(module_path)
|
30
|
-
|
31
|
+
create_tmp_module_path(module_path) # this is required to finish initialization
|
31
32
|
end
|
32
33
|
|
33
34
|
def enable_beaker_tests?
|
@@ -99,47 +100,6 @@ class Retrospec
|
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
102
|
-
def types
|
103
|
-
@types ||= search_module || []
|
104
|
-
end
|
105
|
-
|
106
|
-
# puts a symlink in that module directory that points back to the user supplied module path
|
107
|
-
def tmp_module_path
|
108
|
-
if @tmp_module_path.nil?
|
109
|
-
# create a link where source is the current repo and dest is /tmp/modules/module_name
|
110
|
-
path = File.join(tmp_modules_dir, module_dir_name)
|
111
|
-
FileUtils.ln_s(module_path, path)
|
112
|
-
@tmp_module_path = path
|
113
|
-
end
|
114
|
-
@tmp_module_path
|
115
|
-
end
|
116
|
-
|
117
|
-
# the directory name of the module
|
118
|
-
# usually this is the same as the module name but it can be namespaced sometimes
|
119
|
-
def module_dir_name
|
120
|
-
@module_dir_name ||= File.basename(module_path)
|
121
|
-
end
|
122
|
-
|
123
|
-
# returns the name of the module ie. mysql::config => mysql
|
124
|
-
def module_name
|
125
|
-
begin
|
126
|
-
@module_name ||= types.first.name.split('::').first
|
127
|
-
rescue
|
128
|
-
@module_name = module_dir_name
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# creates a tmp module directory so puppet can work correctly
|
133
|
-
def tmp_modules_dir
|
134
|
-
if @modules_dir.nil?
|
135
|
-
dir = Dir.mktmpdir
|
136
|
-
tmp_modules_path = File.expand_path(File.join(dir, 'modules'))
|
137
|
-
FileUtils.mkdir_p(tmp_modules_path)
|
138
|
-
@modules_dir = tmp_modules_path
|
139
|
-
end
|
140
|
-
@modules_dir
|
141
|
-
end
|
142
|
-
|
143
103
|
# Creates an associated spec file for each type and even creates the subfolders for nested classes one::two::three
|
144
104
|
def safe_create_resource_spec_files(type,template='resource_spec_file.erb')
|
145
105
|
@parameters = type.arguments
|
@@ -161,11 +121,6 @@ class Retrospec
|
|
161
121
|
file_path
|
162
122
|
end
|
163
123
|
|
164
|
-
# creates a puppet environment given a module path and environment name
|
165
|
-
def puppet_environment
|
166
|
-
@puppet_environment ||= Puppet::Node::Environment.create('production', [tmp_modules_dir])
|
167
|
-
end
|
168
|
-
|
169
124
|
# generates a file path for spec tests based on the resource name. An added option
|
170
125
|
# is to generate directory names for each parent resource as a default option
|
171
126
|
# at this time acceptance tests follow this same test directory layout until best
|
@@ -214,32 +169,6 @@ class Retrospec
|
|
214
169
|
|
215
170
|
private
|
216
171
|
|
217
|
-
# creates a puppet resource request to be used indirectly
|
218
|
-
def request(key, method)
|
219
|
-
instance = Puppet::Indirector::Indirection.instance(:resource_type)
|
220
|
-
indirection_name = 'test'
|
221
|
-
@request = Puppet::Indirector::Request.new(indirection_name, method, key, instance)
|
222
|
-
@request.environment = puppet_environment
|
223
|
-
@request
|
224
|
-
end
|
225
|
-
|
226
|
-
# creates an instance of the resource type parser
|
227
|
-
def resource_type_parser
|
228
|
-
@resource_type_parser ||= Puppet::Indirector::ResourceType::Parser.new
|
229
|
-
end
|
230
|
-
|
231
|
-
# returns the resource type ofject given a resource name ie. tomcat::connector
|
232
|
-
def find_resource(resource_name)
|
233
|
-
request = request(resource_name, 'find')
|
234
|
-
resource_type_parser.find(request)
|
235
|
-
end
|
236
|
-
|
237
|
-
# returns the resource types found in the module
|
238
|
-
def search_module(pattern='*')
|
239
|
-
request = request(pattern, 'search')
|
240
|
-
resource_type_parser.search(request)
|
241
|
-
end
|
242
|
-
|
243
172
|
# processes a directory and expands to its full path, assumes './'
|
244
173
|
# returns the validated dir
|
245
174
|
def validate_module_dir(dir)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module PuppetModule
|
2
|
+
module Utilities
|
3
|
+
|
4
|
+
# puts a symlink in that module directory that points back to the user supplied module path
|
5
|
+
def create_tmp_module_path(module_path)
|
6
|
+
path = File.join(tmp_modules_dir, module_dir_name)
|
7
|
+
unless File.exists?(path)
|
8
|
+
# create a link where source is the current repo and dest is /tmp/modules/module_name
|
9
|
+
FileUtils.ln_s(module_path, path)
|
10
|
+
end
|
11
|
+
path
|
12
|
+
end
|
13
|
+
|
14
|
+
def tmp_module_path
|
15
|
+
@tmp_module_path ||= File.join(tmp_modules_dir, module_dir_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
# the directory name of the module
|
19
|
+
# usually this is the same as the module name but it can be namespaced sometimes
|
20
|
+
def module_dir_name
|
21
|
+
@module_dir_name ||= File.basename(module_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
# returns the name of the module ie. mysql::config => mysql
|
25
|
+
def module_name
|
26
|
+
begin
|
27
|
+
@module_name ||= types.first.name.split('::').first
|
28
|
+
rescue
|
29
|
+
@module_name = module_dir_name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# creates a tmp module directory so puppet can work correctly
|
34
|
+
def tmp_modules_dir
|
35
|
+
if @tmp_modules_dir.nil?
|
36
|
+
dir = Dir.mktmpdir
|
37
|
+
tmp_path = File.expand_path(File.join(dir, 'modules'))
|
38
|
+
FileUtils.mkdir_p(tmp_path)
|
39
|
+
@tmp_modules_dir = tmp_path
|
40
|
+
end
|
41
|
+
@tmp_modules_dir
|
42
|
+
end
|
43
|
+
|
44
|
+
# creates a puppet environment given a module path and environment name
|
45
|
+
def puppet_environment
|
46
|
+
@puppet_environment ||= Puppet::Node::Environment.create('production', [tmp_modules_dir])
|
47
|
+
end
|
48
|
+
|
49
|
+
# creates a puppet resource request to be used indirectly
|
50
|
+
def request(key, method)
|
51
|
+
instance = Puppet::Indirector::Indirection.instance(:resource_type)
|
52
|
+
indirection_name = 'test'
|
53
|
+
@request = Puppet::Indirector::Request.new(indirection_name, method, key, instance)
|
54
|
+
@request.environment = puppet_environment
|
55
|
+
@request
|
56
|
+
end
|
57
|
+
|
58
|
+
# creates an instance of the resource type parser
|
59
|
+
def resource_type_parser
|
60
|
+
@resource_type_parser ||= Puppet::Indirector::ResourceType::Parser.new
|
61
|
+
end
|
62
|
+
|
63
|
+
# returns the resource type object given a resource name ie. tomcat::connector
|
64
|
+
def find_resource(resource_name)
|
65
|
+
request = request(resource_name, 'find')
|
66
|
+
resource_type_parser.find(request)
|
67
|
+
end
|
68
|
+
|
69
|
+
# returns the resource types found in the module
|
70
|
+
def search_module(pattern='*')
|
71
|
+
request = request(pattern, 'search')
|
72
|
+
resource_type_parser.search(request)
|
73
|
+
end
|
74
|
+
|
75
|
+
# TODO we need to parse the types and find all the types that inherit other types and then order them so we can load the files first
|
76
|
+
def types
|
77
|
+
@types ||= search_module || []
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/puppet-retrospec.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: puppet-retrospec 0.5.
|
5
|
+
# stub: puppet-retrospec 0.5.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "puppet-retrospec"
|
9
|
-
s.version = "0.5.
|
9
|
+
s.version = "0.5.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Corey Osman"]
|
14
|
-
s.date = "2015-02-
|
14
|
+
s.date = "2015-02-16"
|
15
15
|
s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
|
16
16
|
s.email = "corey@logicminds.biz"
|
17
17
|
s.executables = ["retrospec"]
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/retrospec.rb",
|
33
33
|
"lib/retrospec/conditional.rb",
|
34
34
|
"lib/retrospec/helpers.rb",
|
35
|
+
"lib/retrospec/module_utilities.rb",
|
35
36
|
"lib/retrospec/resource.rb",
|
36
37
|
"lib/retrospec/templates/acceptance_spec_test.erb",
|
37
38
|
"lib/retrospec/templates/fixtures_file.erb",
|
@@ -116,7 +116,7 @@ describe "puppet-retrospec" do
|
|
116
116
|
it 'should create proper spec helper file' do
|
117
117
|
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
118
118
|
filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper.rb'))
|
119
|
-
path = tomcat.
|
119
|
+
path = tomcat.create_tmp_module_path(@opts[:module_path])
|
120
120
|
tomcat.safe_create_spec_helper
|
121
121
|
expect(File.exists?(filepath)).to eq(true)
|
122
122
|
end
|
@@ -124,7 +124,7 @@ describe "puppet-retrospec" do
|
|
124
124
|
it 'should create proper shared context file' do
|
125
125
|
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
126
126
|
filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
|
127
|
-
path = tomcat.
|
127
|
+
path = tomcat.create_tmp_module_path(@opts[:module_path])
|
128
128
|
tomcat.safe_make_shared_context
|
129
129
|
expect(File.exists?(filepath)).to eq(true)
|
130
130
|
end
|
@@ -181,9 +181,9 @@ describe "puppet-retrospec" do
|
|
181
181
|
it 'should create a link in the temp modules directory' do
|
182
182
|
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
183
183
|
path = tomcat.tmp_modules_dir
|
184
|
-
tomcat.
|
185
|
-
File.exists?(
|
186
|
-
|
184
|
+
tmp_path = tomcat.create_tmp_module_path(@opts[:module_path])
|
185
|
+
expect(File.exists?(tmp_path)).to eq(true)
|
186
|
+
expect(tmp_path).to eq(File.join(path, tomcat.module_name))
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'should create a file from a template' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-retrospec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/retrospec.rb
|
200
200
|
- lib/retrospec/conditional.rb
|
201
201
|
- lib/retrospec/helpers.rb
|
202
|
+
- lib/retrospec/module_utilities.rb
|
202
203
|
- lib/retrospec/resource.rb
|
203
204
|
- lib/retrospec/templates/acceptance_spec_test.erb
|
204
205
|
- lib/retrospec/templates/fixtures_file.erb
|