beaker-rspec 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2JlNjhkMWE1ZDc4NjRkMjJjY2RmMzg1MWE4YTI2ZTVkNTg5OWViNg==
5
- data.tar.gz: !binary |-
6
- ODBmYzkwODQyYzFkNzlhYWRiNWJkNTJjOTVlZDg1YzMzZWI2MWYxNA==
2
+ SHA1:
3
+ metadata.gz: 8380fa2b5f1c758616697cd232219138a0a1859a
4
+ data.tar.gz: 78294a37a2b4d1c8e13f11ac59af7fa4588195cd
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTMzNzI5MTY3YTQ2ZGI0MjA4ZDU1ZmFlNmY1MjE3NDliMTljNjEzNGVmNjBj
10
- NDI1MmRmNTk4N2JhMzRiMmExMDRkZGM2Y2JhYmE0MTg1ZjhlZjk0ZGM4ODMy
11
- ZjdlYTQ2NTM2ZWQzYzIxZDkyZjFkNjUzYjJlOTU0MGE2NTRlNmU=
12
- data.tar.gz: !binary |-
13
- MTU2MDA0NzkwOGQwOWMyYTVkMDE1YWU0ZDM5MTRjODFiODAyYzQ1M2JiMmYw
14
- NTE2OTdkMjk3NDM1YzBhYWUwNDdjOTg2YWY1ZDFlZDEzY2QxZTA2ODQyNTZk
15
- MTYxNDE0MjVmMjNlNmY2ZWFlOTI5ODJkYTE1ZWZhZjM3YWVhMGY=
6
+ metadata.gz: 1355bd2ff61b7c4399983ab9839d2294cc423098bd336e97b3b21b77eff24578d1b449b5f37248b866774d8d3009bcfb5e4a1caa50f46000cadffffe2e66acd2
7
+ data.tar.gz: 826c814f863aa16e7a85e2bca368ed731a15f0c1439a6503d2c07acffdbc643a80547f090d8bc309cbccf0355bbbc4b4222b785bbbf77c2d248560d19a006d7d
data/beaker-rspec.gemspec CHANGED
@@ -6,7 +6,7 @@ less_than_one_nine = ruby_conf['MAJOR'].to_i == 1 && ruby_conf['MINOR'].to_i < 9
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "beaker-rspec"
9
- s.version = '5.0.0'
9
+ s.version = '5.0.1'
10
10
  s.authors = ["Puppetlabs"]
11
11
  s.email = ["sqa@puppetlabs.com"]
12
12
  s.homepage = "https://github.com/puppetlabs/beaker-rspec"
@@ -62,6 +62,12 @@ module BeakerRSpec
62
62
  RSpec.configuration.hosts
63
63
  end
64
64
 
65
+ # Accessor for default node
66
+ # @return [Beaker::Host]
67
+ def default_node
68
+ RSpec.configuration.default_node ||= find_only_one :default
69
+ end
70
+
65
71
  # Cleanup the testing framework, shut down test boxen and tidy up
66
72
  def cleanup
67
73
  @network_manager.cleanup
@@ -1,8 +1,39 @@
1
1
  require 'serverspec'
2
2
  require 'specinfra'
3
+ require 'specinfra/backend/powershell/script_helper'
3
4
 
4
5
  # Set specinfra backend to use our custom backend
5
- set :backend, 'BeakerExec'
6
+ set :backend, 'BeakerDispatch'
7
+
8
+ module Specinfra
9
+
10
+ # Accessor for current example
11
+ def cur_example
12
+ Specinfra.backend.example
13
+ end
14
+
15
+ def get_working_node
16
+ example = cur_example
17
+ if example and example.metadata[:node]
18
+ node = example.metadata[:node]
19
+ else
20
+ node = default_node
21
+ end
22
+ node
23
+ end
24
+
25
+ # The cygwin backend
26
+ def cygwin_backend
27
+ @cygwin_backend ||= Specinfra::Backend::BeakerCygwin.instance
28
+ end
29
+
30
+ # Backend for everything non-cygwin
31
+ def exec_backend
32
+ @exec_backend ||= Specinfra::Backend::BeakerExec.instance
33
+ end
34
+
35
+ end
36
+
6
37
 
