pdqtest 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5266f16024798c5f5557f7f9ca6efcb9ca6e4b7e
4
- data.tar.gz: 42a2a7498e5102b0ee2eef1e52562f956e4924bc
3
+ metadata.gz: 252a38cb94b84c965c798e0813a55fcb429e522b
4
+ data.tar.gz: fb594b19707e074e9050d412ef9aca00afc76aa0
5
5
  SHA512:
6
- metadata.gz: fa0cde45a6031b7d9971faaba5d2109bbffd825957274842e964d0b9b819554ff642bcba01eb6cc86b7f92b397ccff4df0dd2365a075ec8141056cc18ccf1850
7
- data.tar.gz: 0cf5640d97c1e32b6c03656d36984049c740fd72c7218ddbd7ae57fb36c821824c30807e9c7ccb342fe37f74e2278c11ca5afc08959938034a964abfeedf6301
6
+ metadata.gz: 95a764923fa9e77f8c8b32840f80e9a5377e44711cdf4ca0af98a9545f01ae2894356391ccb540d2d363fbbd8025030e7a925435c3c8f02e6c3a5cd3d4c0a164
7
+ data.tar.gz: 01ac447b7dd030e560f0400d32c481fa26549b0b0220f373d12eee2cf9adead4cff50f9d281b3249985b7d60b507a1aa00d3f4b416ef87e7fc59553b2b3dae55
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .librarian
12
12
  Puppetfile.lock
13
13
  *.gem
14
+ /fixtures/passing_tests/spec/fixtures
data/README.md CHANGED
@@ -36,8 +36,18 @@ This will install PDQTest into the `Gemfile` and will generate an example set of
36
36
  ## Running tests
37
37
 
38
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.
39
+ Ordinarily, there is no need to maintain a `.fixtures.yml` file. Dependencies on public forge modules should be specified in your module's `metadata.json` file.
40
40
 
41
+ If you need to download modules from git (eg those not available on forge.puppetlabs.com), then you must populate the `fixtures` section of `.fixtures.yml`, eg:
42
+
43
+ ```
44
+ repositories:
45
+ corporatestuff:
46
+ repo: 'https://nonpublicgit.megacorp.com/corporatestuff.git'
47
+ ref: 'mybranch'
48
+ ```
49
+
50
+ Note that only the repositories section of the file will be processed as we do not use `puppetlabs_spec_helper` to do this for us.
41
51
 
42
52
  ### All tests
43
53
  If you just want to run all tests:
@@ -86,5 +96,10 @@ You should use pdqtest if you find it increases your productivity and enriches y
86
96
  This software is not supported by Puppet, Inc. Use at your own risk.
87
97
 
88
98
  ## Contributing
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/declarativesystems/pdqtest.
89
100
 
90
- Bug reports and pull requests are welcome on GitHub at https://github.com/GeoffWilliams/pdqtest.
101
+ ### Running tests
102
+ * PDQTest includes a comprehensive tests for core library functions. Please ensure tests pass before and after any PRs
103
+ * Run all tests `bundle exec rake spec`
104
+ * Run specific test file `bundle exec rspec ./spec/SPEC/FILE/TO/RUN.rb`
105
+ * Run specific test case `bundle exec rspec ./spec/SPEC/FILE/TO/RUN.rb:99` (where 99 is the line number of the test)
@@ -28,20 +28,39 @@ RUN yum install -y cronie \
28
28
  gpm-libs \
29
29
  policycoreutils \
30
30
  policycoreutils-restorecond && yum clean all
31
- RUN echo "metadata_expire=never" >> /etc/yum.conf && \
32
- echo "LANG=C" >> /etc/environment && \
33
- echo "LC_ALL=C" >> /etc/environment && \
34
- echo "export PATH=/usr/local/bats/bin:/opt/puppetlabs/puppet/bin/:${PATH}" >> /etc/environment && \
35
- echo "export TERM=xterm" >> /etc/environment
31
+ RUN echo "metadata_expire=never" >> /etc/yum.conf
32
+
33
+ # fix locale
34
+ RUN echo 'LANG=en_US.UTF-8' > /etc/locale.conf
35
+ RUN yum -y reinstall glibc-common
36
+ # swallow errors
37
+ RUN localedef --quiet -v -c -i en_US -f UTF-8 en_US.UTF-8 || true
38
+
39
+
40
+ ENV LANG en_US.UTF-8
41
+ # && \
42
+ # echo "LANG=C" >> /etc/environment && \
43
+ ENV LC_ALL en_US.UTF-8
44
+ # echo "LC_ALL=C" >> /etc/environment && \
45
+ ENV PATH /usr/local/bats/bin:/opt/puppetlabs/puppet/bin/:/usr/sbin:/sbin:/usr/bin:/bin
46
+ # echo "export PATH=/usr/local/bats/bin:/opt/puppetlabs/puppet/bin/:${PATH}" >> /etc/environment && \
47
+ ENV TERM xterm
48
+ # echo "export TERM=xterm" >> /etc/environment
36
49
 
