pdqtest 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +57 -18
- data/exe/pdqtest +37 -0
- data/lib/pdqtest/puppet.rb +48 -0
- data/lib/pdqtest/rspec.rb +33 -0
- data/lib/pdqtest/skeleton.rb +2 -5
- data/lib/pdqtest/util.rb +7 -0
- data/lib/pdqtest/version.rb +1 -1
- data/res/templates/rspec.rb +10 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5266f16024798c5f5557f7f9ca6efcb9ca6e4b7e
|
4
|
+
data.tar.gz: 42a2a7498e5102b0ee2eef1e52562f956e4924bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa0cde45a6031b7d9971faaba5d2109bbffd825957274842e964d0b9b819554ff642bcba01eb6cc86b7f92b397ccff4df0dd2365a075ec8141056cc18ccf1850
|
7
|
+
data.tar.gz: 0cf5640d97c1e32b6c03656d36984049c740fd72c7218ddbd7ae57fb36c821824c30807e9c7ccb342fe37f74e2278c11ca5afc08959938034a964abfeedf6301
|
data/README.md
CHANGED
@@ -1,41 +1,80 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/
|
1
|
+
[![Build Status](https://travis-ci.org/declarativesystems/pdqtest.svg?branch=master)](https://travis-ci.org/GeoffWilliams/pdqtest)
|
2
2
|
|
3
3
|
# PDQTest
|
4
4
|
|
5
|
-
|
5
|
+
PDQTest - Puppet Docker Quick-test - is the quickest and easiest way to test your puppet modules. PDQTest features tests for:
|
6
|
+
* Linting
|
7
|
+
* Syntax
|
8
|
+
* RSpec
|
9
|
+
* Acceptance (BATS)
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
## Statistics
|
10
|
-
Without running puppet, spinning up containers and running bats tests took on average 1-3 seconds, vs ~15 with a hacked version of testkitchen, ~4 minutes with unhacked (when offline).
|
11
|
-
|
12
|
-
Thats a sick improvement!
|
11
|
+
PDQTest runs linting, syntax and RSpec tests within the machine it is running from and then loads a docker container to perform acceptance testing.
|
13
12
|
|
14
13
|
## Installation
|
15
14
|
|
16
|
-
|
15
|
+
To install PDQTest on your system:
|
17
16
|
|
17
|
+
### System Ruby
|
18
|
+
```shell
|
19
|
+
gem install pdqtest
|
20
|
+
```
|
21
|
+
|
22
|
+
### Bundler, add this line to your application's Gemfile:
|
18
23
|
```ruby
|
19
|
-
gem 'pdqtest
|
24
|
+
gem 'pdqtest
|
20
25
|
```
|
26
|
+
* It's advisable to specify a version number to ensure repeatable builds
|
21
27
|
|
22
|
-
|
28
|
+
### Puppet modules
|
29
|
+
To add PDQTests to a puppet module, run the command:
|
30
|
+
```
|
31
|
+
pdqtest init
|
32
|
+
```
|
33
|
+
|
34
|
+
This will install PDQTest into the `Gemfile` and will generate an example set of acceptance tests
|
23
35
|
|
24
|
-
|
36
|
+
## Running tests
|
25
37
|
|
26
|
-
|
38
|
+
### Module dependencies/.fixtures.yml
|
39
|
+
Module dependencies should be specified in your module's `metadata.json` file. There is no requirement to maintain a `.fixtures.yml` file.
|
27
40
|
|
28
|
-
$ gem install pdqtest
|
29
41
|
|
30
|
-
|
42
|
+
### All tests
|
43
|
+
If you just want to run all tests:
|
31
44
|
|
32
|
-
|
45
|
+
```shell
|
46
|
+
bundle exec pdqtest all
|
47
|
+
```
|
48
|
+
|
49
|
+
### RSpec tests
|
50
|
+
```shell
|
51
|
+
bundle exec pdqtest rspec
|
52
|
+
```
|
53
|
+
|
54
|
+
### Debugging failed builds
|
55
|
+
PDQTest makes it easy to debug failed builds:
|
56
|
+
|
57
|
+
```shell
|
58
|
+
pdqtest shell
|
59
|
+
```
|
60
|
+
|
61
|
+
* Open a shell inside the docker container that would be used to run tests
|
62
|
+
* Your code is available at `/cut`
|
63
|
+
|
64
|
+
```shell
|
65
|
+
pdqtest --keep-container all
|
66
|
+
```
|
67
|
+
* Run all tests, report pass/fail status
|
68
|
+
* Keep the container Running
|
69
|
+
* After testing, the container used to run tests will be left running and a message will be printed showing how to enter the container used for testing. Your code is avaiable at `/cut`
|
33
70
|
|
34
71
|
## Development
|
35
72
|
|
36
|
-
|
73
|
+
PRs welcome :) Please ensure suitable tests cover any new functionality and that all tests are passing before and after your development work:
|
37
74
|
|
38
|
-
|
75
|
+
```shell
|
76
|
+
bundle exec rake spec
|
77
|
+
```
|
39
78
|
|
40
79
|
## Who should use PDQTest?
|
41
80
|
You should use pdqtest if you find it increases your productivity and enriches your life
|
data/exe/pdqtest
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'pdqtest/instance'
|
3
3
|
require 'pdqtest/rspec'
|
4
|
+
require 'pdqtest/util'
|
4
5
|
require 'pdqtest/skeleton'
|
5
6
|
require 'pdqtest/lint'
|
6
7
|
require 'pdqtest/syntax'
|
@@ -25,6 +26,8 @@ Escort::App.create do |app|
|
|
25
26
|
end
|
26
27
|
|
27
28
|
app.command :all do |command|
|
29
|
+
command.summary "All"
|
30
|
+
command.description "Run all tests"
|
28
31
|
command.action do |options, arguments|
|
29
32
|
PDQTest::Instance.set_keep_container(options[:global][:options][:keep_container])
|
30
33
|
PDQTest::Core.run([
|
@@ -37,6 +40,8 @@ Escort::App.create do |app|
|
|
37
40
|
end
|
38
41
|
|
39
42
|
app.command :rspec do |command|
|
43
|
+
command.summary "RSpec"
|
44
|
+
command.description "Run the RSpec tests"
|
40
45
|
command.action do |options, arguments|
|
41
46
|
PDQTest::Core.run(lambda {PDQTest::Rspec.run})
|
42
47
|
end
|
@@ -44,6 +49,8 @@ Escort::App.create do |app|
|
|
44
49
|
|
45
50
|
|
46
51
|
app.command :acceptance do |command|
|
52
|
+
command.summary "Acceptance"
|
53
|
+
command.description "Run the acceptance (Docker) tests"
|
47
54
|
command.options do |opts|
|
48
55
|
opts.opt(:example,
|
49
56
|
'Run only this example (eg --example examples/init.pp)',
|
@@ -60,34 +67,64 @@ Escort::App.create do |app|
|
|
60
67
|
end
|
61
68
|
|
62
69
|
app.command :init do |command|
|
70
|
+
command.summary "Initialise testing"
|
71
|
+
command.description "Install skeleton testing configuration into this module"
|
63
72
|
command.action do |options, arguments|
|
64
73
|
PDQTest::Skeleton.init
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
77
|
+
app.command :generate_rspec do |command|
|
78
|
+
command.summary "Generate RSpec"
|
79
|
+
command.description "For each class in the module, generate basic RSpec tests"
|
80
|
+
command.action do |options, arguments|
|
81
|
+
PDQTest::Rspec.gen_specs
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
68
86
|
app.command :shell do |command|
|
87
|
+
command.summary "Shell"
|
88
|
+
command.description "Open a shell inside a docker container identical to the test environment before anything has run"
|
69
89
|
command.action do |options, arguments|
|
70
90
|
PDQTest::Instance.shell
|
71
91
|
end
|
72
92
|
end
|
73
93
|
|
74
94
|
app.command :syntax do |command|
|
95
|
+
command.summary "Syntax"
|
96
|
+
command.description "Check for syntax errors"
|
75
97
|
command.action do |options, arguments|
|
76
98
|
PDQTest::Core.run(lambda {PDQTest::Syntax.puppet})
|
77
99
|
end
|
78
100
|
end
|
79
101
|
|
80
102
|
app.command :lint do |command|
|
103
|
+
command.summary "Lint"
|
104
|
+
command.description "Check for lint errors"
|
105
|
+
|
81
106
|
command.action do |options, arguments|
|
82
107
|
PDQTest::Core.run(lambda {PDQTest::Lint.puppet})
|
83
108
|
end
|
84
109
|
end
|
85
110
|
|
86
111
|
app.command :setup do |command|
|
112
|
+
command.summary "Setup"
|
113
|
+
command.description "Install the docker container required for testing"
|
114
|
+
|
87
115
|
command.action do |options, arguments|
|
88
116
|
PDQTest::Core.run(lambda {
|
89
117
|
system("docker pull #{PDQTest::Docker::IMAGE_NAME}")
|
90
118
|
})
|
91
119
|
end
|
92
120
|
end
|
121
|
+
|
122
|
+
app.command :info do |command|
|
123
|
+
command.summary "Info"
|
124
|
+
command.description "Print info about this module"
|
125
|
+
command.action do |options, arguments|
|
126
|
+
PDQTest::Puppet.info
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
93
130
|
end
|
data/lib/pdqtest/puppet.rb
CHANGED
@@ -14,6 +14,8 @@ module PDQTest
|
|
14
14
|
BEFORE_SUFFIX = '__before.bats'
|
15
15
|
AFTER_SUFFIX = '.bats'
|
16
16
|
EXAMPLES_DIR = './examples'
|
17
|
+
MANIFESTS_DIR = './manifests'
|
18
|
+
CLASS_RE = /^class /
|
17
19
|
@@bats_executed = []
|
18
20
|
@@setup_executed = []
|
19
21
|
|
@@ -51,6 +53,26 @@ module PDQTest
|
|
51
53
|
"cd #{PDQTest::Instance::TEST_DIR} && librarian-puppet install --path #{MODULE_DIR} --destructive"
|
52
54
|
end
|
53
55
|
|
56
|
+
def self.class2filename(c)
|
57
|
+
if c == module_name
|
58
|
+
f = "#{MANIFESTS_DIR}/init.pp"
|
59
|
+
else
|
60
|
+
f = c.gsub(module_name, MANIFESTS_DIR).gsub('::', File::SEPARATOR) + '.pp'
|
61
|
+
end
|
62
|
+
|
63
|
+
f
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.filename2class(f)
|
67
|
+
if f == "#{MANIFESTS_DIR}/init.pp"
|
68
|
+
c = module_name
|
69
|
+
else
|
70
|
+
c = f.gsub(MANIFESTS_DIR, "#{module_name}").gsub(File::SEPARATOR, '::').gsub('.pp','')
|
71
|
+
end
|
72
|
+
|
73
|
+
c
|
74
|
+
end
|
75
|
+
|
54
76
|
def self.find_examples()
|
55
77
|
examples = []
|
56
78
|
if Dir.exists?(EXAMPLES_DIR)
|
@@ -64,6 +86,27 @@ module PDQTest
|
|
64
86
|
examples
|
65
87
|
end
|
66
88
|
|
89
|
+
# find the available classes in this module
|
90
|
+
def self.find_classes()
|
91
|
+
mod_name = module_name
|
92
|
+
classes = []
|
93
|
+
if Dir.exists?(MANIFESTS_DIR)
|
94
|
+
Find.find(MANIFESTS_DIR) do |m|
|
95
|
+
if m =~ /\.pp$/
|
96
|
+
# check the file contains a valid class
|
97
|
+
if ! File.readlines(m).grep(CLASS_RE).empty?
|
98
|
+
# Class detected, work out class name and add to list of found classes
|
99
|
+
classes << filename2class(m)
|
100
|
+
else
|
101
|
+
Escort::Logger.output.puts "no puppet class found in #{m}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
classes
|
108
|
+
end
|
109
|
+
|
67
110
|
def self.test_basename(t)
|
68
111
|
# remove examples/ and .pp
|
69
112
|
# eg ./examples/apache/mod/mod_php.pp --> apache/mod/mod_php
|
@@ -175,5 +218,10 @@ module PDQTest
|
|
175
218
|
def self.puppet_apply(example)
|
176
219
|
"cd #{PDQTest::Instance::TEST_DIR} && puppet apply --detailed-exitcodes #{example}"
|
177
220
|
end
|
221
|
+
|
222
|
+
def self.info
|
223
|
+
Escort::Logger.output.puts "Parsed module name: #{module_name}"
|
224
|
+
Escort::Logger.output.puts "Link module command: #{link_module}"
|
225
|
+
end
|
178
226
|
end
|
179
227
|
end
|
data/lib/pdqtest/rspec.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
require 'pdqtest/puppet'
|
2
|
+
require 'pdqtest/util'
|
3
|
+
require 'erb'
|
1
4
|
module PDQTest
|
2
5
|
module Rspec
|
6
|
+
SPEC_DIR = './spec'
|
7
|
+
SPEC_CLASSES_DIR = "#{SPEC_DIR}/classes"
|
8
|
+
|
3
9
|
def self.run
|
4
10
|
status = system("bundle exec librarian-puppet install --path ./spec/fixtures/modules --destructive")
|
5
11
|
status &= system("bundle exec rake spec")
|
@@ -7,5 +13,32 @@ module PDQTest
|
|
7
13
|
status
|
8
14
|
end
|
9
15
|
|
16
|
+
def self.class2specfile(c)
|
17
|
+
pp = Puppet::class2filename(c)
|
18
|
+
pp.gsub(Puppet::MANIFESTS_DIR, SPEC_CLASSES_DIR).gsub('.pp', '_spec.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.gen_specs
|
22
|
+
classes = PDQTest::Puppet::find_classes
|
23
|
+
|
24
|
+
classes.each { |classname|
|
25
|
+
spec_file = class2specfile(classname)
|
26
|
+
if File.exists?(spec_file)
|
27
|
+
Escort::Logger.output.puts "Skipped #{classname} - tests already exist at #{spec_file}"
|
28
|
+
else
|
29
|
+
# first ensure any nested directories exist
|
30
|
+
base_dir = File.dirname(spec_file)
|
31
|
+
if ! Dir.exists?(base_dir)
|
32
|
+
Dir.mkdir(base_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
# process the rspec template into a new file
|
36
|
+
template = File.read(Util::resource_path(File.join('templates', 'rspec.rb')))
|
37
|
+
testcase = ERB.new(template, nil, '-').result(binding)
|
38
|
+
File.write(spec_file, testcase)
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
10
43
|
end
|
11
44
|
end
|
data/lib/pdqtest/skeleton.rb
CHANGED
@@ -2,6 +2,7 @@ require 'fileutils'
|
|
2
2
|
require 'digest'
|
3
3
|
require 'pdqtest/puppet'
|
4
4
|
require 'pdqtest/version'
|
5
|
+
require 'pdqtest/util'
|
5
6
|
|
6
7
|
module PDQTest
|
7
8
|
module Skeleton
|
@@ -24,12 +25,8 @@ module PDQTest
|
|
24
25
|
target_hash != skeleton_hash
|
25
26
|
end
|
26
27
|
|
27
|
-
def self.resource_path(resource)
|
28
|
-
File.join(File.dirname(File.expand_path(__FILE__)), "../../res/#{resource}")
|
29
|
-
end
|
30
|
-
|
31
28
|
def self.install_skeleton(target_file, skeleton, replace=true)
|
32
|
-
skeleton_file = resource_path(File.join('skeleton', skeleton))
|
29
|
+
skeleton_file = Util::resource_path(File.join('skeleton', skeleton))
|
33
30
|
if File.exists?(target_file) and replace and should_replace_file(target_file, skeleton_file)
|
34
31
|
# move existing file out of the way
|
35
32
|
FileUtils.mv(target_file, target_file + BACKUP_EXT)
|
data/lib/pdqtest/util.rb
ADDED
data/lib/pdqtest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdqtest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/pdqtest/rspec.rb
|
208
208
|
- lib/pdqtest/skeleton.rb
|
209
209
|
- lib/pdqtest/syntax.rb
|
210
|
+
- lib/pdqtest/util.rb
|
210
211
|
- lib/pdqtest/version.rb
|
211
212
|
- pdqtest.gemspec
|
212
213
|
- res/skeleton/Gemfile
|
@@ -218,6 +219,7 @@ files:
|
|
218
219
|
- res/skeleton/init__before.bats
|
219
220
|
- res/skeleton/init__setup.sh
|
220
221
|
- res/skeleton/spec_helper.rb
|
222
|
+
- res/templates/rspec.rb
|
221
223
|
homepage: https://github.com/GeoffWilliams/pdqtest
|
222
224
|
licenses:
|
223
225
|
- Apache-2.0
|
@@ -238,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
240
|
version: '0'
|
239
241
|
requirements: []
|
240
242
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.5.
|
243
|
+
rubygems_version: 2.5.2
|
242
244
|
signing_key:
|
243
245
|
specification_version: 4
|
244
246
|
summary: Quick and simple integration tests run inside of a docker container
|