7
38
  # Override existing specinfra configuration to avoid conflicts
8
39
  # with beaker's shell, stdout, stderr defines
@@ -25,38 +56,129 @@ module Specinfra
25
56
  :dockerfile_finalizer,
26
57
  ].freeze
27
58
  end
59
+
28
60
  end
29
61
  end
30
62
 
31
- module Specinfra::Backend
32
- class BeakerExec < Specinfra::Backend::Base
33
- # Run a command using serverspec. Defaults to running on the 'default' test node, otherwise uses the
34
- # node specified in @example.metadata[:node]
35
- # @param [String] cmd The serverspec command to executed
36
- # @param [Hash] opt No currently supported options
37
- # @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
38
- def run_command(cmd, opt={})
39
- cmd = build_command(cmd)
40
- cmd = add_pre_command(cmd)
41
- ret = ssh_exec!(cmd)
63
+ module Specinfra::Helper::Os
64
+ private
42
65
 
43
- if @example
44
- @example.metadata[:command] = cmd
45
- @example.metadata[:stdout] = ret[:stdout]
66
+ # Override detect_os to look at the node platform, short circuit discoverability
67
+ # when we know that we have a windows node
68
+ def detect_os
69
+ return Specinfra.configuration.os if Specinfra.configuration.os
70
+ backend = Specinfra.backend
71
+ node = get_working_node
72
+ if node['platform'] =~ /windows/
73
+ return {:family => 'windows'}
74
+ end
75
+ Specinfra::Helper::DetectOs.subclasses.each do |c|
76
+ res = c.detect
77
+ if res
78
+ res[:arch] ||= Specinfra.backend.run_command('uname -m').stdout.strip
79
+ return res
46
80
  end
81
+ end
82
+ end
83
+ end
47
84
 
48
- CommandResult.new ret
85
+ class Specinfra::CommandFactory
86
+ class << self
87
+ # Force creation of a windows command
88
+ def get_windows_cmd(meth, *args)
89
+
90
+ action, resource_type, subaction = breakdown(meth)
91
+ method = action
92
+ method += "_#{subaction}" if subaction
93
+
94
+ common_class = Specinfra::Command
95
+ base_class = common_class.const_get('Base')
96
+ os_class = common_class.const_get('Windows')
97
+ version_class = os_class.const_get('Base')
98
+ command_class = version_class.const_get(resource_type.to_camel_case)
99
+
100
+ command_class = command_class.create
101
+ if command_class.respond_to?(method)
102
+ command_class.send(method, *args)
103
+ else
104
+ raise NotImplementedError.new("#{method} is not implemented in #{command_class}")
105
+ end
106
+ end
107
+
108
+ end
109
+ end
110
+
111
+ module Specinfra
112
+ # Rewrite the runner to use the appropriate backend based upon platform information
113
+ class Runner
114
+
115
+ def self.method_missing(meth, *args)
116
+ backend = Specinfra.backend
117
+ node = get_working_node
118
+ if node['platform'] !~ /windows/
119
+ processor = Specinfra::Processor
120
+ if processor.respond_to?(meth)
121
+ processor.send(meth, *args)
122
+ elsif backend.respond_to?(meth)
123
+ backend.send(meth, *args)
124
+ else
125
+ run(meth, *args)
126
+ end
127
+ else
128
+ if backend.respond_to?(meth)
129
+ backend.send(meth, *args)
130
+ else
131
+ run(meth, *args)
132
+ end
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def self.run(meth, *args)
139
+ backend = Specinfra.backend
140
+ node = get_working_node
141
+ if node['platform'] =~ /windows/
142
+ cmd = Specinfra.command.get_windows_cmd(meth, *args)
143
+ else
144
+ cmd = Specinfra.command.get(meth, *args)
145
+ end
146
+ backend = Specinfra.backend
147
+ ret = backend.run_command(cmd)
148
+ if meth.to_s =~ /^check/
149
+ ret.success?
150
+ else
151
+ ret
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ module Specinfra::Backend::PowerShell
158
+ class Command
159
+ # Do a better job at escaping regexes, handle both LF and CRLF (YAY!)
160
+ def convert_regexp(target)
161
+ case target
162
+ when Regexp
163
+ target.source
164
+ else
165
+ Regexp.escape(target.to_s.gsub '/', '\/').gsub('\n', '(\r\n|\n)')
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ module Specinfra::Backend
172
+ class BeakerBase < Specinfra::Backend::Base
173
+ # Example accessor
174
+ def example
175
+ @example
49
176
  end