37
50
  # puppet
38
51
  RUN yum -y install http://yum.puppetlabs.com/el/7/PC1/x86_64/puppet-agent-1.8.2-1.el7.x86_64.rpm && \
39
52
  /opt/puppetlabs/puppet/bin/puppet --version && \
40
53
  /opt/puppetlabs/puppet/bin/facter --version
41
54
 
55
+ # bats
42
56
  RUN git clone https://github.com/sstephenson/bats /usr/local/bats
57
+
58
+ # librarian
43
59
  RUN /opt/puppetlabs/puppet/bin/gem install librarian-puppet
44
60
 
61
+ # git refresh (for processing .fixtures.yml git modules)
62
+ RUN /opt/puppetlabs/puppet/bin/gem install git_refresh
63
+
45
64
  # code under test
46
65
  RUN mkdir /cut
47
66
  VOLUME /cut
@@ -1 +1,3 @@
1
- docker build --squash -t geoffwilliams/pdqtest-centos:2017-01-08-0 .
1
+ all:
2
+ # requires experimental mode - see https://github.com/docker/docker/tree/master/experimental#use-docker-experimental
3
+ bash -c 'docker build --squash -t geoffwilliams/pdqtest-centos:$$(date -I)-0 .'
data/exe/pdqtest CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'pdqtest'
3
+ require 'pdqtest/emoji'
2
4
  require 'pdqtest/instance'
3
5
  require 'pdqtest/rspec'
4
6
  require 'pdqtest/util'
@@ -23,12 +25,21 @@ Escort::App.create do |app|
23
25
  :type => :boolean,
24
26
  :default => false,
25
27
  )
28
+
29
+ opts.opt(:disable_emoji,
30
+ 'Do not display emoji status characters',
31
+ :long => '--disable-emoji',
32
+ :type => :boolean,
33
+ :default => false,
34
+ )
26
35
  end
27
36
 
28
37
  app.command :all do |command|
29
38
  command.summary "All"
30
39
  command.description "Run all tests"
31
40
  command.action do |options, arguments|
41
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
42
+
32
43
  PDQTest::Instance.set_keep_container(options[:global][:options][:keep_container])
