control_spec_helper 0.0.2 → 0.0.3.pre

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.ruby-version +1 -1
  4. data/Gemfile.lock +57 -26
  5. data/Guardfile +1 -0
  6. data/Rakefile +141 -48
  7. data/bin/csh-generate +7 -0
  8. data/config/Guardfile +24 -0
  9. data/control_spec_helper.gemspec +9 -5
  10. data/ext/Rakefile.sample +0 -2
  11. data/ext/spec_helper_control.rb +2 -1
  12. data/lib/control_spec_helper/control_spec_helper.rb +22 -21
  13. data/lib/control_spec_helper/debug.rb +7 -0
  14. data/lib/control_spec_helper/generate.rb +79 -0
  15. data/lib/control_spec_helper/rake_tasks.rb +0 -1
  16. data/lib/{slalom.rb → control_spec_helper/util.rb} +22 -7
  17. data/lib/control_spec_helper/version.rb +1 -1
  18. data/lib/control_spec_helper.rb +2 -0
  19. data/lib/tasks/apply.rake +1 -1
  20. data/lib/tasks/lint.rake +2 -1
  21. data/lib/tasks/r10k.rake +1 -1
  22. data/lib/tasks/spec_prep.rake +0 -1
  23. data/lib/tasks/unit.rake +15 -0
  24. data/spec/spec_helper.rb +2 -2
  25. data/spec/support/shared_contexts/rake.rb +1 -1
  26. data/spec/tasks/apply_debug_spec.rb +72 -0
  27. data/spec/tasks/apply_spec.rb +72 -0
  28. data/spec/tasks/apply_standalone_spec.rb +73 -0
  29. data/spec/tasks/help_spec.rb +54 -0
  30. data/spec/tasks/lint_spec.rb +69 -0
  31. data/spec/tasks/puppet_cmd_spec.rb +55 -0
  32. data/spec/tasks/r10k_spec.rb +69 -0
  33. data/spec/tasks/spec_clean_spec.rb +61 -0
  34. data/spec/tasks/spec_prep_spec.rb +69 -0
  35. data/spec/tasks/unit_spec.rb +70 -0
  36. data/spec/tasks/vplugins_spec.rb +18 -25
  37. data/spec/unit/control_spec_helper_spec.rb +3 -3
  38. data/spec/unit/debug_spec.rb +2 -2
  39. data/spec/unit/profile_fixtures_spec.rb +111 -125
  40. data/spec/unit/r10k_spec.rb +7 -0
  41. metadata +106 -48
  42. data/lib/tasks/git.rake +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18bbd384c54c74eb7500a318c068b5d43b60a85f
4
- data.tar.gz: d44d869e7c98330024040ee22388f61e9ded4138
3
+ metadata.gz: b54bde90c4b319d0f9e2107ba26bf2780445860e
4
+ data.tar.gz: 92625f271ce558d64addee4e6668a6a2923bb24a
5
5
  SHA512:
6
- metadata.gz: ae8ce1c9f36c360f110b9dfc358d5510e96a096904a5533810c2fc8f6eb5715e168e1b86c7187a7c0647bc194d14d361ecde8aad959caa58ca0376ae3efe4f85
7
- data.tar.gz: 3a19bee071a8bf631ec03279da5848819cd0768858cf81b8cf654c32f6ffbf25b24cfe98a3274dcb47c4a71a704344ed2c1357fe291dc47e3315805485ea6dc7
6
+ metadata.gz: 91a175b0417e0497cd18799df712453201e0da0542462d29f5cb85030637de4d4d80f160754abef4d116923400d5db60ccef35c064e67c876fc9030f4f661934
7
+ data.tar.gz: a39b7cd2881c6bc1f307446ab3ec4bc3a8b868d1c48a40d800246a710c31431fd7338e667c5e645b144e7eeba980f6d8715d5620f8382ac0dd7eeb5d09885dde
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
1
  pkg/
2
2
  .*.sw
3
3
  *.swp