50
177
 
51
178
  # Execute the provided ssh command
52
179
  # @param [String] command The command to be executed
53
180
  # @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
54
- def ssh_exec!(command)
55
- if @example and @example.metadata[:node]
56
- node = @example.metadata[:node]
57
- else
58
- node = default
59
- end
181
+ def ssh_exec!(node, command)
60
182
  r = on node, command, { :acceptable_exit_codes => (0..127) }
61
183
  {
62
184
  :exit_status => r.exit_code,
@@ -65,6 +187,86 @@ module Specinfra::Backend
65
187
  }
66
188
  end
67
189
 
190
+ end
191
+ end
192
+
193
+ # Used as a container for the two backends, dispatches as windows/nix depending on node platform
194
+ module Specinfra::Backend
195
+ class BeakerDispatch < BeakerBase
196
+
197
+ def dispatch_method(meth, *args)
198
+ if get_working_node['platform'] =~ /windows/
199
+ cygwin_backend.send(meth, *args)
200
+ else
201
+ exec_backend.send(meth, *args)
202
+ end
203
+ end
204
+
205
+ def run_command(cmd, opts={})
206
+ dispatch_method('run_command', cmd, opts)
207
+ end
208
+
209
+ def build_command(cmd)
210
+ dispatch_method('build_command', cmd)
211
+ end
212
+
213
+ def add_pre_command(cmd)
214
+ dispatch_method('add_pre_command', cmd)
215
+ end
216
+ end
217
+ end
218
+
219
+ # Backend for running serverspec commands on windows test nodes
220
+ module Specinfra::Backend
221
+ class BeakerCygwin < BeakerBase
222
+ include Specinfra::Backend::PowerShell::ScriptHelper
223
+
224
+ # Run a windows style command using serverspec. Defaults to running on the 'default_node'
225
+ # test node, otherwise uses the node specified in @example.metadata[:node]
226
+ # @param [String] cmd The serverspec command to executed
227
+ # @param [Hash] opt No currently supported options
228
+ # @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
229
+ def run_command(cmd, opt = {})
230
+ node = get_working_node
231
+ script = create_script(cmd)
232
+ on node, "rm -f script.ps1"
233
+ create_remote_file(node, 'script.ps1', script)
234
+ # cygwin support /dev/null, if running from winrm would use < NULL
235
+ ret = ssh_exec!(node, "powershell.exe -File script.ps1 < /dev/null")
236
+
237
+ if @example
238
+ @example.metadata[:command] = script
239
+ @example.metadata[:stdout] = ret[:stdout]
240
+ end
241
+
242
+ CommandResult.new ret
243
+ end
244
+ end
245
+ end
246
+
247
+ # Backend for running serverspec commands on non-windows test nodes
248
+ module Specinfra::Backend
249
+ class BeakerExec < BeakerBase
250
+
251
+ # Run a unix style command using serverspec. Defaults to running on the 'default_node'
252
+ # test node, otherwise uses the node specified in @example.metadata[:node]
253
+ # @param [String] cmd The serverspec command to executed
254
+ # @param [Hash] opt No currently supported options
255
+ # @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
256
+ def run_command(cmd, opt = {})
257
+ node = get_working_node
258
+ cmd = build_command(cmd)
259
+ cmd = add_pre_command(cmd)
260
+ ret = ssh_exec!(node, cmd)
261
+
262
+ if @example
263
+ @example.metadata[:command] = cmd
264
+ @example.metadata[:stdout] = ret[:stdout]
265
+ end
266
+
267
+ CommandResult.new ret
268
+ end
269
+
68
270
  def build_command(cmd)