33
44
  PDQTest::Core.run([
34
45
  lambda {PDQTest::Syntax.puppet},
@@ -43,6 +54,7 @@ Escort::App.create do |app|
43
54
  command.summary "RSpec"
44
55
  command.description "Run the RSpec tests"
45
56
  command.action do |options, arguments|
57
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
46
58
  PDQTest::Core.run(lambda {PDQTest::Rspec.run})
47
59
  end
48
60
  end
@@ -60,6 +72,7 @@ Escort::App.create do |app|
60
72
  )
61
73
  end
62
74
  command.action do |options, arguments|
75
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
63
76
  PDQTest::Instance.set_keep_container(options[:global][:options][:keep_container])
64
77
  example = options[:global][:commands][:acceptance][:options][:example]
65
78
  PDQTest::Core.run(lambda {PDQTest::Instance.run(example)})
@@ -70,6 +83,7 @@ Escort::App.create do |app|
70
83
  command.summary "Initialise testing"
71
84
  command.description "Install skeleton testing configuration into this module"
72
85
  command.action do |options, arguments|
86
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
73
87
  PDQTest::Skeleton.init
74
88
  end
75
89
  end
@@ -78,6 +92,7 @@ Escort::App.create do |app|
78
92
  command.summary "Generate RSpec"
79
93
  command.description "For each class in the module, generate basic RSpec tests"
80
94
  command.action do |options, arguments|
95
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
81
96
  PDQTest::Rspec.gen_specs
82
97
  end
83
98
  end
@@ -95,6 +110,7 @@ Escort::App.create do |app|
95
110
  command.summary "Syntax"
96
111
  command.description "Check for syntax errors"
97
112
  command.action do |options, arguments|
113
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
98
114
  PDQTest::Core.run(lambda {PDQTest::Syntax.puppet})
99
115
  end
100
116
  end
@@ -104,6 +120,7 @@ Escort::App.create do |app|
104
120
  command.description "Check for lint errors"
105
121
 
106
122
  command.action do |options, arguments|
123
+ PDQTest::Emoji.disable(options[:global][:options][:disable_emoji])
107
124
  PDQTest::Core.run(lambda {PDQTest::Lint.puppet})
108
125
  end
109
126
  end
data/lib/pdqtest/core.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'pdqtest'
2
+ require 'pdqtest/emoji'
1
3
  module PDQTest
2
4
  module Core
3
5
 
@@ -7,10 +9,15 @@ module PDQTest
7
9
  functions.each { |f|
8
10
  if ! f.call
9
11
  Escort::Logger.error.error "Error encountered running #{f.to_s}"
12
+
13
+ # epic fail, exit program
14
+ PDQTest::Emoji.final_status(false)
10
15
  abort("ABORTED - there are test failures! :(")
11
16
  end
12
17
  }
13
18
 
19
+ # we passed already
20
+ PDQTest::Emoji.final_status(true)
14
21
  true
15
22
  end
16
23
 
@@ -4,7 +4,7 @@ module PDQTest
4
4
  ERR = 1
5
5
  STATUS = 2
6
6
  ENV='export TERM=xterm LC_ALL=C PATH=/usr/local/bats/bin:/opt/puppetlabs/puppet/bin:$PATH;'
7
- IMAGE_NAME='geoffwilliams/pdqtest-centos:2017-01-08-0'
7
+ IMAGE_NAME='geoffwilliams/pdqtest-centos:2017-03-30-0'
8
8
 
9
9
 
10
10
  def self.wrap_cmd(cmd)
@@ -58,6 +58,11 @@ module PDQTest
58
58
  }
59
59
  end
60
60
 
61
+ def self.log_all(res)
62
+ log_err(res)
63
+ log_out(res)
64
+ end
65
+
61
66
  def self.log_err(res)
