puppet-catalog_rspec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/puppet-catalog_rspec/catalog.rb +18 -0
- data/lib/puppet-catalog_rspec/resource.rb +37 -0
- data/lib/puppet-catalog_rspec/rspec.rb +3 -0
- data/lib/puppet-catalog_rspec/version.rb +5 -0
- data/lib/puppet-catalog_rspec.rb +4 -0
- data/puppet-catalog_rspec.gemspec +36 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 558cd4aaa0908ae662b6a575183008bf515dd89b
|
4
|
+
data.tar.gz: a3f08e37122919e221370700954a0244e9fb19ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25d33565079fde577eb66deb66b72f0a75979c0dd928394673d485bfcb22e3c9fcb0c2f739e206f26d1738fe8b096e41373579ee844102882a257e28ad6a4c96
|
7
|
+
data.tar.gz: 0cbedcd56cf450c02584c325e5b8121833cfc6df43e3b949e31357848e429de07127f86b78b74c7f0f2a939ab70c526029644761bf1e6701c1857b4cfa812e4e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
puppet-catalog_rspec (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
x86_64-darwin-17
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.16)
|
31
|
+
puppet-catalog_rspec!
|
32
|
+
rake (~> 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Bert Hajee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Create Specs from your existing Puppet Catalog
|
2
|
+
|
3
|
+
[![Enterprise Modules](https://raw.githubusercontent.com/enterprisemodules/public_images/master/banner1.jpg)](https://www.enterprisemodules.com)
|
4
|
+
|
5
|
+
Writing tests greatly enhances the quality and stability of your code in general. The same also goes for Puppet code. Puppet has a great tool for writing unit tests for Puppet code [rspec-puppet](http://rspec-puppet.com/).
|
6
|
+
|
7
|
+
But writing unit tests is not always easy. Sometimes it is hard to get visualize what your catalog looks like when a certain combination of facts and properties is passed to your code.
|
8
|
+
|
9
|
+
This Gem can help you. It allows you to dump the Puppet catalog as `puppet-rspec` code.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'puppet-catalog_rspec'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ gem install puppet-catalog_rspec
|
29
|
+
```
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
To use the gem, put the next line in your `spec_helper.rb`:
|
33
|
+
|
34
|
+
```
|
35
|
+
require 'puppet-catalog_rspec'
|
36
|
+
```
|
37
|
+
|
38
|
+
Now we are ready to roll.
|
39
|
+
|
40
|
+
## Workflow
|
41
|
+
|
42
|
+
There is no one single workflow that works, but this is what we use. In your spec file create the state you want to build the test code for by using the correct facts and params. Then use the next statement in your spec file:
|
43
|
+
|
44
|
+
```
|
45
|
+
it { dump_catalog }
|
46
|
+
```
|
47
|
+
|
48
|
+
This will dump the full current catalog as rspec-code. Here is an example:
|
49
|
+
|
50
|
+
```
|
51
|
+
it { is_expected.to contain_archive('/install/p17572726_1036_Generic.zip')
|
52
|
+
.with('path' => '/install/p17572726_1036_Generic.zip')
|
53
|
+
.with('ensure' => 'present')
|
54
|
+
.with('cleanup' => 'false')
|
55
|
+
.with('extract' => 'false')
|
56
|
+
.with('source' => 'puppet:///middleware/p17572726_1036_Generic.zip')
|
57
|
+
.with('user' => 'oracle')
|
58
|
+
.with('group' => 'dba')
|
59
|
+
.that_requires('File[/opt/oracle/middleware/utils/bsu/cache_dir]')
|
60
|
+
}
|
61
|
+
|
62
|
+
it { is_expected.to contain_exec('patch policy for p17572726_1036_Generic.zip')
|
63
|
+
.with('command' => 'bash -c "{ echo 'grant codeBase \"file:/opt/oracle/middleware/patch_wls1036/patch_jars/-\" {'; echo ' permission java.security.AllPermission;'; echo '};'; } >> /opt/oracle/middleware/wlserver/server/lib/weblogic.policy"')
|
64
|
+
.with('unless' => 'grep 'file:/opt/oracle/middleware/patch_wls1036/patch_jars/-' /opt/oracle/middleware/wlserver/server/lib/weblogic.policy')
|
65
|
+
.with('path' => '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/java/jdk1.7.0_45/bin')
|
66
|
+
.with('user' => 'oracle')
|
67
|
+
.with('group' => 'dba')
|
68
|
+
.with('logoutput' => 'on_failure')
|
69
|
+
.that_requires('Bsu_patch[FCX7]')
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
Now copy and paste the parts that you want to check in your manifest into your rspec-code and voila.
|
74
|
+
## Development
|
75
|
+
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/enterprisemodules/puppet-catalog_rspec.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "puppet/catalog_rspec"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'puppet/resource/catalog'
|
2
|
+
|
3
|
+
# Monky patch Puppet
|
4
|
+
class Puppet::Resource::Catalog
|
5
|
+
def to_rspec
|
6
|
+
resources.each do |resource|
|
7
|
+
next if filtered?(resource.to_s)
|
8
|
+
resource.to_rspec
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def filtered?(klass)
|
15
|
+
['Class[main]', 'Stage[main]'].include?(klass)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'puppet/resource'
|
2
|
+
|
3
|
+
# Monky patch Puppet
|
4
|
+
class Puppet::Resource
|
5
|
+
def to_rspec
|
6
|
+
type = self.type.downcase.tr(':', '_')
|
7
|
+
puts "it { is_expected.to contain_#{type}('#{title}')"
|
8
|
+
properties
|
9
|
+
puts '}'
|
10
|
+
puts ''
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def properties
|
16
|
+
hash = to_hash
|
17
|
+
keys = hash.keys
|
18
|
+
max_length = keys.map(&:length).max
|
19
|
+
hash.each do |k, v|
|
20
|
+
case k
|
21
|
+
when :name
|
22
|
+
# Skip name
|
23
|
+
next
|
24
|
+
when :require
|
25
|
+
[v].flatten.each { |r| puts " .that_requires('#{r}')" }
|
26
|
+
when :before
|
27
|
+
[v].flatten.each { |r| puts " .that_comes_before('#{r}')" }
|
28
|
+
when :notify
|
29
|
+
[v].flatten.each { |r| puts " .that_notifies('#{r}')" }
|
30
|
+
when :subscribe
|
31
|
+
[v].flatten.each { |r| puts " .that_subscribes_to('#{v}')" }
|
32
|
+
else
|
33
|
+
puts " .with(#{("'#{k}'").ljust(max_length + 2)} => '#{v}')"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "puppet-catalog_rspec/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "puppet-catalog_rspec"
|
8
|
+
spec.version = Puppet::CatalogRspec::VERSION
|
9
|
+
spec.authors = ["Bert Hajee"]
|
10
|
+
spec.email = ["bert.hajee@enterprisemodules.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Dump the Puppet catalog in rspec format}
|
13
|
+
spec.description = %q{As an aid when writing Puppet RSpec tests, you can dump the Puppet catalog in RSpec format}
|
14
|
+
spec.homepage = "https://github.com/enterprisemodules/puppet-catalog_rspec"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-catalog_rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bert Hajee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: As an aid when writing Puppet RSpec tests, you can dump the Puppet catalog
|
56
|
+
in RSpec format
|
57
|
+
email:
|
58
|
+
- bert.hajee@enterprisemodules.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/puppet-catalog_rspec.rb
|
74
|
+
- lib/puppet-catalog_rspec/catalog.rb
|
75
|
+
- lib/puppet-catalog_rspec/resource.rb
|
76
|
+
- lib/puppet-catalog_rspec/rspec.rb
|
77
|
+
- lib/puppet-catalog_rspec/version.rb
|
78
|
+
- puppet-catalog_rspec.gemspec
|
79
|
+
homepage: https://github.com/enterprisemodules/puppet-catalog_rspec
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata:
|
83
|
+
allowed_push_host: https://rubygems.org/
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.13
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Dump the Puppet catalog in rspec format
|
104
|
+
test_files: []
|