4
- fixtures/puppet-control/*
4
+ fixtures/*
5
5
  *.*~
6
6
  .bundle/*
7
7
  vendor/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.3.1
data/Gemfile.lock CHANGED
@@ -1,73 +1,105 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- control_spec_helper (0.0.2)
4
+ control_spec_helper (0.0.3.pre)
5
+ git (~> 1.3)
6
+ guard (~> 2.14)
7
+ guard-rspec (~> 4.7)
8
+ listen (= 3.1.1)
5
9
  mocha (~> 1.1)
10
+ net-ssh (~> 3.1)
6
11
  puppet (~> 4.0)
7
- puppet-lint (~> 1.1)
12
+ puppet-lint (~> 2.0)
8
13
  puppet-syntax (~> 2.1)
14
+ r10k (~> 2.2)
9
15
  rake (~> 11.0)
10
16
  rspec-puppet (~> 2.4)
17
+ rubocop (~> 0.39)
11
18
 
12
19
  GEM
13
20
  remote: https://rubygems.org/
14
21
  specs:
15
- CFPropertyList (2.2.8)
16
- ast (2.2.0)
22
+ ast (2.3.0)
17
23
  coderay (1.1.1)
18
24
  colored (1.2)
19
25
  cri (2.6.1)
20
26
  colored (~> 1.2)
21
27
  diff-lcs (1.2.5)
22
28
  facter (2.4.6)
23
- CFPropertyList (~> 2.2.6)
29
+ fakefs (0.8.1)
24
30
  faraday (0.9.2)
25
31
  multipart-post (>= 1.2, < 3)
26
32
  faraday_middleware (0.10.0)
27
33
  faraday (>= 0.7.4, < 0.10)
34
+ ffi (1.9.10)
35
+ formatador (0.2.5)
28
36
  git (1.3.0)
29
- hiera (3.1.2)
37
+ guard (2.14.0)
38
+ formatador (>= 0.2.4)
39
+ listen (>= 2.7, < 4.0)
40
+ lumberjack (~> 1.0)
41
+ nenv (~> 0.1)
42
+ notiffany (~> 0.0)
43
+ pry (>= 0.9.12)
44
+ shellany (~> 0.0)
45
+ thor (>= 0.18.1)
46
+ guard-compat (1.2.1)
47
+ guard-rspec (4.7.2)
48
+ guard (~> 2.1)
49
+ guard-compat (~> 1.1)
50
+ rspec (>= 2.99.0, < 4.0)
51
+ hiera (3.2.0)
30
52
  json_pure
31
53
  json_pure (1.8.3)
54
+ listen (3.1.1)
55
+ rb-fsevent (>= 0.9.3)
56
+ rb-inotify (>= 0.9.7)
32
57
  log4r (1.1.10)
58
+ lumberjack (1.0.10)
33
59
  metaclass (0.0.4)
34
60
  method_source (0.8.2)
35
61
  minitar (0.5.4)
36
62
  mocha (1.1.0)
37
63
  metaclass (~> 0.0.1)
38
- multi_json (1.11.3)
64
+ multi_json (1.12.1)
39
65
  multipart-post (2.0.0)
40
- net-ssh (3.1.1)
41
- parser (2.3.1.0)
66
+ nenv (0.3.0)
67
+ net-ssh (3.2.0)
68
+ notiffany (0.1.0)
69
+ nenv (~> 0.1)
70
+ shellany (~> 0.0)
71
+ parser (2.3.1.2)
42
72
  ast (~> 2.2)
43
73
  powerpack (0.1.1)
44
74
  pry (0.10.3)
45
75
  coderay (~> 1.1.0)
46
76
  method_source (~> 0.8.1)
47
77
  slop (~> 3.4)
48
- puppet (4.4.2)
49
- CFPropertyList (~> 2.2.6)
78
+ puppet (4.5.2)
50
79
  facter (> 2.0, < 4)
51
80
  hiera (>= 2.0, < 4)
52
81
  json_pure
53
- puppet-lint (1.1.0)
82
+ puppet-lint (2.0.0)
54
83
  puppet-syntax (2.1.0)
55
84
  rake
56
- puppet_forge (2.1.5)
85
+ puppet_forge (2.2.1)
57
86
  faraday (~> 0.9.0)
58
87
  faraday_middleware (>= 0.9.0, < 0.11.0)
59
88
  minitar
60
89
  semantic_puppet (~> 0.1.0)
61
- r10k (2.2.2)
90
+ r10k (2.3.0)
62
91
  colored (= 1.2)
63
92
  cri (~> 2.6.1)
64
93
  log4r (= 1.1.10)
65
94
  minitar
66
95
  multi_json (~> 1.10)
67
- puppet_forge (~> 2.1.5)
96
+ puppet_forge (~> 2.2)
68
97
  semantic_puppet (~> 0.1.0)
69
98
  rainbow (2.1.0)
70
- rake (11.1.2)
99
+ rake (11.2.2)
100
+ rb-fsevent (0.9.7)
101
+ rb-inotify (0.9.7)
102
+ ffi (>= 0.5.0)
71
103
  rspec (3.4.0)
72
104
  rspec-core (~> 3.4.0)
73
105
  rspec-expectations (~> 3.4.0)
@@ -83,27 +115,26 @@ GEM
83
115
  rspec-puppet (2.4.0)
84
116
  rspec
85
117
  rspec-support (3.4.1)
86
- rubocop (0.39.0)
87
- parser (>= 2.3.0.7, < 3.0)
118
+ rubocop (0.40.0)
119
+ parser (>= 2.3.1.0, < 3.0)
88
120
  powerpack (~> 0.1)
89
121
  rainbow (>= 1.99.1, < 3.0)
90
122
  ruby-progressbar (~> 1.7)
91
123
  unicode-display_width (~> 1.0, >= 1.0.1)
92
- ruby-progressbar (1.8.0)
93
- semantic_puppet (0.1.1)
124
+ ruby-progressbar (1.8.1)
125
+ semantic_puppet (0.1.3)
126
+ shellany (0.0.1)
94
127
  slop (3.6.0)
95
- unicode-display_width (1.0.3)
128
+ thor (0.19.1)
129
+ unicode-display_width (1.1.0)
96
130
 
97
131
  PLATFORMS
98
132
  ruby
99
133
 
100
134
  DEPENDENCIES
101
135
  control_spec_helper!
102
- git (~> 1.3)
103
- net-ssh (~> 3.1)
136
+ fakefs (~> 0.8)
104
137
  pry (~> 0.10)
105
- r10k (~> 2.2)
106
- rubocop (~> 0.39)
107
138
 
108
139
  BUNDLED WITH
109
- 1.11.2
140
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1 @@
1
+ config/Guardfile
data/Rakefile CHANGED
@@ -4,7 +4,8 @@ require 'rubygems/package_task'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'git'
6
6
  require 'net/ssh'
7
- require './lib/slalom'
7
+ require 'English'
8
+ require 'control_spec_helper/util'
8
9
 
9
10
  task :default do
10
11
  sh %(rake -T)
@@ -54,62 +55,154 @@ namespace :fixtures do
54
55
  FileUtils.mkdir('fixtures') unless File.directory?('fixtures')
55
56
  end
56
57
 
58
+ task :shared_prep do
59
+ unless File.exist?('fixtures/puppet-control')
60
+ puts 'Cloning puppet_control repository...'
61
+ Git.clone('https://github.com/slalompdx/puppet-control.git',
62
+ 'puppet-control',
63
+ path: 'fixtures',
64
+ branch: 'fixture')
65
+ end
66
+ end
67
+
57
68
  desc 'Remove fixtures directory'
58
69
  task :clean do
70
+ if File.exist?('fixtures/puppet-control')
71
+ Dir.chdir('fixtures/puppet-control') do
72
+ `unset RUBYLIB ; vagrant destroy -f`
73
+ end
74
+ end
59
75
  FileUtils.rm_rf('fixtures')
60
76
  end
61
77
 
62
- desc 'Prepare fixtures repository'
63
- task prep: [:create, 'package:gem'] do
64
- begin
65
- unless File.exist?('fixtures/puppet-control')
66
- puts 'Cloning puppet_control repository...'
67
- Git.clone('https://github.com/slalompdx/puppet-control.git',
68
- 'puppet-control',
69
- path: 'fixtures',
70
- branch: 'fixture')
78
+ desc 'Bring up test vm'
79
+ task vm: [:create, 'package:gem', :shared_prep] do
80
+ Bundler.with_clean_env do
81
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
82
+ puts 'Bringing up test VM...'
83
+ IO.popen('unset RUBYLIB ; vagrant up') do |io|
84
+ io.each { |s| print s }
85
+ end
71
86
  end
72
- Bundler.with_clean_env do
73
- Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
74
- puts 'Copying control_spec_helper into fixtures'
75
- FileUtils.mkdir(
76
- "#{File.dirname(__FILE__)}/fixtures/puppet-control/csh"
77
- ) unless File.exist?(
78
- "#{File.dirname(__FILE__)}/fixtures/puppet-control/csh"
79
- )
80
- FileUtils.cp(
81
- "#{File.dirname(__FILE__)}/pkg/control_spec_helper-#{version}.gem",
82
- "#{File.dirname(__FILE__)}/fixtures/puppet-control/csh"
87
+ end
88
+ end
89
+
90
+ desc 'Copy built gem into fixtures directory'
91
+ task copy_gem: [:create, 'package:gem', :shared_prep] do
92
+ Bundler.with_clean_env do
93
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
94
+ puts 'Copying control_spec_helper into fixtures'
95
+ FileUtils.mkdir_p('./vendor/cache') unless File.exist?('./vendor/cache')
96
+ FileUtils.mkdir_p('./vendor/gems') unless File.exist?('./vendor/gems')
97
+ FileUtils.cp("../../pkg/control_spec_helper-#{version}.gem",
98
+ './vendor/cache')
99
+ `gem unpack \
100
+ ./vendor/cache/*.gem \
101
+ --target=./fixtures/puppet-control/vendor/gems/`
102
+ end
103
+ end
104
+ end
105
+
106
+ desc 'Install control_spec_helper gem on client vm'
107
+ task install_gem: [:copy_gem] do
108
+ Bundler.with_clean_env do
109
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
110
+ connection = build_vagrant_connection(vagrant_ssh_config)
111
+ puts 'Installing control_spec_helper gem...'
112
+ ssh_exec!(
113
+ connection,
114
+ 'cd /vagrant && gem install ./vendor/cache/*.gem --no-ri --no-rdoc'
115
+ )
116
+ connection.close
117
+ end
118
+ end
119
+ end
120
+
121
+ desc 'Run bundle install on client vm'
122
+ task bundle_install: [:install_gem] do
123
+ Bundler.with_clean_env do
124
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
125
+ connection = build_vagrant_connection(vagrant_ssh_config)
126
+ puts 'Running bundle install...'
127
+ ssh_exec!(connection, 'cd /vagrant && bundle install --path=vendor/')
128
+ connection.close
129
+ end
130
+ end
131
+ end
132
+
133
+ desc 'Install vagrant on client vm'
134
+ task install_vagrant: [:vm] do
135
+ Bundler.with_clean_env do
136
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
137
+ connection = build_vagrant_connection(vagrant_ssh_config)
138
+ response = ssh_exec!(connection, 'rpm -qa | grep vagrant')
139
+ if response[2] != 0
140
+ puts 'Installing vagrant...'
141
+ ssh_exec!(
142
+ connection,
143
+ 'sudo rpm -ivh https://releases.hashicorp.com/'\
144
+ 'vagrant/1.8.1/vagrant_1.8.1_x86_64.rpm'
83
145
  )
84
- FileUtils.mkdir_p("#{File.dirname(__FILE__)}/fixtures/"\
85
- 'puppet-control/vendor/gems')
86
- `gem unpack \
87
- #{File.dirname(__FILE__)}/fixtures/puppet-control/csh/*.gem \
88
- --target=./fixtures/puppet-control/vendor/gems/`
89
- puts 'Bringing up test VM...'
90
- IO.popen('unset RUBYLIB ; vagrant up') do |io|
91
- io.each { |s| print s }
92
- end
93
- c = vagrant_ssh_config
94
- Net::SSH.start(
95
- c['HostName'],
96
- c['User'],
97
- port: c['Port'],
98
- password: 'vagrant'
99
- ) do |ssh|
100
- puts 'Installing control_spec_helper gem...'
101
- ssh.exec!(
102
- 'cd /vagrant && gem install ./csh/*.gem --no-ri --no-rdoc'
103
- )
104
- puts 'Running bundle install...'
105
- ssh.exec!('cd /vagrant && bundle install')
106
- puts 'Installing vagrant...'
107
- puts ssh.exec!('sudo rpm -ivh https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1_x86_64.rpm')
108
- end
146
+ else
147
+ puts 'Skipping vagrant install, already present...'
109
148
  end
110
149
  end
111
- ensure
112
- `bundle config --delete local.control_spec_helper`
113
150
  end
114
151
  end
152
+
153
+ desc 'Link puppet binary on client vm'
154
+ task link_puppet: [:vm] do
155
+ Bundler.with_clean_env do
156
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
157
+ connection = build_vagrant_connection(vagrant_ssh_config)
158
+ puts 'Linking puppet binary...'
159
+ ssh_exec!(connection,
160
+ 'sudo ls /usr/bin/puppet || '\
161
+ 'sudo ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet'
162
+ )
163
+ connection.close
164
+ end
165
+ end
166
+ end
167
+
168
+ desc 'Run r10k on client vm'
169
+ task run_r10k: [:vm] do
170
+ Bundler.with_clean_env do
171
+ Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
172
+ connection = build_vagrant_connection(vagrant_ssh_config)
173
+ puts 'Running r10k on vm...'
174
+ ssh_exec!(connection,
175
+ 'cd /vagrant ; bundle exec rake r10k')
176
+ connection.close
177
+ end
178
+ end
179
+ end
180
+ desc 'Convenience method - Update gem on existing vm'
181
+ task :update_gem do
182
+ Rake::Task['package:gem'].invoke
183
+ Rake::Task['fixtures:copy_gem'].invoke
184
+ Rake::Task['fixtures:install_gem'].invoke
185
+ Rake::Task['fixtures:bundle_install'].invoke
186
+ end
187
+
188
+ desc 'Prepare fixtures repository'
189
+ task prep: [:create, 'package:gem', :shared_prep] do
190
+ Rake::Task['fixtures:vm'].invoke
191
+ Rake::Task['fixtures:copy_gem'].invoke
192
+ Rake::Task['fixtures:install_gem'].invoke
193
+ Rake::Task['fixtures:bundle_install'].invoke
194
+ Rake::Task['fixtures:install_vagrant'].invoke
195
+ Rake::Task['fixtures:link_puppet'].invoke
196
+ Rake::Task['fixtures:run_r10k'].invoke
197
+ end
198
+ end
199
+
200
+ desc 'Execute unit tests'
201
+ task unit: ['fixtures:shared_prep'] do
202
+ exec 'bundle exec rspec -P spec/unit/*_spec.rb'
203
+ end
204
+
205
+ desc 'Execute acceptance tests'
206
+ task acceptance: ['fixtures:prep'] do
207
+ exec 'bundle exec rspec -P spec/tasks/*_spec.rb'
115
208
  end
data/bin/csh-generate ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'control_spec_helper/generate'
4
+
5
+ ControlSpecHelper::Generate.skeleton
6
+
7
+ # vi:ft=ruby
data/config/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ rspec_options = {
2
+ cmd: 'bundle exec rspec',
3
+ run_all: { cmd: 'bundle exec rspec -P spec/unit/*_spec.rb' }
4
+ }
5
+
6
+ guard :rspec, rspec_options do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+
20
+ # Rake files
21
+ watch(%r{lib/tasks/.+\.rake})
22
+ end
23
+
24
+ # vi:ft=ruby
@@ -22,12 +22,16 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency 'rake', '~> 11.0'
23
23
  s.add_runtime_dependency 'rspec-puppet', '~> 2.4'
24
24
  s.add_runtime_dependency 'puppet', '~> 4.0'
25
- s.add_runtime_dependency 'puppet-lint', '~> 1.1'
26
25
  s.add_runtime_dependency 'puppet-syntax', '~> 2.1'
27
26
  s.add_runtime_dependency 'mocha', '~> 1.1'
27
+ s.add_runtime_dependency 'git', '~> 1.3'
28
+ s.add_runtime_dependency 'rubocop', '~> 0.39'
29
+ s.add_runtime_dependency 'r10k', '~> 2.2'
30
+ s.add_runtime_dependency 'net-ssh', '~> 3.1'
31
+ s.add_runtime_dependency 'listen', '3.1.1'
32
+ s.add_runtime_dependency 'guard', '~> 2.14'
33
+ s.add_runtime_dependency 'guard-rspec', '~> 4.7'
34
+ s.add_runtime_dependency 'puppet-lint', '~> 2.0'
28
35
  s.add_development_dependency 'pry', '~> 0.10'
29
- s.add_development_dependency 'git', '~> 1.3'
30
- s.add_development_dependency 'rubocop', '~> 0.39'
31
- s.add_development_dependency 'r10k', '~> 2.2'
32
- s.add_development_dependency 'net-ssh', '~> 3.1'
36
+ s.add_development_dependency 'fakefs', '~> 0.8'
33
37
  end
data/ext/Rakefile.sample CHANGED
@@ -1,5 +1,3 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
-
3
1
  require 'control_spec_helper/control_spec_helper'
4
2
  require 'control_spec_helper/rake_tasks'
5
3
  require 'puppet-lint/tasks/puppet-lint'
@@ -11,7 +11,8 @@ else
11
11
  RSpec.configure do |c|
12
12
  # Project root
13
13
  proj_root = File.expand_path(
14
- File.join(File.dirname(__FILE__), '..', '..', '..'))
14
+ File.join(File.dirname(__FILE__), '..', '..', '..')
15
+ )
15
16
 
16
17
  # Readable test descriptions
17
18
  c.formatter = :documentation
@@ -1,7 +1,12 @@
1
1
  # rubocop:disable Metrics/ModuleLength
2
2
 
3
+ require 'English'
4
+ require 'control_spec_helper/debug'
5
+
3
6
  # Test control repositories, similar to puppetlabs_spec_helper
4
7
  module ControlSpecHelper
8
+ include ControlSpecHelper::Debug
9
+
5
10
  attr_writer :basepath, :basebranch, :root
6
11
 
7
12
  def file_name
@@ -16,19 +21,15 @@ module ControlSpecHelper
16
21
  @basebranch ||= 'master'
17
22
  end
18
23
 
19
- def debug(msg)
20
- $stderr.puts "DEBUG: #{msg}" unless ENV['debug'].nil?
21
- end
22
-
23
24
  def puppet_cmd
24
- 'puppet apply manifests/site.pp \
25
+ 'sudo puppet apply manifests/site.pp \
25
26
  --modulepath $(echo `pwd`/modules:`pwd`/site) --hiera_config hiera.yaml'
26
27
  end
27
28
 
28
29
  def project_root
29
30
  return @root if @root
30
31
  @root = `git rev-parse --show-toplevel`.chomp
31
- debug("project_root = #{@root}")
32
+ Debug.log("project_root = #{@root}")
32
33
  @root
33
34
  end
34
35
 
@@ -70,13 +71,13 @@ module ControlSpecHelper
70
71
  def roles_that_include(klass)
71
72
  roles = ''
72
73
  Dir.chdir(role_path) do
73
- debug("cd to #{role_path}")
74
+ Debug.log("cd to #{role_path}")
74
75
  roles = `git grep -l #{klass}`
75
76
  .split("\n")
76
77
  .map { |path| class_from_path(File.join(role_path, path)) }
77
78
  .compact
78
79
  end
79
- debug "cd to #{Dir.pwd}"
80
+ Debug.log "cd to #{Dir.pwd}"
80
81
  roles
81
82
  end
82
83
 
@@ -101,35 +102,35 @@ module ControlSpecHelper
101
102
  end
102
103
 
103
104
  def r10k
105
+ Debug.log "cd to #{Dir.pwd}"
104
106
  Dir.chdir(project_root) do
105
- debug("cd to #{project_root}")
107
+ Debug.log("cd to #{project_root}")
106
108
  puts 'Installing modules with r10k'
107
109
  `r10k puppetfile install`
108
110
  end
109
- debug "cd to #{Dir.pwd}"
111
+ $CHILD_STATUS.exitstatus
110
112
  end
111
113
 
112
114
  # rubocop:disable Metrics/AbcSize
113
115
  # rubocop:disable Metrics/MethodLength
114
116
  def profile_fixtures
115
117
  Dir.chdir(profile_path) do
116
- debug(ENV['debug'])
117
- debug("cd to #{profile_path}")
118
- profile_ln = "#{File.dirname(file_name)}/spec/fixtures/modules/profile"
118
+ Debug.log("cd to #{profile_path}")
119
+ profile_ln = "#{Dir.pwd}/spec/fixtures/modules/profile"
119
120
 
120
- FileUtils.mkpath "#{File.dirname(file_name)}/spec/fixtures/modules/"
121
+ FileUtils.mkpath "#{Dir.pwd}/spec/fixtures/modules/"
121
122
  File.symlink(profile_path, profile_ln) unless File.exist?(profile_ln)
122
123
 
123
- Dir.glob("#{File.dirname(file_name)}/../../modules/*").each do |folder|
124
+ Dir.glob("#{Dir.pwd}/../../modules/*").each do |folder|
124
125
  next unless File.directory?(folder)
125
- old_path = File.join(File.dirname(file_name), folder)
126
- new_path = "#{File.dirname(file_name)}/spec/fixtures/modules/" \
126
+ old_path = File.join(profile_path, '..', '..', 'modules',
127
+ File.basename(folder))
128
+ new_path = "#{Dir.pwd}/spec/fixtures/modules/" \
127
129
  "#{File.basename(folder)}"
128
-
129
130
  File.symlink(old_path, new_path) unless File.symlink?(new_path)
130
131
  end
131
132
  end
132
- debug "cd to #{Dir.pwd}"
133
+ Debug.log "cd to #{Dir.pwd}"
133
134
  end
134
135
  # rubocop:enable Metrics/MethodLength
135
136
  # rubocop:enable Metrics/AbcSize
@@ -137,7 +138,7 @@ module ControlSpecHelper
137
138
  # rubocop:disable Metrics/AbcSize
138
139
  def spec_clean
139
140
  Dir.chdir(project_root) do
140
- debug("cd to #{project_root}")
141
+ Debug.log("cd to #{project_root}")
141
142
  fixtures = File.join(profile_path, 'spec', 'fixtures', 'modules')
142
143
  modules = File.join(project_root, 'modules')
143
144
 
@@ -147,7 +148,7 @@ module ControlSpecHelper
147
148
  FileUtils.rm_rf(fixtures)
148
149
  FileUtils.rm_rf(modules)
149
150
  end
150
- debug "cd to #{Dir.pwd}"
151
+ Debug.log "cd to #{Dir.pwd}"
151
152
  end
152
153
  # rubocop:enable Metrics/AbcSize
153
154
  end
@@ -0,0 +1,7 @@
1
+ module ControlSpecHelper
2
+ module Debug
3
+ def self.log(msg)
4
+ $stderr.puts "DEBUG: #{msg}" unless ENV['debug'].nil?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,79 @@
1
+ require 'fileutils'
2
+
3
+ module ControlSpecHelper
4
+ module Generate
5
+ def self.skeleton
6
+ dirs = [
7
+ File.join('site', ''),
8
+ File.join('site', 'profile', ''),
9
+ File.join('site', 'role', ''),
10
+ File.join('site', 'profile', 'manifests', ''),
11
+ File.join('site', 'profile', 'spec', ''),
12
+ File.join('site', 'role', 'manifests', ''),
13
+ File.join('site', 'role', 'spec', '')
14
+ ]
15
+
16
+ files = {
17
+ '.gitignore' => <<-HEREDOC,
18
+ .bundle/
19
+ .vagrant/
20
+ HEREDOC
21
+ 'Puppetfile' => <<-HEREDOC,
22
+ mod 'puppetlabs/stdlib'
23
+ HEREDOC
24
+ 'Rakefile' => <<-HEREDOC,
25
+ require 'control_spec_helper/control_spec_helper'
26
+ require 'control_spec_helper/rake_tasks'
27
+ require 'puppet-lint/tasks/puppet-lint'
28
+
29
+ include ControlSpecHelper
30
+ HEREDOC
31
+
32
+ File.join('site', 'profile', 'spec', 'spec_helper.rb') => <<-HEREDOC,
33
+ require 'rspec-puppet'
34
+
35
+ fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
36
+
37
+ RSpec.configure do |c|
38
+ c.module_path = File.join(fixture_path, 'modules')
39
+ c.manifest_dir = File.join(fixture_path, 'manifests')
40
+ end
41
+ HEREDOC
42
+
43
+ File.join('site', 'role', 'spec', 'spec_helper.rb') => <<-HEREDOC,
44
+ require 'rspec-puppet'
45
+
46
+ fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
47
+
48
+ RSpec.configure do |c|
49
+ c.module_path = File.join(fixture_path, 'modules')
50
+ c.manifest_dir = File.join(fixture_path, 'manifests')
51
+ end
52
+ HEREDOC
53
+ }
54
+
55
+ cwd = Dir.pwd
56
+ answer = ''
57
+
58
+ until answer =~ /ye?s?/i
59
+ print "Create control repo skeleton in #{cwd}? (yN) "
60
+ answer = $stdin.gets.chomp
61
+ abort 'Exiting...' if answer =~ /no?/i || answer.empty?
62
+ end
63
+
64
+ puts 'Creating skeleton...'
65
+
66
+ dirs.each do |path|
67
+ Dir.chdir(cwd) { FileUtils.mkdir_p(path) }
68
+ end
69
+
70
+ files.each do |path, content|
71
+ Dir.chdir(cwd) do
72
+ f = File.new(path, 'w')
73
+ f.puts content
74
+ f.close
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end