62
67
  exec_err(res).each { |l|
63
68
  # Output comes back as an array and needs to be iterated or we lose our
@@ -0,0 +1,33 @@
1
+ module PDQTest
2
+ module Emoji
3
+ @@disable = false
4
+
5
+ def self.disable(disable)
6
+ @@disable = disable
7
+ end
8
+
9
+ # print cool emoji based on status
10
+ def self.emoji_status(status, emoji_pass, emoji_fail, label)
11
+ lable_string = "#{label}: "
12
+ if ! @@disable
13
+ if status
14
+ # cool bananas
15
+ Escort::Logger.output.puts lable_string + emoji_pass
16
+ else
17
+ # boom! crappy code
18
+ Escort::Logger.error.error lable_string + emoji_fail
19
+ end
20
+ end
21
+ end
22
+
23
+ # partial status when lots to do
24
+ def self.partial_status(status, label)
25
+ emoji_status(status, "😬", "💣", label)
26
+ end
27
+
28
+ # Overall program exit status
29
+ def self.final_status(status)
30
+ emoji_status(status, "😎", "💩", 'Overall')
31
+ end
32
+ end
33
+ end
@@ -26,16 +26,24 @@ module PDQTest
26
26
  Excon.defaults[:write_timeout] = 10000
27
27
  Excon.defaults[:read_timeout] = 10000
28
28
 
29
- @@active_container = PDQTest::Docker::new_container(TEST_DIR)
30
- Escort::Logger.output.puts "alive, running tests"
31
- status = PDQTest::Puppet.run(@@active_container, example)
29
+ # remove reference to any previous test container
30
+ @@active_container = nil
32
31
 
33
- if @@keep_container
34
- Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system"
35
- Escort::Logger.output.puts " docker exec -ti #{@@active_container.id} bash "
32
+ if PDQTest::Puppet::find_examples().empty?
33
+ Escort::Logger.output.puts "No acceptance tests found, annotate examples with #{PDQTest::Puppet::MAGIC_MARKER} to make some"
34
+ status = true
36
35
  else
37
- PDQTest::Docker.cleanup_container(@@active_container)
38
- @@active_container = nil
36
+ @@active_container = PDQTest::Docker::new_container(TEST_DIR)
37
+ Escort::Logger.output.puts "alive, running tests"
38
+ status = PDQTest::Puppet.run(@@active_container, example)
39
+
40
+ if @@keep_container
41
+ Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system"
42
+ Escort::Logger.output.puts " docker exec -ti #{@@active_container.id} bash "
43
+ else
44
+ PDQTest::Docker.cleanup_container(@@active_container)
45
+ @@active_container = nil
46
+ end
39
47
  end
40
48
  Escort::Logger.output.puts "...finished status=#{status}"
41
49
  status
data/lib/pdqtest/lint.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'pdqtest/emoji'
1
2
  module PDQTest
2
3
  module Lint
3
4
  LINT_PATHS = [
@@ -22,6 +23,7 @@ module PDQTest
22
23
  end
23
24
  }
24
25
 
26
+ PDQTest::Emoji.partial_status(status, 'Linter')
25
27
  status
26
28
  end
27
29
 
@@ -2,6 +2,7 @@ require 'pdqtest/puppet'
2
2
  require 'pdqtest/docker'
3
3
  require 'pdqtest/instance'
4
4
  require 'escort'
5
+ require 'yaml'
5
6
 
6
7
  module PDQTest
7
8
  class Puppet
@@ -18,6 +19,7 @@ module PDQTest
18
19
  CLASS_RE = /^class /
19
20
  @@bats_executed = []
20
21
  @@setup_executed = []
22
+ FIXTURES = '.fixtures.yml'
21
23
 
22
24
  def self.reset_bats_executed
23
25
  @@bats_executed = []
@@ -50,7 +52,12 @@ module PDQTest
50
52
 
51
53
  def self.install_deps
52
54
  # Install dependencies for module
53
- "cd #{PDQTest::Instance::TEST_DIR} && librarian-puppet install --path #{MODULE_DIR} --destructive"
55
+ steps = []
56
+ steps << "cd #{PDQTest::Instance::TEST_DIR}"
57
+ steps << "librarian-puppet install --path #{MODULE_DIR} --destructive"
58
+ steps + git_fixtures
59
+
60
+ steps.join(' && ')
54
61
  end
55
62
 
56
63
  def self.class2filename(c)
@@ -86,6 +93,33 @@ module PDQTest
86
93
  examples
87
94
  end
88
95
 
96
+ # process fixtures->repositories->* from .fixtures.yml if present to
97
+ # generate an array of commands to run ON THE DOCKER VM to checkout the
98
+ # required modules from git
99
+ def self.git_fixtures()
100
+ refresh_cmd = []
101
+ if File.exists?(FIXTURES)
102
+ fixtures = YAML.load_file(FIXTURES)
103
+ if fixtures.has_key?('repositories')
104
+ fixtures['repositories'].each { |fixture, opts|
105
+ if opts.instance_of?(String)
106
+ source = opts
107
+ target = "spec/fixtures/modules/#{fixture}"
108
+ ref = 'master'
109
+ elsif opts.instance_of?(Hash)
110
+ target = "spec/fixtures/modules/#{fixture}"
111
+ source = opts['repo']
112
+ ref = opts['ref']
113
+ end
114
+
115
+ refresh_cmd << "git_refresh #{target} #{source} #{ref}"
116
+ }
117
+ end
118
+ end
119
+
120
+ refresh_cmd
121
+ end
122
+
89
123
  # find the available classes in this module
90
124
  def self.find_classes()
91
125
  mod_name = module_name
@@ -192,26 +226,42 @@ module PDQTest
192
226
 
193
227
  def self.run(container, example=nil)
194
228
  status = true
195
- Escort::Logger.output.puts "fetch deps"
196
- res = PDQTest::Docker.exec(container, install_deps)
229
+ Escort::Logger.output.puts "...fetch deps"
230
+ cmd = install_deps
231
+ res = PDQTest::Docker.exec(container, cmd)
197
232
  status &= PDQTest::Docker.exec_status(res)
198
-
199
- Escort::Logger.output.puts "linking"
200
- res = PDQTest::Docker.exec(container, link_module)
201
- status &= PDQTest::Docker.exec_status(res)
202
- Escort::Logger.output.puts "run tests"
203
- if example
204
- status &= run_example(container, example)
205
- else
206
- find_examples.each { |e|
207
- if status
208
- status &= run_example(container, e)
233
+ if status
234
+ Escort::Logger.output.puts "...linking"
235
+ cmd = link_module
236
+ res = PDQTest::Docker.exec(container, cmd)
237
+ status &= PDQTest::Docker.exec_status(res)
238
+ if status
239
+ Escort::Logger.output.puts "...run tests"
240
+ if example
241
+ status &= run_example(container, example)
209
242
  if ! status
210
- Escort::Logger.error.error "Example #{e} failed! - skipping rest of tests"
243
+ Escort::Logger.error.error "Example #{example} failed!"
211
244
  end
245
+ else
246
+ find_examples.each { |e|
247
+ if status
248
+ status &= run_example(container, e)
249
+ if ! status
250
+ Escort::Logger.error.error "Example #{e} failed! - skipping rest of tests"
251
+ end
252
+ end
253
+ }
212
254
  end
213
- }
255
+ else
256
+ PDQTest::Docker.log_all(res)
257
+ Escort::Logger.error.error "Error linking module, see previous error, command was: #{cmd}"
258
+ end
259
+ else
260
+ PDQTest::Docker.log_all(res)
261
+ Escort::Logger.error.error "Error installing dependencies, see previous error, command was: #{cmd}"
214
262
  end
263
+
264
+ PDQTest::Emoji.partial_status(status, 'Puppet')
215
265
  status
216
266
  end
217
267
 
data/lib/pdqtest/rspec.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'pdqtest'
1
2
  require 'pdqtest/puppet'
2
3
  require 'pdqtest/util'
4
+ require 'pdqtest/emoji'
3
5
  require 'erb'
4
6
  module PDQTest
5
7
  module Rspec
@@ -8,8 +10,18 @@ module PDQTest
8
10
 
9
11
  def self.run
10
12
  status = system("bundle exec librarian-puppet install --path ./spec/fixtures/modules --destructive")
11
- status &= system("bundle exec rake spec")
13
+ PDQTest::Puppet.git_fixtures.each { |extra_mod_install_cmd|
14
+ if status
15
+ # fast-fail
16
+ status &= system("bundle exec #{extra_mod_install_cmd}")
17
+ end
18
+ }
19
+ if status
20
+ # fail fast on test execution
21
+ status &= system("bundle exec rake spec")
22
+ end
12
23
 
24
+ PDQTest::Emoji.partial_status(status, 'RSpec-Puppet')
13
25
  status
14
26
  end
15
27
 
@@ -1,8 +1,13 @@
1
1
  require 'puppet-syntax/tasks/puppet-syntax'
2
+ require 'pdqtest'
3
+ require 'pdqtest/emoji'
2
4
  module PDQTest
3
5
  module Syntax
4
6
  def self.puppet
5
- system("rake syntax")
7
+ status = system("rake syntax")
8
+ PDQTest::Emoji.partial_status(status, 'Syntax')
9
+
10
+ status
6
11
  end
7
12
  end
8
13
  end
@@ -1,3 +1,3 @@
1
1
  module PDQTest
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
data/pdqtest.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_runtime_dependency "puppet-syntax", "2.2.0"
36
36
  spec.add_runtime_dependency "puppetlabs_spec_helper", "1.2.2"
37
37
  spec.add_runtime_dependency "librarian-puppet", "2.2.3"
38
+ spec.add_runtime_dependency "git_refresh", "0.1.0"
38
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdqtest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
180
  version: 2.2.3
181
+ - !ruby/object:Gem::Dependency
182
+ name: git_refresh
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '='
186
+ - !ruby/object:Gem::Version
187
+ version: 0.1.0
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '='
193
+ - !ruby/object:Gem::Version
194
+ version: 0.1.0
181
195
  description: write one...
182
196
  email:
183
197
  - geoff.williams@puppetlabs.com
@@ -201,6 +215,7 @@ files:
201
215
  - lib/pdqtest.rb
202
216
  - lib/pdqtest/core.rb
203
217
  - lib/pdqtest/docker.rb
218
+ - lib/pdqtest/emoji.rb
204
219
  - lib/pdqtest/instance.rb
205
220
  - lib/pdqtest/lint.rb
206
221
  - lib/pdqtest/puppet.rb