puppet-retrospec 0.6.1 → 0.7.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -0
- data/VERSION +1 -1
- data/bin/retrospec +1 -0
- data/lib/retrospec.rb +11 -4
- data/lib/retrospec/helpers.rb +8 -8
- data/lib/retrospec/puppet_module.rb +9 -5
- data/puppet-retrospec.gemspec +3 -3
- data/spec/unit/puppet-retrospec_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2d1e94be8d1bb747a80e140e221d2ec084c4e84
|
4
|
+
data.tar.gz: cfc0f190bc77582fe7e1d851d60c6b06662efb16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a30bcaa63582f99df12131482eb08055825c0a72bf01c11faafb0b312da1bbb32ac3208dda81b1461d31097f9dbbe9d21481fbcf6c44d4650d52951cbaa6764
|
7
|
+
data.tar.gz: 1b577832ee652ac2113dfe1828326c26ef5576593e9acb3833ecc0eecd49c6fe2871f3a707e4444706a774d9ba9b41b01e99ecacafe385a96ae32fcb78649c14
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,7 @@ Table of Contents
|
|
25
25
|
* [Running Tests](#running-tests)
|
26
26
|
* [Understanding Variable Resolution](#understanding-variable-resolution)
|
27
27
|
* [Todo](#todo)
|
28
|
+
* [Future Parser Support](#future-parser-support)
|
28
29
|
* [Support](#support)
|
29
30
|
|
30
31
|
Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
@@ -478,6 +479,25 @@ Resolution workflow.
|
|
478
479
|
2. Find all vardef objects, resolve them if possible and store the values
|
479
480
|
3. Anything contained in a block of code is currently ignored, until later refinement.
|
480
481
|
|
482
|
+
Future Parser Support
|
483
|
+
==============
|
484
|
+
Currently Retrospec uses the old/current AST parser for code parsing. If your code contains future parser syntax
|
485
|
+
the current parser will fail to render some resource definitions but will still render the spec file template without parameters
|
486
|
+
and resource tests that are contained in your manifest.
|
487
|
+
Since Puppet 4 introduces many new things and breaks many other things I am not sure
|
488
|
+
which side of the grass is greener at this time. What I do know is that most people are using Puppet 3 and it may take
|
489
|
+
time to move to Puppet 4. I would suspect Retrospec would be more valuable for those moving to Puppet 4
|
490
|
+
who don't have unit tests that currently have Puppet 3 codebases. For those with a clean slate and start directly in
|
491
|
+
Puppet 4, Retrospec will still be able to produce the templates but some of the test cases will be missing if the old AST
|
492
|
+
parser cannot read future code syntax. If your puppet 4 codebase is compatible with puppet 3 syntax there should not be an issue.
|
493
|
+
|
494
|
+
In order to allow future parser validation please run retrospec with the following option.
|
495
|
+
|
496
|
+
```shell
|
497
|
+
retrospec --enable-future-parser
|
498
|
+
|
499
|
+
```
|
500
|
+
|
481
501
|
Todo
|
482
502
|
============
|
483
503
|
- Add support to fill out used facts in the unit tests automatically
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/bin/retrospec
CHANGED
@@ -10,6 +10,7 @@ opts = Trollop::options do
|
|
10
10
|
opt :enable_user_templates, "Use Retrospec templates from #{File.expand_path('~/.puppet_retrospec_templates')}",
|
11
11
|
:require => false, :type => :boolean
|
12
12
|
opt :enable_beaker_tests, "Enable the creation of beaker tests", :require => false, :type => :boolean
|
13
|
+
opt :enable_future_parser, "Enables the future parser only during validation", :require => false, :type => :boolean
|
13
14
|
end
|
14
15
|
include Puppet_Retrospec
|
15
16
|
|
data/lib/retrospec.rb
CHANGED
@@ -22,6 +22,7 @@ class Retrospec
|
|
22
22
|
# opts[:enable_beaker_tests]
|
23
23
|
# opts[:template_dir]
|
24
24
|
def initialize(supplied_module_path=nil,opts={})
|
25
|
+
Utilities::PuppetModule.instance.future_parser = opts[:enable_future_parser]
|
25
26
|
# user supplied a template path or user wants to use local templates
|
26
27
|
if opts[:template_dir] or opts[:enable_user_templates]
|
27
28
|
@template_dir = Helpers.setup_user_template_dir(opts[:template_dir])
|
@@ -156,8 +157,14 @@ class Retrospec
|
|
156
157
|
file_name = tokens.pop
|
157
158
|
"#{file_name}_spec.rb"
|
158
159
|
end
|
159
|
-
|
160
|
-
private
|
161
|
-
|
162
|
-
|
163
160
|
end
|
161
|
+
|
162
|
+
class String
|
163
|
+
def red; "\033[31m#{self}\033[0m" end
|
164
|
+
def green; "\033[32m#{self}\033[0m" end
|
165
|
+
def cyan; "\033[36m#{self}\033[0m" end
|
166
|
+
def yellow; "\033[33m#{self}\033[0m" end
|
167
|
+
def warning; yellow end
|
168
|
+
def fatal; red end
|
169
|
+
def info; green end
|
170
|
+
end
|
data/lib/retrospec/helpers.rb
CHANGED
@@ -32,11 +32,11 @@ class Helpers
|
|
32
32
|
def self.safe_mkdir(dir)
|
33
33
|
if File.exists? dir
|
34
34
|
unless File.directory? dir
|
35
|
-
$stderr.puts "!! #{dir} already exists and is not a directory"
|
35
|
+
$stderr.puts "!! #{dir} already exists and is not a directory".fatal
|
36
36
|
end
|
37
37
|
else
|
38
38
|
FileUtils.mkdir_p dir
|
39
|
-
puts " + #{dir}/"
|
39
|
+
puts " + #{dir}/".info
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -82,7 +82,7 @@ class Helpers
|
|
82
82
|
|
83
83
|
def self.safe_copy_file(src, dest)
|
84
84
|
if File.exists?(dest) and not File.zero?(dest)
|
85
|
-
$stderr.puts "!! #{dest} already exists"
|
85
|
+
$stderr.puts "!! #{dest} already exists".warning
|
86
86
|
else
|
87
87
|
if not File.exists?(src)
|
88
88
|
safe_touch(src)
|
@@ -90,18 +90,18 @@ class Helpers
|
|
90
90
|
safe_mkdir(File.dirname(dest))
|
91
91
|
FileUtils.cp(src,dest)
|
92
92
|
end
|
93
|
-
puts " + #{dest}"
|
93
|
+
puts " + #{dest}".info
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.safe_touch(file)
|
98
98
|
if File.exists? file
|
99
99
|
unless File.file? file
|
100
|
-
$stderr.puts "!! #{file} already exists and is not a regular file"
|
100
|
+
$stderr.puts "!! #{file} already exists and is not a regular file".fatal
|
101
101
|
end
|
102
102
|
else
|
103
103
|
FileUtils.touch file
|
104
|
-
puts " + #{file}"
|
104
|
+
puts " + #{file}".info
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -110,14 +110,14 @@ class Helpers
|
|
110
110
|
old_content = File.read(filepath)
|
111
111
|
# if we did a better comparison of content we could be smarter about when we create files
|
112
112
|
if old_content != content or not File.zero?(filepath)
|
113
|
-
$stderr.puts "!! #{filepath} already exists and differs from template"
|
113
|
+
$stderr.puts "!! #{filepath} already exists and differs from template".warning
|
114
114
|
end
|
115
115
|
else
|
116
116
|
safe_mkdir(File.dirname(filepath)) unless File.exists? File.dirname(filepath)
|
117
117
|
File.open(filepath, 'w') do |f|
|
118
118
|
f.puts content
|
119
119
|
end
|
120
|
-
puts " + #{filepath}"
|
120
|
+
puts " + #{filepath}".info
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -3,6 +3,7 @@ require 'puppet/face'
|
|
3
3
|
module Utilities
|
4
4
|
class PuppetModule
|
5
5
|
attr_writer :module_path
|
6
|
+
attr_accessor :future_parser
|
6
7
|
|
7
8
|
include Singleton
|
8
9
|
|
@@ -61,26 +62,29 @@ module Utilities
|
|
61
62
|
if dir.nil?
|
62
63
|
dir = '.'
|
63
64
|
elsif dir.instance_of?(Array)
|
64
|
-
puts "Retrospec - an array of module paths is not supported at this time"
|
65
|
+
puts "Retrospec - an array of module paths is not supported at this time".fatal
|
65
66
|
exit 1
|
66
67
|
end
|
67
68
|
dir = File.expand_path(dir)
|
68
69
|
manifest_dir = File.join(dir,'manifests')
|
69
70
|
if ! File.exist?(manifest_dir)
|
70
|
-
puts "No manifest directory in #{manifest_dir}, cannot validate this is a module"
|
71
|
+
puts "No manifest directory in #{manifest_dir}, cannot validate this is a module".fatal
|
71
72
|
exit 1
|
72
73
|
else
|
73
74
|
files = Dir.glob("#{manifest_dir}/**/*.pp")
|
74
|
-
warn "No puppet manifest files found at #{manifest_dir}" if files.length < 1
|
75
|
+
warn "No puppet manifest files found at #{manifest_dir}".warning if files.length < 1
|
75
76
|
# validate the manifest files, because if one files doesn't work it affects everything
|
76
77
|
files.each do |file|
|
77
78
|
begin
|
78
|
-
Puppet
|
79
|
+
Puppet[:parser] = 'future' if future_parser
|
80
|
+
Puppet::Face[:parser, :current].validate(file)
|
79
81
|
rescue SystemExit => e
|
80
|
-
puts "Manifest file: #{file} has parser errors, please fix and re-check using\n puppet parser validate #{file}"
|
82
|
+
puts "Manifest file: #{file} has parser errors, please fix and re-check using\n puppet parser validate #{file}".fatal
|
81
83
|
exit 1
|
82
84
|
end
|
83
85
|
end
|
86
|
+
# switch back to current parser, since we rely on the AST parser
|
87
|
+
Puppet[:parser] = 'current' if future_parser
|
84
88
|
end
|
85
89
|
dir
|
86
90
|
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
|
+
# stub: puppet-retrospec 0.7.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "puppet-retrospec"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.7.0"
|
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-
|
14
|
+
s.date = "2015-04-07"
|
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"]
|
@@ -28,6 +28,13 @@ describe "puppet-retrospec" do
|
|
28
28
|
expect(tomcat).to be_instance_of(Retrospec)
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'should set the parser to future' do
|
32
|
+
opts = {:module_path => @path, :enable_beaker_tests => false,
|
33
|
+
:enable_user_templates => false, :template_dir => nil, :enable_future_parser => true }
|
34
|
+
tomcat = Retrospec.new(opts[:module_path], opts)
|
35
|
+
expect(tomcat.spec_object.instance.future_parser).to eq(true)
|
36
|
+
end
|
37
|
+
|
31
38
|
it 'should create files without error' do
|
32
39
|
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
33
40
|
tomcat.create_files
|
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.
|
4
|
+
version: 0.7.0
|
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-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|