69
271
  useshell = '/bin/sh'
70
272
  cmd = cmd.shelljoin if cmd.is_a?(Array)
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:beaker) do |c|
4
+ c.pattern = "spec/acceptance/**/*_spec.rb"
5
+ end
@@ -12,6 +12,8 @@ RSpec.configure do |c|
12
12
  c.add_setting :options, :default => {}
13
13
  # Define persistant logger object
14
14
  c.add_setting :logger, :default => nil
15
+ # Define persistant default node
16
+ c.add_setting :default_node, :default => nil
15
17
 
16
18
  #default option values
17
19
  defaults = {
@@ -17,11 +17,48 @@ describe "ignore" do
17
17
  logger.notify("hi, I'm a notify message")
18
18
  end
19
19
 
20
- hosts.each do |node|
21
- describe service('ssh'), :node => node do
22
- it { should be_running }
23
- it { should be_enabled }
20
+ context "has serverspec support" do
21
+ hosts.each do |node|
22
+ sshd = case node['platform']
23
+ when /windows|el-|redhat|centos|debian/
24
+ 'sshd'
25
+ else
26
+ 'ssh'
27
+ end
28
+ describe service(sshd), :node => node do
29
+ it { should be_running }
30
+ end
31
+
32
+ usr = case node['platform']
33
+ when /windows/
34
+ 'Administrator'
35
+ else
36
+ 'root'
37
+ end
38
+ describe user(usr), :node => node do
39
+ it { should exist }
40
+ end
41
+ end
42
+ end
43
+
44
+ context "serverspec: can access default node" do
45
+ usr = case default['platform']
46
+ when /windows/
47
+ 'Administrator'
48
+ else
49
+ 'root'
50
+ end
51
+ describe user(usr) do
52
+ it { should exist }
24
53
  end
25
54
  end
26
55
 
56
+ context "serverspec: can match multiline file to multiline contents" do
57
+ contents = "four = five\n[one]\ntwo = three"
58
+ create_remote_file(default, "file_with_contents.txt", contents)
59
+ describe file("file_with_contents.txt") do
60
+ it { should be_file }
61
+ it { should contain(contents) }
62
+ end
63
+ end
27
64
  end
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppetlabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fakefs
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: markdown
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: thin
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: beaker
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '2.0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: serverspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '2'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: specinfra
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '2'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '2'
167
167
  description: RSpec bindings for beaker, see https://github.com/puppetlabs/beaker
@@ -171,7 +171,7 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
- - .gitignore
174
+ - ".gitignore"
175
175
  - Gemfile
176
176
  - LICENSE
177
177
  - README.md
@@ -179,6 +179,7 @@ files:
179
179
  - lib/beaker-rspec.rb
180
180
  - lib/beaker-rspec/beaker_shim.rb
181
181
  - lib/beaker-rspec/helpers/serverspec.rb
182
+ - lib/beaker-rspec/rake_task.rb
182
183
  - lib/beaker-rspec/spec_helper.rb
183
184
  - sample.cfg
184
185
  - spec/acceptance/example_spec.rb
@@ -193,17 +194,17 @@ require_paths:
193
194
  - lib
194
195
  required_ruby_version: !ruby/object:Gem::Requirement
195
196
  requirements:
196
- - - ! '>='
197
+ - - ">="
197
198
  - !ruby/object:Gem::Version
198
199
  version: '0'
199
200
  required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  requirements:
201
- - - ! '>='
202
+ - - ">="
202
203
  - !ruby/object:Gem::Version
203
204
  version: '0'
204
205
  requirements: []
205
206
  rubyforge_project:
206
- rubygems_version: 2.2.2
207
+ rubygems_version: 2.4.5
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: RSpec bindings for beaker