beaker 4.38.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +36 -11
  5. data/.rubocop.yml +75 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +88 -33
  8. data/Gemfile +16 -4
  9. data/HISTORY.md +103 -0
  10. data/Rakefile +101 -112
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Gemfile +1 -1
  16. data/acceptance/fixtures/module/Rakefile +3 -3
  17. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
  18. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
  19. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  20. data/acceptance/lib/helpers/test_helper.rb +7 -6
  21. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  22. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  24. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +7 -8
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +9 -7
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +23 -30
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +21 -16
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
  41. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
  42. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  43. data/acceptance/tests/base/dsl/structure_test.rb +9 -21
  44. data/acceptance/tests/base/host/file_test.rb +8 -8
  45. data/acceptance/tests/base/host/group_test.rb +2 -3
  46. data/acceptance/tests/base/host/host_test.rb +69 -66
  47. data/acceptance/tests/base/host/packages.rb +27 -30
  48. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  49. data/acceptance/tests/base/host/user_test.rb +2 -3
  50. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  51. data/acceptance/tests/base/test_suite/export.rb +6 -9
  52. data/acceptance/tests/install/from_file.rb +3 -5
  53. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  54. data/acceptance/tests/subcommands/destroy.rb +19 -21
  55. data/acceptance/tests/subcommands/exec.rb +0 -1
  56. data/acceptance/tests/subcommands/init.rb +2 -3
  57. data/acceptance/tests/subcommands/provision.rb +0 -1
  58. data/beaker.gemspec +10 -14
  59. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  60. data/docs/concepts/style_guide.md +1 -1
  61. data/docs/how_to/debug_beaker_tests.md +13 -13
  62. data/docs/how_to/hosts/eos.md +2 -12
  63. data/docs/how_to/install_puppet.md +0 -18
  64. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  65. data/docs/how_to/the_beaker_dsl.md +0 -2
  66. data/lib/beaker/cli.rb +63 -74
  67. data/lib/beaker/command.rb +22 -30
  68. data/lib/beaker/command_factory.rb +4 -3
  69. data/lib/beaker/dsl/assertions.rb +7 -19
  70. data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
  72. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  73. data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
  74. data/lib/beaker/dsl/helpers.rb +2 -4
  75. data/lib/beaker/dsl/outcomes.rb +17 -19
  76. data/lib/beaker/dsl/patterns.rb +1 -3
  77. data/lib/beaker/dsl/roles.rb +18 -21
  78. data/lib/beaker/dsl/structure.rb +55 -67
  79. data/lib/beaker/dsl/test_tagging.rb +7 -10
  80. data/lib/beaker/dsl/wrappers.rb +15 -16
  81. data/lib/beaker/dsl.rb +2 -3
  82. data/lib/beaker/host/aix/exec.rb +1 -1
  83. data/lib/beaker/host/aix/file.rb +0 -1
  84. data/lib/beaker/host/aix/group.rb +3 -3
  85. data/lib/beaker/host/aix/user.rb +3 -3
  86. data/lib/beaker/host/aix.rb +3 -4
  87. data/lib/beaker/host/cisco.rb +36 -48
  88. data/lib/beaker/host/eos.rb +4 -30
  89. data/lib/beaker/host/freebsd/exec.rb +1 -1
  90. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  91. data/lib/beaker/host/freebsd.rb +9 -12
  92. data/lib/beaker/host/mac/exec.rb +5 -5
  93. data/lib/beaker/host/mac/group.rb +13 -13
  94. data/lib/beaker/host/mac/pkg.rb +6 -109
  95. data/lib/beaker/host/mac/user.rb +7 -7
  96. data/lib/beaker/host/mac.rb +8 -9
  97. data/lib/beaker/host/pswindows/exec.rb +70 -74
  98. data/lib/beaker/host/pswindows/file.rb +4 -6
  99. data/lib/beaker/host/pswindows/group.rb +5 -5
  100. data/lib/beaker/host/pswindows/pkg.rb +17 -17
  101. data/lib/beaker/host/pswindows/user.rb +4 -4
  102. data/lib/beaker/host/pswindows.rb +4 -3
  103. data/lib/beaker/host/unix/exec.rb +86 -88
  104. data/lib/beaker/host/unix/file.rb +41 -47
  105. data/lib/beaker/host/unix/group.rb +3 -3
  106. data/lib/beaker/host/unix/pkg.rb +158 -421
  107. data/lib/beaker/host/unix/user.rb +4 -4
  108. data/lib/beaker/host/unix.rb +18 -20
  109. data/lib/beaker/host/windows/exec.rb +20 -20
  110. data/lib/beaker/host/windows/file.rb +5 -5
  111. data/lib/beaker/host/windows/group.rb +5 -5
  112. data/lib/beaker/host/windows/pkg.rb +6 -57
  113. data/lib/beaker/host/windows/user.rb +4 -4
  114. data/lib/beaker/host/windows.rb +13 -13
  115. data/lib/beaker/host.rb +82 -139
  116. data/lib/beaker/host_prebuilt_steps.rb +121 -233
  117. data/lib/beaker/hypervisor/noop.rb +2 -4
  118. data/lib/beaker/hypervisor.rb +46 -63
  119. data/lib/beaker/local_connection.rb +4 -6
  120. data/lib/beaker/logger.rb +71 -85
  121. data/lib/beaker/logger_junit.rb +22 -26
  122. data/lib/beaker/network_manager.rb +40 -43
  123. data/lib/beaker/options/command_line_parser.rb +12 -23
  124. data/lib/beaker/options/hosts_file_parser.rb +34 -25
  125. data/lib/beaker/options/options_file_parser.rb +3 -6
  126. data/lib/beaker/options/options_hash.rb +3 -10
  127. data/lib/beaker/options/parser.rb +89 -105
  128. data/lib/beaker/options/presets.rb +114 -123
  129. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  130. data/lib/beaker/options/validator.rb +26 -31
  131. data/lib/beaker/perf.rb +29 -34
  132. data/lib/beaker/platform.rb +38 -46
  133. data/lib/beaker/result.rb +7 -6
  134. data/lib/beaker/shared/error_handler.rb +8 -10
  135. data/lib/beaker/shared/fog_credentials.rb +5 -9
  136. data/lib/beaker/shared/host_manager.rb +40 -46
  137. data/lib/beaker/shared/options_resolver.rb +3 -7
  138. data/lib/beaker/shared/repetition.rb +6 -8
  139. data/lib/beaker/shared/semvar.rb +39 -43
  140. data/lib/beaker/shared/timed.rb +2 -5
  141. data/lib/beaker/shared.rb +1 -1
  142. data/lib/beaker/ssh_connection.rb +46 -55
  143. data/lib/beaker/subcommand.rb +23 -30
  144. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  145. data/lib/beaker/tasks/quick_start.rb +5 -10
  146. data/lib/beaker/tasks/rake_task.rb +26 -28
  147. data/lib/beaker/tasks/test.rb +4 -4
  148. data/lib/beaker/test_case.rb +15 -27
  149. data/lib/beaker/test_suite.rb +35 -39
  150. data/lib/beaker/test_suite_result.rb +52 -57
  151. data/lib/beaker/version.rb +1 -1
  152. data/lib/beaker.rb +5 -6
  153. data/spec/beaker/cli_spec.rb +135 -153
  154. data/spec/beaker/command_spec.rb +64 -58
  155. data/spec/beaker/dsl/assertions_spec.rb +38 -47
  156. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
  157. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  158. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
  159. data/spec/beaker/dsl/outcomes_spec.rb +15 -14
  160. data/spec/beaker/dsl/roles_spec.rb +170 -132
  161. data/spec/beaker/dsl/structure_spec.rb +181 -163
  162. data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
  163. data/spec/beaker/dsl/wrappers_spec.rb +39 -40
  164. data/spec/beaker/host/aix_spec.rb +14 -14
  165. data/spec/beaker/host/cisco_spec.rb +92 -102
  166. data/spec/beaker/host/eos_spec.rb +15 -36
  167. data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
  168. data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
  169. data/spec/beaker/host/mac/exec_spec.rb +4 -5
  170. data/spec/beaker/host/mac/group_spec.rb +47 -56
  171. data/spec/beaker/host/mac/user_spec.rb +53 -62
  172. data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
  173. data/spec/beaker/host/pswindows/file_spec.rb +21 -18
  174. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  175. data/spec/beaker/host/pswindows_spec.rb +14 -14
  176. data/spec/beaker/host/unix/exec_spec.rb +87 -92
  177. data/spec/beaker/host/unix/file_spec.rb +76 -82
  178. data/spec/beaker/host/unix/pkg_spec.rb +165 -407
  179. data/spec/beaker/host/unix_spec.rb +11 -207
  180. data/spec/beaker/host/windows/exec_spec.rb +32 -34
  181. data/spec/beaker/host/windows/file_spec.rb +22 -23
  182. data/spec/beaker/host/windows/group_spec.rb +17 -19
  183. data/spec/beaker/host/windows/pkg_spec.rb +10 -13
  184. data/spec/beaker/host/windows/user_spec.rb +17 -23
  185. data/spec/beaker/host/windows_spec.rb +39 -39
  186. data/spec/beaker/host_prebuilt_steps_spec.rb +193 -341
  187. data/spec/beaker/host_spec.rb +241 -312
  188. data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
  189. data/spec/beaker/localhost_connection_spec.rb +14 -13
  190. data/spec/beaker/logger_junit_spec.rb +22 -34
  191. data/spec/beaker/logger_spec.rb +174 -155
  192. data/spec/beaker/network_manager_spec.rb +27 -27
  193. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  194. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  195. data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
  196. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  197. data/spec/beaker/options/options_hash_spec.rb +7 -9
  198. data/spec/beaker/options/parser_spec.rb +187 -187
  199. data/spec/beaker/options/presets_spec.rb +8 -10
  200. data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
  201. data/spec/beaker/options/validator_spec.rb +27 -28
  202. data/spec/beaker/perf_spec.rb +32 -34
  203. data/spec/beaker/platform_spec.rb +27 -37
  204. data/spec/beaker/shared/error_handler_spec.rb +8 -17
  205. data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
  206. data/spec/beaker/shared/host_manager_spec.rb +55 -89
  207. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  208. data/spec/beaker/shared/repetition_spec.rb +24 -31
  209. data/spec/beaker/shared/semvar_spec.rb +21 -26
  210. data/spec/beaker/ssh_connection_spec.rb +85 -90
  211. data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
  212. data/spec/beaker/subcommand_spec.rb +89 -89
  213. data/spec/beaker/test_case_spec.rb +33 -62
  214. data/spec/beaker/test_suite_spec.rb +153 -160
  215. data/spec/helpers.rb +48 -53
  216. data/spec/matchers.rb +9 -8
  217. data/spec/mocks.rb +6 -11
  218. data/spec/spec_helper.rb +0 -4
  219. metadata +60 -85
  220. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  221. data/acceptance/tests/base/external_resources_test.rb +0 -31
  222. data/spec/beaker/host/mac_spec.rb +0 -113
  223. data/spec/mock_fission.rb +0 -60
  224. data/spec/mock_vsphere.rb +0 -314
  225. data/spec/mock_vsphere_helper.rb +0 -183
