control_spec_helper 0.0.1 → 0.0.2
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/.gitignore +5 -1
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +109 -0
- data/Rakefile +87 -8
- data/control_spec_helper.gemspec +22 -15
- data/ext/spec_helper_control.rb +8 -5
- data/lib/control_spec_helper/control_spec_helper.rb +49 -32
- data/lib/control_spec_helper/rake_tasks.rb +1 -157
- data/lib/control_spec_helper/version.rb +1 -1
- data/lib/rake_tasks.rb +4 -0
- data/lib/slalom.rb +60 -0
- data/lib/tasks/acceptance.rake +26 -0
- data/lib/tasks/apply.rake +7 -0
- data/lib/tasks/apply_debug.rake +7 -0
- data/lib/tasks/apply_dev.rake +7 -0
- data/lib/tasks/apply_noop.rake +6 -0
- data/lib/tasks/apply_standalone.rake +7 -0
- data/lib/tasks/default.rake +3 -0
- data/lib/tasks/git.rake +9 -0
- data/lib/tasks/help.rake +6 -0
- data/lib/tasks/hooks.rake +11 -0
- data/lib/tasks/lint.rake +26 -0
- data/lib/tasks/puppet_cmd.rake +6 -0
- data/lib/tasks/r10k.rake +6 -0
- data/lib/tasks/serverspec.rake +10 -0
- data/lib/tasks/spec.rake +10 -0
- data/lib/tasks/spec_clean.rake +6 -0
- data/lib/tasks/spec_prep.rake +10 -0
- data/lib/tasks/vplugins.rake +9 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/shared_contexts/rake.rb +26 -0
- data/spec/tasks/vplugins_spec.rb +71 -0
- data/spec/unit/class_from_path_spec.rb +62 -0
- data/spec/unit/control_spec_helper_spec.rb +62 -1
- data/spec/unit/debug_spec.rb +30 -0
- data/spec/unit/diff_from_base_spec.rb +34 -0
- data/spec/unit/diff_profile_spec.rb +38 -0
- data/spec/unit/diff_roles_spec.rb +38 -0
- data/spec/unit/profile_fixtures_spec.rb +185 -0
- data/spec/unit/project_root_spec.rb +45 -0
- data/spec/unit/r10k_spec.rb +58 -0
- data/spec/unit/spec_clean_spec.rb +137 -0
- data/spec/unit/spec_from_class_spec.rb +65 -0
- metadata +148 -30
@@ -1,158 +1,2 @@
|
|
1
|
-
# rubocop:disable Style/HashSyntax
|
2
|
-
require 'rake'
|
3
|
-
require 'rspec/core/rake_task'
|
4
1
|
require 'puppet-lint/tasks/puppet-lint'
|
5
|
-
|
6
|
-
|
7
|
-
task :default => [:help]
|
8
|
-
|
9
|
-
desc 'update repo from origin (destructive)'
|
10
|
-
task :git do
|
11
|
-
puts 'Updating puppet-control repo'
|
12
|
-
`git fetch --all`
|
13
|
-
`git checkout --track origin/cloud`
|
14
|
-
`git reset --hard origin/cloud`
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'install all modules from the Puppetfile (idempotent)'
|
18
|
-
task :r10k do
|
19
|
-
r10k
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'print the command used to run puppet'
|
23
|
-
task :puppet_cmd do
|
24
|
-
puts puppet_cmd
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'run puppet apply (enforce mode)'
|
28
|
-
task :apply => [:git, :r10k] do
|
29
|
-
puts "Running 'puppet apply'"
|
30
|
-
exec puppet_cmd
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'run puppet apply (no git)'
|
34
|
-
task :apply_dev => :r10k do
|
35
|
-
puts "Running 'puppet apply'"
|
36
|
-
exec puppet_cmd
|
37
|
-
end
|
38
|
-
|
39
|
-
desc 'run puppet apply (noop)'
|
40
|
-
task :apply_noop do
|
41
|
-
puts "Running 'puppet apply'"
|
42
|
-
exec "#{puppet_cmd} --noop"
|
43
|
-
end
|
44
|
-
|
45
|
-
desc 'run puppet apply (debug)'
|
46
|
-
task :apply_debug do
|
47
|
-
puts "Running 'puppet apply'"
|
48
|
-
exec "#{puppet_cmd} --debug --trace"
|
49
|
-
end
|
50
|
-
|
51
|
-
desc 'run puppet apply (no r10k or git)'
|
52
|
-
task :apply_standalone do
|
53
|
-
puts "Running 'puppet apply'"
|
54
|
-
exec "#{puppet_cmd} --debug --trace"
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'install or update pre-commit hook'
|
58
|
-
task :hooks do
|
59
|
-
include FileUtils
|
60
|
-
puts 'Installing pre-commit hook'
|
61
|
-
hook = File.join(project_root, 'scripts', 'pre-commit')
|
62
|
-
dest = File.join(project_root, '.git', 'hooks', 'pre-commit')
|
63
|
-
FileUtils.cp hook, dest
|
64
|
-
FileUtils.chmod 'a+x', dest
|
65
|
-
end
|
66
|
-
|
67
|
-
desc 'install Vagrant plugins'
|
68
|
-
task :vplugins do
|
69
|
-
exec 'vagrant plugin install vagrant-auto_network vagrant-hosts'
|
70
|
-
end
|
71
|
-
|
72
|
-
desc 'prep for spec tests'
|
73
|
-
task :spec_prep do
|
74
|
-
r10k
|
75
|
-
profile_fixtures
|
76
|
-
end
|
77
|
-
|
78
|
-
desc 'run unit tests'
|
79
|
-
task :spec do
|
80
|
-
Rake::Task['spec_prep'].invoke
|
81
|
-
Dir.chdir(profile_path) do
|
82
|
-
system 'bundle exec rake rspec'
|
83
|
-
end
|
84
|
-
Rake::Task['spec_clean'].invoke
|
85
|
-
end
|
86
|
-
|
87
|
-
desc 'clean up after unit tests'
|
88
|
-
task :spec_clean do
|
89
|
-
spec_clean
|
90
|
-
end
|
91
|
-
|
92
|
-
desc 'Run acceptance tests for 1 or more roles'
|
93
|
-
task :acceptance do
|
94
|
-
Rake::Task['spec_clean'].invoke
|
95
|
-
|
96
|
-
role = if ENV['role'] || ENV['roles']
|
97
|
-
(ENV['role'] || ENV['roles']).split(',')
|
98
|
-
elsif !diff_roles.empty?
|
99
|
-
diff_roles
|
100
|
-
else
|
101
|
-
puts 'no roles specified and no changes detected'
|
102
|
-
exit 0
|
103
|
-
end
|
104
|
-
|
105
|
-
puts "-- Acceptance tests for #{role.join(', ')} --"
|
106
|
-
paths = role.map do |klass|
|
107
|
-
if klass.match(/^role/)
|
108
|
-
spec_from_class(klass)
|
109
|
-
else
|
110
|
-
spec_from_class("role::#{klass}")
|
111
|
-
end
|
112
|
-
end.join(' ')
|
113
|
-
Dir.chdir(role_path) do
|
114
|
-
abort unless
|
115
|
-
system "bash -c 'bundle exec rspec --format documentation #{paths}'"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
desc 'Run acceptance tests locally from SUT'
|
120
|
-
task :serverspec do
|
121
|
-
Dir.chdir(role_path) do
|
122
|
-
if ENV['role']
|
123
|
-
role_spec = ENV['role']
|
124
|
-
else
|
125
|
-
role_spec = `facter role`.chomp.split('::').join('/')
|
126
|
-
end
|
127
|
-
ENV['serverspec'] = 'true'
|
128
|
-
system "rspec spec/acceptance/#{role_spec}_spec.rb"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Override default puppet-lint choices
|
133
|
-
# Must clear as it will not override the existing puppet-lint rake task since
|
134
|
-
# we require to import for the PuppetLint::RakeTask
|
135
|
-
Rake::Task[:lint].clear
|
136
|
-
# Relative is not able to be set within the context of PuppetLint::RakeTask
|
137
|
-
PuppetLint.configuration.relative = true
|
138
|
-
PuppetLint::RakeTask.new(:lint) do |config|
|
139
|
-
config.fail_on_warnings = true
|
140
|
-
config.disable_checks = %w(
|
141
|
-
80chars
|
142
|
-
class_inherits_from_params_class
|
143
|
-
class_parameter_defaults
|
144
|
-
documentation
|
145
|
-
)
|
146
|
-
config.ignore_paths = %w(
|
147
|
-
tests/**/*.pp
|
148
|
-
vendor/**/*.pp
|
149
|
-
examples/**/*.pp
|
150
|
-
spec/**/*.pp
|
151
|
-
pkg/**/*.pp
|
152
|
-
)
|
153
|
-
end
|
154
|
-
|
155
|
-
desc 'Display the list of available rake tasks'
|
156
|
-
task :help do
|
157
|
-
system('rake -T')
|
158
|
-
end
|
2
|
+
Dir.glob("#{File.dirname(__FILE__)}/../tasks/**/*.rake").each { |f| import f }
|
data/lib/rake_tasks.rb
ADDED
data/lib/slalom.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'etc'
|
3
|
+
|
4
|
+
def vagrant_ssh_config
|
5
|
+
config = {}
|
6
|
+
`unset RUBYLIB ; vagrant ssh-config --machine-readable`.split(',')[7]
|
7
|
+
.split('\n')[0..9].collect(&:lstrip)
|
8
|
+
.each do |element|
|
9
|
+
key, value = element.split(' ')
|
10
|
+
config[key] = value
|
11
|
+
end
|
12
|
+
config
|
13
|
+
end
|
14
|
+
|
15
|
+
# Helper method to separate ssh output into streams and error code
|
16
|
+
# Sample use:
|
17
|
+
# Net::SSH.start(server, Etc.getlogin) do |ssh|
|
18
|
+
# puts ssh_exec!(ssh, "true").inspect
|
19
|
+
# # => ["", "", 0, nil]
|
20
|
+
|
21
|
+
# puts ssh_exec!(ssh, "false").inspect
|
22
|
+
# # => ["", "", 1, nil]
|
23
|
+
# end
|
24
|
+
|
25
|
+
# rubocop:disable Metrics/AbcSize
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
27
|
+
def ssh_exec!(ssh, command)
|
28
|
+
stdout_data = ''
|
29
|
+
stderr_data = ''
|
30
|
+
exit_code = nil
|
31
|
+
exit_signal = nil
|
32
|
+
ssh.open_channel do |channel|
|
33
|
+
channel.exec(command) do |_ch, success|
|
34
|
+
unless success
|
35
|
+
abort 'FAILED: couldn\'t execute command (ssh.channel.exec)'
|
36
|
+
end
|
37
|
+
channel.on_data do |_ch, data|
|
38
|
+
stdout_data += data
|
39
|
+
puts stdout_data
|
40
|
+
end
|
41
|
+
|
42
|
+
channel.on_extended_data do |_ch, _type, data|
|
43
|
+
stderr_data += data
|
44
|
+
puts stderr_data
|
45
|
+
end
|
46
|
+
|
47
|
+
channel.on_request('exit-status') do |_ch, data|
|
48
|
+
exit_code = data.read_long
|
49
|
+
end
|
50
|
+
|
51
|
+
channel.on_request('exit-signal') do |_ch, data|
|
52
|
+
exit_signal = data.read_long
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ssh.loop
|
57
|
+
[stdout_data, stderr_data, exit_code, exit_signal]
|
58
|
+
end
|
59
|
+
# rubocop:enable Metrics/MethodLength
|
60
|
+
# rubocop:enable Metrics/AbcSize
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# lib/tasks/acceptance.rb
|
2
|
+
|
3
|
+
desc 'Run acceptance tests for 1 or more roles'
|
4
|
+
task acceptance: [:spec_clean] do
|
5
|
+
role = if ENV['role'] || ENV['roles']
|
6
|
+
(ENV['role'] || ENV['roles']).split(',')
|
7
|
+
elsif !diff_roles.empty?
|
8
|
+
diff_roles
|
9
|
+
else
|
10
|
+
puts 'no roles specified and no changes detected'
|
11
|
+
exit 0
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "-- Acceptance tests for #{role.join(', ')} --"
|
15
|
+
paths = role.map do |klass|
|
16
|
+
if klass =~ /^role/
|
17
|
+
spec_from_class(klass)
|
18
|
+
else
|
19
|
+
spec_from_class("role::#{klass}")
|
20
|
+
end
|
21
|
+
end.join(' ')
|
22
|
+
Dir.chdir(role_path) do
|
23
|
+
abort unless
|
24
|
+
system "bash -c 'bundle exec rspec --format documentation #{paths}'"
|
25
|
+
end
|
26
|
+
end
|
data/lib/tasks/git.rake
ADDED
data/lib/tasks/help.rake
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# lib/tasks/hooks.rb
|
2
|
+
|
3
|
+
desc 'install or update pre-commit hook'
|
4
|
+
task :hooks do
|
5
|
+
include FileUtils
|
6
|
+
puts 'Installing pre-commit hook'
|
7
|
+
hook = File.join(project_root, 'scripts', 'pre-commit')
|
8
|
+
dest = File.join(project_root, '.git', 'hooks', 'pre-commit')
|
9
|
+
FileUtils.cp hook, dest
|
10
|
+
FileUtils.chmod 'a+x', dest
|
11
|
+
end
|
data/lib/tasks/lint.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# lib/tasks/lint.rb
|
2
|
+
|
3
|
+
# Override default puppet-lint choices
|
4
|
+
# Must clear as it will not override the existing puppet-lint rake task since
|
5
|
+
# we require to import for the PuppetLint::RakeTask
|
6
|
+
require 'puppet-lint/tasks/puppet-lint'
|
7
|
+
|
8
|
+
Rake::Task[:lint].clear
|
9
|
+
# Relative is not able to be set within the context of PuppetLint::RakeTask
|
10
|
+
PuppetLint.configuration.relative = true
|
11
|
+
PuppetLint::RakeTask.new(:lint) do |config|
|
12
|
+
config.fail_on_warnings = true
|
13
|
+
config.disable_checks = %w(
|
14
|
+
80chars
|
15
|
+
class_inherits_from_params_class
|
16
|
+
class_parameter_defaults
|
17
|
+
documentation
|
18
|
+
)
|
19
|
+
config.ignore_paths = %w(
|
20
|
+
tests/**/*.pp
|
21
|
+
vendor/**/*.pp
|
22
|
+
examples/**/*.pp
|
23
|
+
spec/**/*.pp
|
24
|
+
pkg/**/*.pp
|
25
|
+
)
|
26
|
+
end
|
data/lib/tasks/r10k.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# lib/tasks/serverspec.rb
|
2
|
+
|
3
|
+
desc 'Run acceptance tests locally from SUT'
|
4
|
+
task :serverspec do
|
5
|
+
Dir.chdir(role_path) do
|
6
|
+
role_spec = ENV['role'] || `facter role`.chomp.split('::').join('/')
|
7
|
+
ENV['serverspec'] = 'true'
|
8
|
+
system "rspec spec/acceptance/#{role_spec}_spec.rb"
|
9
|
+
end
|
10
|
+
end
|
data/lib/tasks/spec.rake
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,13 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'rake'
|
2
3
|
require 'control_spec_helper'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'puppet-lint/tasks/puppet-lint'
|
6
|
+
require 'puppet-syntax/tasks/puppet-syntax'
|
7
|
+
|
8
|
+
# Dir.glob("#{File.dirname(__FILE__)}/../lib/tasks/**/*.rake")
|
9
|
+
# .each { |f| require f }
|
10
|
+
Dir.glob("#{File.dirname(__FILE__)}/support/shared_contexts/**/*.rb")
|
11
|
+
.each { |f| require f }
|
12
|
+
|
13
|
+
Rails_root = Pathname.new('..').expand_path(File.dirname(__FILE__))
|