@@ -11,17 +11,17 @@ module PSWindows::Exec
11
11
  ABS_CMD = 'c:\\\\windows\\\\system32\\\\cmd.exe'
12
12
  CMD = 'cmd.exe'
13
13
 
14
- def echo(msg, abs=true)
14
+ def echo(msg, abs = true)
15
15
  (abs ? ABS_CMD : CMD) + " /c echo #{msg}"
16
16
  end
17
17
 
18
- def touch(file, abs=true)
18
+ def touch(file, abs = true)
19
19
  (abs ? ABS_CMD : CMD) + " /c echo. 2> #{file}"
20
20
  end
21
21
 
22
22
  def rm_rf path
23
23
  # ensure that we have the right slashes for windows
24
- path = path.gsub(/\//, '\\')
24
+ path = path.tr('/', '\\')
25
25
  execute(%(del /s /q "#{path}"))
26
26
  end
27
27
 
@@ -29,10 +29,10 @@ module PSWindows::Exec
29
29
  # @param [String] orig The origin path
30
30
  # @param [String] dest the destination path
31
31
  # @param [Boolean] rm Remove the destination prior to move
32
- def mv(orig, dest, rm=true)
32
+ def mv(orig, dest, rm = true)
33
33
  # ensure that we have the right slashes for windows
34
- orig = orig.gsub(/\//,'\\')
35
- dest = dest.gsub(/\//,'\\')
34
+ orig = orig.tr('/', '\\')
35
+ dest = dest.tr('/', '\\')
36
36
  rm_rf dest unless !rm
37
37
  execute("move /y #{orig} #{dest}")
38
38
  end
@@ -46,17 +46,14 @@ module PSWindows::Exec
46
46
 
47
47
  result = execute("powershell Test-Path #{file} -PathType Leaf")
48
48
 
49
- if result.include? 'False'
50
- execute("powershell New-Item -ItemType file #{file}")
51
- end
49
+ execute("powershell New-Item -ItemType file #{file}") if result.include? 'False'
52
50
  execute("powershell (gci #{file}).LastWriteTime = Get-Date " \
53
- "-Year '#{time.year}'" \
54
- "-Month '#{time.month}'" \
55
- "-Day '#{time.day}'" \
56
- "-Hour '#{time.hour}'" \
57
- "-Minute '#{time.minute}'" \
58
- "-Second '#{time.second}'"
59
- )
51
+ "-Year '#{time.year}'" \
52
+ "-Month '#{time.month}'" \
53
+ "-Day '#{time.day}'" \
54
+ "-Hour '#{time.hour}'" \
55
+ "-Minute '#{time.minute}'" \
56
+ "-Second '#{time.second}'")
60
57
  end
61
58
 
62
59
  def path
@@ -75,8 +72,10 @@ module PSWindows::Exec
75
72
  ips.each_line do |line|
76
73
  matches = line.split('=')
77
74
  next if matches.length <= 1
75
+
78
76
  matches = matches[1].match(/^{"(.*?)"/)
79
77
  next if matches.nil? || matches.captures.nil? || matches.captures.empty?
78
+
80
79
  ip = matches.captures[0] if matches && matches.captures
81
80
  break if ip != ''
82
81
  end
@@ -88,14 +87,13 @@ module PSWindows::Exec
88
87
  # @param [String] target The hostname to ping
89
88
  # @param [Integer] attempts Amount of times to attempt ping before giving up
90
89
  # @return [Boolean] true of ping successful, overwise false
91
- def ping target, attempts=5
90
+ def ping target, attempts = 5
92
91
  try = 0
93
- while try < attempts do
92
+ while try < attempts
94
93
  result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true)
95
- if result.exit_code == 0
96
- return true
97
- end
98
- try+=1
94
+ return true if result.exit_code == 0
95
+
96
+ try += 1
99
97
  end
100
98
  result.exit_code == 0
101
99
  end
@@ -104,88 +102,87 @@ module PSWindows::Exec
104
102
  # @param [String] dir The directory structure to create on the host
105
103
  # @return [Boolean] True, if directory construction succeeded, otherwise False
106
104
  def mkdir_p dir
107
- normalized_path = dir.gsub('/','\\')
105
+ normalized_path = dir.tr('/', '\\')
108
106
  result = exec(powershell("New-Item -Path '#{normalized_path}' -ItemType 'directory'"),
109
107
  :acceptable_exit_codes => [0, 1])
110
108
  result.exit_code == 0
111
109
  end
112
110
 
113
- #Add the provided key/val to the current ssh environment
114
- #@param [String] key The key to add the value to
115
- #@param [String] val The value for the key
116
- #@example
111
+ # Add the provided key/val to the current ssh environment
112
+ # @param [String] key The key to add the value to
113
+ # @param [String] val The value for the key
114
+ # @example
117
115
  # host.add_env_var('PATH', '/usr/bin:PATH')
118
116
  def add_env_var key, val
119
117
  key = key.to_s.upcase
120
- #see if the key/value pair already exists
121
- cur_val = subbed_val = get_env_var(key, true)
118
+ # see if the key/value pair already exists
119
+ cur_val = get_env_var(key, true)
122
120
  subbed_val = cur_val.gsub(/#{Regexp.escape(val.gsub(/'|"/, ''))}/, '')
123
121
  if cur_val.empty?
124
122
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', '#{val}', 'Machine')"))
125
- self.close #refresh the state
126
- elsif subbed_val == cur_val #not present, add it
123
+ self.close # refresh the state
124
+ elsif subbed_val == cur_val # not present, add it
127
125
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', '#{val};#{cur_val}', 'Machine')"))
128
- self.close #refresh the state
126
+ self.close # refresh the state
129
127
  end
130
128
  end
131
129
 
132
- #Delete the provided key/val from the current ssh environment
133
- #@param [String] key The key to delete the value from
134
- #@param [String] val The value to delete for the key
135
- #@example
130
+ # Delete the provided key/val from the current ssh environment
131
+ # @param [String] key The key to delete the value from
132
+ # @param [String] val The value to delete for the key
133
+ # @example
136
134
  # host.delete_env_var('PATH', '/usr/bin:PATH')
137
135
  def delete_env_var key, val
138
136
  key = key.to_s.upcase
139
- #get the current value of the key
140
- cur_val = subbed_val = get_env_var(key, true)
137
+ # get the current value of the key
138
+ cur_val = get_env_var(key, true)
141
139
  subbed_val = (cur_val.split(';') - [val.gsub(/'|"/, '')]).join(';')
142
- if subbed_val != cur_val
143
- #remove the current key value
144
- self.clear_env_var(key)
145
- #set to the truncated value
146
- self.add_env_var(key, subbed_val)
147
- end
140
+ return unless subbed_val != cur_val
141
+
142
+ # remove the current key value
143
+ self.clear_env_var(key)
144
+ # set to the truncated value
145
+ self.add_env_var(key, subbed_val)
148
146
  end
149
147
 
150
- #Return the value of a specific env var
151
- #@param [String] key The key to look for
152
- #@param [Boolean] clean Remove the 'KEY=' and only return the value of the env var
153
- #@example
148
+ # Return the value of a specific env var
149
+ # @param [String] key The key to look for
150
+ # @param [Boolean] clean Remove the 'KEY=' and only return the value of the env var
151
+ # @example
154
152
  # host.get_env_var('path')
155
153
  def get_env_var key, clean = false
156
- self.close #refresh the state
154
+ self.close # refresh the state
157
155
  key = key.to_s.upcase
158
156
  val = exec(Beaker::Command.new("set #{key}"), :accept_all_exit_codes => true).stdout.chomp
159
- if val.empty?
160
- return ''
157
+ return '' if val.empty?
158
+
159
+ val = val.split("\n")[0] # only take the first result
160
+ if clean
161
+ val.gsub(/#{key}=/i, '')
161
162
  else
162
- val = val.split(/\n/)[0] # only take the first result
163
- if clean
164
- val.gsub(/#{key}=/i,'')
165
- else
166
- val
167
- end
163
+ val
168
164
  end
169
165
  end
170
166
 
171
- #Delete the environment variable from the current ssh environment
172
- #@param [String] key The key to delete
173
- #@example
167
+ # Delete the environment variable from the current ssh environment
168
+ # @param [String] key The key to delete
169
+ # @example
174
170
  # host.clear_env_var('PATH')
175
171
  def clear_env_var key
176
172
  key = key.to_s.upcase
177
173
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'Machine')"))
178
174
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'User')"))
179
175
  exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'Process')"))
180
- self.close #refresh the state
176
+ self.close # refresh the state
181
177
  end
182
178
 
183
179
  def environment_string env
184
180
  return '' if env.empty?
185
- env_array = self.environment_variable_string_pair_array( env )
181
+
182
+ env_array = self.environment_variable_string_pair_array(env)
186
183
 
187
184
  environment_string = ''
188
- env_array.each_with_index do |env|
185
+ env_array.each do |env|
189
186
  environment_string += "set \"#{env}\" && "
190
187
  end
191
188
  environment_string
@@ -195,11 +192,11 @@ module PSWindows::Exec
195
192
  env_array = []
196
193
  env.each_key do |key|
197
194
  val = env[key]
198
- if val.is_a?(Array)
199
- val = val.join(':')
200
- else
201
- val = val.to_s
202
- end
195
+ val = if val.is_a?(Array)
196
+ val.join(':')
197
+ else
198
+ val.to_s
199
+ end
203
200
  # doing this for the key itself & the upcase'd version allows us to remain
204
201
  # backwards compatible
205
202
  # TODO: (Next Major Version) get rid of upcase'd version
@@ -216,8 +213,7 @@ module PSWindows::Exec
216
213
  # Overrides the {Windows::Exec#ssh_permit_user_environment} method,
217
214
  # since no steps are needed in this setup to allow user ssh environments
218
215
  # to work.
219
- def ssh_permit_user_environment
220
- end
216
+ def ssh_permit_user_environment; end
221
217
 
222
218
  # Sets the user SSH environment.
223
219
  #
@@ -231,18 +227,18 @@ module PSWindows::Exec
231
227
  # @api private
232
228
  # @return nil
233
229
  def ssh_set_user_environment(env)
234
- #add the env var set to this test host
230
+ # add the env var set to this test host
235
231
  env.each_pair do |var, value|
236
232
  add_env_var(var, value)
237
233
  end
238
234
  end
239
235
 
240
- #First path it finds for the command executable
241
- #@param [String] command The command executable to search for
236
+ # First path it finds for the command executable
237
+ # @param [String] command The command executable to search for
242
238
  #
243
239
  # @return [String] Path to the searched executable or empty string if not found
244
240
  #
245
- #@example
241
+ # @example
246
242
  # host.which('ruby')
247
243
  def which(command)
248
244
  where_command = "cmd /C \"where #{command}\""
@@ -1,17 +1,15 @@
1
1
  module PSWindows::File
2
2
  include Beaker::CommandFactory
3
3
 
4
- def tmpfile(name = '')
4
+ def tmpfile(_name = '')
5
5
  result = exec(powershell('[System.IO.Path]::GetTempFileName()'))
6
- result.stdout.chomp()
6
+ result.stdout.chomp
7
7
  end
8
8
 
9
9
  def tmpdir(name = '')
10
- tmp_path = exec(powershell('[System.IO.Path]::GetTempPath()')).stdout.chomp()
10
+ tmp_path = exec(powershell('[System.IO.Path]::GetTempPath()')).stdout.chomp
11
11
 
12
- if name == ''
13
- name = exec(powershell('[System.IO.Path]::GetRandomFileName()')).stdout.chomp()
14
- end
12
+ name = exec(powershell('[System.IO.Path]::GetRandomFileName()')).stdout.chomp if name == ''
15
13
  exec(powershell("New-Item -Path '#{tmp_path}' -Force -Name '#{name}' -ItemType 'directory'"))
16
14
  File.join(tmp_path, name)
17
15
  end
@@ -1,7 +1,7 @@
1
1
  module PSWindows::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list
5
5
  execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module PSWindows::Group
14
14
  end
15
15
  end
16
16
 
17
- def group_get(name, &block)
17
+ def group_get(name)
18
18
  execute("net localgroup \"#{name}\"") do |result|
19
19
  fail_test "failed to get group #{name}" if result.exit_code != 0
20
20
 
@@ -23,15 +23,15 @@ module PSWindows::Group
23
23
  end
24
24
  end
25
25
 
26
- def group_gid(name)
26
+ def group_gid(_name)
27
27
  raise NotImplementedError, "Can't retrieve group gid on a Windows host"
28
28
  end
29
29
 
30
30
  def group_present(name, &block)
31
- execute("net localgroup /add \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
31
+ execute("net localgroup /add \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
32
32
  end
33
33
 
34
34
  def group_absent(name, &block)
35
- execute("net localgroup /delete \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
35
+ execute("net localgroup /delete \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
36
36
  end
37
37
  end
@@ -6,28 +6,28 @@ module PSWindows::Pkg
6
6
  result.exit_code == 0
7
7
  end
8
8
 
9
- def check_for_package(name)
10
- #HACK NOOP
11
- #raise "Cannot check for package #{name} on #{self}"
9
+ def check_for_package(_name)
10
+ # HACK: NOOP
11
+ # raise "Cannot check for package #{name} on #{self}"
12
12
  0
13
13
  end
14
14
 
15
- def install_package(name, cmdline_args = '')
16
- #HACK NOOP
17
- #raise "Package #{name} cannot be installed on #{self}"
15
+ def install_package(_name, _cmdline_args = '')
16
+ # HACK: NOOP
17
+ # raise "Package #{name} cannot be installed on #{self}"
18
18
  0
19
19
  end
20
20
 
21
- def uninstall_package(name, cmdline_args = '')
22
- #HACK NOOP
23
- #raise "Package #{name} cannot be uninstalled on #{self}"
21
+ def uninstall_package(_name, _cmdline_args = '')
22
+ # HACK: NOOP
23
+ # raise "Package #{name} cannot be uninstalled on #{self}"
24
24
  0
25
25
  end
26
26
 
27
- #Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
28
- #@return [Boolean] true if x86_64, false otherwise
27
+ # Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
28
+ # @return [Boolean] true if x86_64, false otherwise
29
29
  def determine_if_x86_64
30
- (identify_windows_architecture =~ /64/) == 0
30
+ identify_windows_architecture.include?('64')
31
31
  end
32
32
 
33
33
  private
@@ -37,10 +37,10 @@ module PSWindows::Pkg
37
37
  arch = nil
38
38
  execute("wmic os get osarchitecture", :accept_all_exit_codes => true) do |result|
39
39
  arch = if result.exit_code == 0
40
- result.stdout =~ /64/ ? '64' : '32'
41
- else
42
- identify_windows_architecture_from_os_name_for_win2003
43
- end
40
+ result.stdout.include?('64') ? '64' : '32'
41
+ else
42
+ identify_windows_architecture_from_os_name_for_win2003
43
+ end
44
44
  end
45
45
  arch
46
46
  end
@@ -49,7 +49,7 @@ module PSWindows::Pkg
49
49
  def identify_windows_architecture_from_os_name_for_win2003
50
50
  arch = nil
51
51
  execute("wmic os get name", :accept_all_exit_codes => true) do |result|
52
- arch = result.stdout =~ /64/ ? '64' : '32'
52
+ arch = result.stdout.include?('64') ? '64' : '32'
53
53
  end
54
54
  arch
55
55
  end
@@ -1,7 +1,7 @@
1
1
  module PSWindows::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list
5
5
  execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module PSWindows::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("net user \"#{name}\"") do |result|
19
19
  fail_test "failed to get user #{name}" if result.exit_code != 0
20
20
 
@@ -24,10 +24,10 @@ module PSWindows::User
24
24
  end
25
25
 
26
26
  def user_present(name, &block)
27
- execute("net user /add \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
27
+ execute("net user /add \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
28
28
  end
29
29
 
30
30
  def user_absent(name, &block)
31
- execute("net user /delete \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
31
+ execute("net user /delete \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
32
32
  end
33
33
  end
@@ -1,10 +1,10 @@
1
- [ 'host', 'command_factory', 'command', 'options', 'dsl/wrappers' ].each do |lib|
1
+ ['host', 'command_factory', 'command', 'options', 'dsl/wrappers'].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module PSWindows
6
6
  class Host < Windows::Host
7
- [ 'user', 'group', 'exec', 'pkg', 'file' ].each do |lib|
7
+ %w[user group exec pkg file].each do |lib|
8
8
  require "beaker/host/pswindows/#{lib}"
9
9
  end
10
10
 
@@ -16,12 +16,14 @@ module PSWindows
16
16
 
17
17
  def external_copy_base
18
18
  return @external_copy_base if @external_copy_base
19
+
19
20
  @external_copy_base = execute('for %I in (%ALLUSERSPROFILE%) do @echo %~I')
20
21
  @external_copy_base
21
22
  end
22
23
 
23
24
  # attr_reader :network_separator, :external_copy_base, :system_temp_path
24
25
  attr_reader :scp_separator, :system_temp_path
26
+
25
27
  def initialize name, host_hash, options
26
28
  super
27
29
 
@@ -33,6 +35,5 @@ module PSWindows
33
35
  @external_copy_base = nil
34
36
  # @external_copy_base = '/programdata'
35
37
  end
36
-
37
38
  end
38
39
  end