beaker 4.40.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) 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 +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +13 -11
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +4 -3
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +15 -27
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +5 -6
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +169 -158
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +47 -56
  167. data/spec/beaker/host/mac/user_spec.rb +53 -62
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -5,89 +5,85 @@ class MacGroupTest
5
5
  end
6
6
 
7
7
  describe MacGroupTest do
8
- let( :puppet1 ) do <<-EOS
9
- name: puppet1
10
- password: *
11
- gid: 55
8
+ let(:puppet1) do
9
+ <<~EOS
10
+ name: puppet1
11
+ password: *
12
+ gid: 55
12
13
 
13
- EOS
14
+ EOS
14
15
  end
15
- let( :puppet2 ) do <<-EOS
16
- name: puppet2
17
- password: *
18
- gid: 56
16
+ let(:puppet2) do
17
+ <<~EOS
18
+ name: puppet2
19
+ password: *
20
+ gid: 56
19
21
 
20
- EOS
22
+ EOS
21
23
  end
22
- let( :dscacheutil_list ) do <<-EOS
23
- #{puppet1}
24
- #{puppet2}
25
- EOS
24
+ let(:dscacheutil_list) do
25
+ <<~EOS
26
+ #{puppet1}
27
+ #{puppet2}
28
+ EOS
26
29
  end
27
- let( :command ) { 'ls' }
28
- let( :host ) { double.as_null_object }
29
- let( :result ) { Beaker::Result.new( host, command ) }
30
+ let(:command) { 'ls' }
31
+ let(:host) { double.as_null_object }
32
+ let(:result) { Beaker::Result.new(host, command) }
30
33
 
31
34
  describe '#group_list' do
32
-
33
35
  it 'returns group names list correctly' do
34
36
  result.stdout = dscacheutil_list
35
- expect( subject ).to receive( :execute ).and_yield(result)
36
- expect( subject.group_list ).to be === ['puppet1', 'puppet2']
37
+ expect(subject).to receive(:execute).and_yield(result)
38
+ expect(subject.group_list).to be === %w[puppet1 puppet2]
37
39
  end
38
40
 
39
41
  it 'yields correctly with the result object' do
40
42
  result.stdout = dscacheutil_list
41
- expect( subject ).to receive( :execute ).and_yield(result)
42
- subject.group_list { |result|
43
- expect( result.stdout ).to be === dscacheutil_list
44
- }
43
+ expect(subject).to receive(:execute).and_yield(result)
44
+ subject.group_list do |result|
45
+ expect(result.stdout).to be === dscacheutil_list
46
+ end
45
47
  end
46
-
47
48
  end
48
49
 
49
50
  describe '#group_get' do
50
-
51
51
  it 'fails if a name line isn\'t included' do
52
52
  result.stdout = ''
53
53
  group_name = 'any_name'
54
- expect( subject ).to receive( :execute ).and_yield(result)
54
+ expect(subject).to receive(:execute).and_yield(result)
55
55
  expect { subject.group_get(group_name) }.to raise_error(MiniTest::Assertion, "failed to get group #{group_name}")
56
56
  end
57
57
 
58
58
  it 'parses mac dscacheutil output into /etc/group format correctly' do
59
59
  result.stdout = puppet1
60
- expect( subject ).to receive( :execute ).and_yield(result)
60
+ expect(subject).to receive(:execute).and_yield(result)
61
61
  subject.group_get('puppet1') do |answer|
62
62
  expect(answer).to be === 'puppet1:*:55'
63
63
  end
64
64
  end
65
-
66
65
  end
67
66
 
68
67
  describe '#group_gid' do
69
-
70
68
  it 'parses mac dscacheutil output into the gid correctly' do
71
69
  result.stdout = puppet1
72
- expect( subject ).to receive( :execute ).and_yield(result)
73
- expect( subject.group_gid(puppet1) ).to be === '55'
70
+ expect(subject).to receive(:execute).and_yield(result)
71
+ expect(subject.group_gid(puppet1)).to be === '55'
74
72
  end
75
73
 
76
74
  it 'returns -1 if gid not found' do
77
75
  result.stdout = ''
78
- expect( subject ).to receive( :execute ).and_yield(result)
79
- expect( subject.group_gid(puppet1) ).to be === -1
76
+ expect(subject).to receive(:execute).and_yield(result)
77
+ expect(subject.group_gid(puppet1)).to be === -1
80
78
  end
81
-
82
79
  end
83
80
 
84
81
  describe '#group_present' do
85
-
86
82
  it 'returns group existence without running create command if it already exists' do
87
83
  result.stdout = puppet1
88
- expect( subject ).to receive( :execute ).once.and_yield(result)
89
- expect( subject ).not_to receive( :gid_next )
90
- subject.group_present( 'puppet1' )
84
+ expect(subject).to receive(:execute).once.and_yield(result)
85
+ expect(subject).not_to receive(:gid_next)
86
+ subject.group_present('puppet1')
91
87
  end
92
88
 
93
89
  it 'runs correct create command if group does not exist' do
@@ -95,40 +91,35 @@ EOS
95
91
  gid = 512
96
92
  name = "madeup_group"
97
93
 
98
- expect( subject ).to receive( :gid_next ).and_return(gid)
99
- expect( subject ).to receive( :execute ).once.ordered.and_yield(result)
100
- expect( subject ).to receive( :execute ).with("dscl . create /Groups/#{name} && dscl . create /Groups/#{name} PrimaryGroupID #{gid}").once.ordered
101
- subject.group_present( name )
94
+ expect(subject).to receive(:gid_next).and_return(gid)
95
+ expect(subject).to receive(:execute).once.ordered.and_yield(result)
96
+ expect(subject).to receive(:execute).with("dscl . create /Groups/#{name} && dscl . create /Groups/#{name} PrimaryGroupID #{gid}").once.ordered
97
+ subject.group_present(name)
102
98
  end
103
99
 
104
100
  it 'makes the correct call to dscacheutil' do
105
101
  result.stdout = puppet1
106
- expect( subject ).to receive( :execute ).with(
107
- /^dscacheutil\ \-q\ group\ \-a\ name\ /
102
+ expect(subject).to receive(:execute).with(
103
+ /^dscacheutil\ \-q\ group\ \-a\ name\ /,
108
104
  ).once.and_yield(result)
109
- expect( subject ).not_to receive( :gid_next )
110
- subject.group_present( 'puppet1' )
105
+ expect(subject).not_to receive(:gid_next)
106
+ subject.group_present('puppet1')
111
107
  end
112
-
113
108
  end
114
109
 
115
110
  describe '#group_absent' do
116
-
117
111
  it 'calls execute to run logic' do
118
112
  name = "main_one"
119
- expect( subject ).to receive( :execute ).once.with("if dscl . -list /Groups/#{name}; then dscl . -delete /Groups/#{name}; fi", {})
120
- subject.group_absent( name )
113
+ expect(subject).to receive(:execute).once.with("if dscl . -list /Groups/#{name}; then dscl . -delete /Groups/#{name}; fi", {})
114
+ subject.group_absent(name)
121
115
  end
122
-
123
116
  end
124
117
 
125
118
  describe '#gid_next' do
126
-
127
119
  it 'returns the next ID given' do
128
120
  n = 10
129
- expect( subject ).to receive( :execute ).and_return("#{n}")
130
- expect( subject.gid_next ).to be === n + 1
121
+ expect(subject).to receive(:execute).and_return("#{n}")
122
+ expect(subject.gid_next).to be === n + 1
131
123
  end
132
-
133
124
  end
134
125
  end
@@ -5,83 +5,81 @@ class MacUserTest
5
5
  end
6
6
 
7
7
  describe MacUserTest do
8
- let( :puppet1 ) do <<-EOS
9
- name: puppet1
10
- password: *
11
- uid: 67
12
- gid: 234
13
- dir: /Users/puppet1
14
- shell: /bin/bash
15
- gecos: Unprivileged User
16
-
17
- EOS
8
+ let(:puppet1) do
9
+ <<~EOS
10
+ name: puppet1
11
+ password: *
12
+ uid: 67
13
+ gid: 234
14
+ dir: /Users/puppet1
15
+ shell: /bin/bash
16
+ gecos: Unprivileged User
17
+
18
+ EOS
18
19
  end
19
- let( :puppet2 ) do <<-EOS
20
- name: puppet2
21
- password: *
22
- uid: 68
23
- gid: 235
24
- dir: /Users/puppet2
25
- shell: /bin/sh
26
- gecos: puppet
27
-
28
- EOS
20
+ let(:puppet2) do
21
+ <<~EOS
22
+ name: puppet2
23
+ password: *
24
+ uid: 68
25
+ gid: 235
26
+ dir: /Users/puppet2
27
+ shell: /bin/sh
28
+ gecos: puppet
29
+
30
+ EOS
29
31
  end
30
- let( :dscacheutil_list ) do <<-EOS
31
- #{puppet1}
32
- #{puppet2}
33
- EOS
32
+ let(:dscacheutil_list) do
33
+ <<~EOS
34
+ #{puppet1}
35
+ #{puppet2}
36
+ EOS
34
37
  end
35
- let( :etc_passwd_line ) do
38
+ let(:etc_passwd_line) do
36
39
  "puppet1:*:67:234::0:0:puppet1:/Users/puppet1:/bin/sh"
37
40
  end
38
- let( :command ) { 'ls' }
39
- let( :host ) { double.as_null_object }
40
- let( :result ) { Beaker::Result.new( host, command ) }
41
+ let(:command) { 'ls' }
42
+ let(:host) { double.as_null_object }
43
+ let(:result) { Beaker::Result.new(host, command) }
41
44
 
42
45
  describe '#user_list' do
43
-
44
46
  it 'returns user names list correctly' do
45
47
  result.stdout = dscacheutil_list
46
- expect( subject ).to receive( :execute ).and_yield(result)
47
- expect( subject.user_list ).to be === ['puppet1', 'puppet2']
48
+ expect(subject).to receive(:execute).and_yield(result)
49
+ expect(subject.user_list).to be === %w[puppet1 puppet2]
48
50
  end
49
51
 
50
52
  it 'yields correctly with the result object' do
51
53
  result.stdout = dscacheutil_list
52
- expect( subject ).to receive( :execute ).and_yield(result)
53
- subject.user_list { |result|
54
- expect( result.stdout ).to be === dscacheutil_list
55
- }
54
+ expect(subject).to receive(:execute).and_yield(result)
55
+ subject.user_list do |result|
56
+ expect(result.stdout).to be === dscacheutil_list
57
+ end
56
58
  end
57
-
58
59
  end
59
60
 
60
61
  describe '#user_get' do
61
-
62
62
  it 'fails if a name line isn\'t included' do
63
63
  result.stdout = ''
64
64
  user_name = 'any_name'
65
- expect( subject ).to receive( :execute ).and_yield(result)
65
+ expect(subject).to receive(:execute).and_yield(result)
66
66
  expect { subject.user_get(user_name) }.to raise_error(MiniTest::Assertion, "failed to get user #{user_name}")
67
67
  end
68
68
 
69
69
  it 'yields correctly with the result object' do
70
70
  result.stdout = etc_passwd_line
71
- expect( subject ).to receive( :execute ).and_yield(result)
71
+ expect(subject).to receive(:execute).and_yield(result)
72
72
  subject.user_get('puppet1') do |result|
73
- expect( result.stdout ).to be === etc_passwd_line
73
+ expect(result.stdout).to be === etc_passwd_line
74
74
  end
75
75
  end
76
-
77
76
  end
78
77
 
79
78
  describe '#user_present' do
80
-
81
79
  it 'returns user existence without running create command if it already exists' do
82
80
  result.stdout = puppet1
83
- expect( subject ).to receive( :execute ).once.and_yield(result)
84
- subject.user_present( 'puppet1' )
81
+ expect(subject).to receive(:execute).once.and_yield(result)
82
+ subject.user_present('puppet1')
85
83
  end
86
84
 
87
85
  it 'runs correct create command if group does not exist' do
@@ -90,42 +88,35 @@ EOS
90
88
  gid = 1007
91
89
  name = "madeup_user"
92
90
 
93
- expect( subject ).to receive( :uid_next ).and_return(uid)
94
- expect( subject ).to receive( :gid_next ).and_return(gid)
95
- expect( subject ).to receive( :execute ).once.ordered.and_yield(result)
96
- expect( subject ).to receive( :execute ).once.ordered
97
- subject.user_present( name )
91
+ expect(subject).to receive(:uid_next).and_return(uid)
92
+ expect(subject).to receive(:gid_next).and_return(gid)
93
+ expect(subject).to receive(:execute).once.ordered.and_yield(result)
94
+ expect(subject).to receive(:execute).once.ordered
95
+ subject.user_present(name)
98
96
  end
99
-
100
97
  end
101
98
 
102
99
  describe '#user_absent' do
103
-
104
100
  it 'calls execute to run logic' do
105
101
  name = "main_one"
106
- expect( subject ).to receive( :execute ).once.with("if dscl . -list /Users/#{name}; then dscl . -delete /Users/#{name}; fi", {})
107
- subject.user_absent( name )
102
+ expect(subject).to receive(:execute).once.with("if dscl . -list /Users/#{name}; then dscl . -delete /Users/#{name}; fi", {})
103
+ subject.user_absent(name)
108
104
  end
109
-
110
105
  end
111
106
 
112
107
  describe '#uid_next' do
113
-
114
108
  it 'returns the next ID given' do
115
109
  n = 117
116
- expect( subject ).to receive( :execute ).and_return("#{n}")
117
- expect( subject.uid_next ).to be === n + 1
110
+ expect(subject).to receive(:execute).and_return("#{n}")
111
+ expect(subject.uid_next).to be === n + 1
118
112
  end
119
-
120
113
  end
121
114
 
122
115
  describe '#gid_next' do
123
-
124
116
  it 'returns the next ID given' do
125
117
  n = 843
126
- expect( subject ).to receive( :execute ).and_return("#{n}")
127
- expect( subject.gid_next ).to be === n + 1
118
+ expect(subject).to receive(:execute).and_return("#{n}")
119
+ expect(subject.gid_next).to be === n + 1
128
120
  end
129
-
130
121
  end
131
122
  end
@@ -17,15 +17,13 @@ module Beaker
17
17
  def to_s
18
18
  "me"
19
19
  end
20
-
21
20
  end
22
21
 
23
22
  let(:opts) { @opts || {} }
24
- let(:logger) { double( 'logger' ).as_null_object }
23
+ let(:logger) { double('logger').as_null_object }
25
24
  let(:instance) { PSWindowsExecTest.new(opts, logger) }
26
25
 
27
26
  context "rm" do
28
-
29
27
  it "deletes" do
30
28
  path = '/path/to/delete'
31
29
  corrected_path = '\\path\\to\\delete'
@@ -45,8 +43,8 @@ module Beaker
45
43
  end
46
44
 
47
45
  it 'does not rm' do
48
- expect( instance ).to receive(:execute).with("move /y #{origin.tr('/', '\\')} #{destination.tr('/', '\\')}").and_return(0)
49
- expect( instance.mv(origin, destination, false) ).to be === 0
46
+ expect(instance).to receive(:execute).with("move /y #{origin.tr('/', '\\')} #{destination.tr('/', '\\')}").and_return(0)
47
+ expect(instance.mv(origin, destination, false)).to be === 0
50
48
  end
51
49
  end
52
50
 
@@ -62,7 +60,7 @@ module Beaker
62
60
  file = 'C:\path\to\file'
63
61
  expect(instance).to receive(:execute).with("powershell Test-Path #{file} -PathType Leaf")
64
62
  expect(instance).to receive(:execute).with(
65
- "powershell (gci C:\\path\\to\\file).LastWriteTime = Get-Date -Year '1970'-Month '1'-Day '1'-Hour '0'-Minute '0'-Second '0'"
63
+ "powershell (gci C:\\path\\to\\file).LastWriteTime = Get-Date -Year '1970'-Month '1'-Day '1'-Hour '0'-Minute '0'-Second '0'",
66
64
  )
67
65
  instance.modified_at(file, '197001010000')
68
66
  end
@@ -76,7 +74,7 @@ module Beaker
76
74
  expect(instance).to receive(:execute).with("powershell Test-Path #{file} -PathType Leaf")
77
75
  expect(instance).to receive(:execute).with("powershell New-Item -ItemType file #{file}")
78
76
  expect(instance).to receive(:execute).with(
79
- "powershell (gci C:\\path\\to\\file).LastWriteTime = Get-Date -Year '1970'-Month '1'-Day '1'-Hour '0'-Minute '0'-Second '0'"
77
+ "powershell (gci C:\\path\\to\\file).LastWriteTime = Get-Date -Year '1970'-Month '1'-Day '1'-Hour '0'-Minute '0'-Second '0'",
80
78
  )
81
79
  instance.modified_at(file, '197001010000')
82
80
  end
@@ -84,27 +82,27 @@ module Beaker
84
82
  end
85
83
 
86
84
  describe '#environment_string' do
87
- let(:host) { {'pathseparator' => ':'} }
85
+ let(:host) { { 'pathseparator' => ':' } }
88
86
 
89
87
  it 'returns a blank string if theres no env' do
90
- expect( instance.environment_string( {} ) ).to be == ''
88
+ expect(instance.environment_string({})).to be == ''
91
89
  end
92
90
 
93
91
  it 'takes an env hash with var_name/value pairs' do
94
- expect( instance.environment_string( {:HOME => '/', :http_proxy => 'http://foo'} ) ).
95
- to be == 'set "HOME=/" && set "http_proxy=http://foo" && set "HTTP_PROXY=http://foo" && '
92
+ expect(instance.environment_string({ :HOME => '/', :http_proxy => 'http://foo' }))
93
+ .to be == 'set "HOME=/" && set "http_proxy=http://foo" && set "HTTP_PROXY=http://foo" && '
96
94
  end
97
95
 
98
96
  it 'takes an env hash with var_name/value[Array] pairs' do
99
- expect( instance.environment_string( {:LD_PATH => ['/', '/tmp']}) ).
100
- to be == "set \"LD_PATH=/:/tmp\" && "
97
+ expect(instance.environment_string({ :LD_PATH => ['/', '/tmp'] }))
98
+ .to be == "set \"LD_PATH=/:/tmp\" && "
101
99
  end
102
100
  end
103
101
 
104
102
  describe '#which' do
105
103
  before do
106
104
  allow(instance).to receive(:execute)
107
- .with(where_command, :accept_all_exit_codes => true).and_return(result)
105
+ .with(where_command, :accept_all_exit_codes => true).and_return(result)
108
106
  end
109
107
 
110
108
  let(:where_command) { "cmd /C \"where ruby\"" }
@@ -132,28 +130,28 @@ module Beaker
132
130
  end
133
131
 
134
132
  describe '#mkdir_p' do
135
- let(:dir_path) { "C:\\tmpdir\\my_dir" }
136
- let(:beaker_command) { instance_spy(Beaker::Command) }
137
- let(:command) {"-Command New-Item -Path '#{dir_path}' -ItemType 'directory'"}
138
- let(:result) { instance_spy(Beaker::Result) }
139
-
140
- before do
141
- allow(Beaker::Command).to receive(:new).
142
- with('powershell.exe', array_including(command)).and_return(beaker_command)
143
- allow(instance).to receive(:exec).with(beaker_command, :acceptable_exit_codes => [0, 1]).and_return(result)
144
- end
133
+ let(:dir_path) { "C:\\tmpdir\\my_dir" }
134
+ let(:beaker_command) { instance_spy(Beaker::Command) }
135
+ let(:command) { "-Command New-Item -Path '#{dir_path}' -ItemType 'directory'" }
136
+ let(:result) { instance_spy(Beaker::Result) }
145
137
 
146
- it 'returns true and creates folder structure' do
147
- allow(result).to receive(:exit_code).and_return(0)
138
+ before do
139
+ allow(Beaker::Command).to receive(:new)
140
+ .with('powershell.exe', array_including(command)).and_return(beaker_command)
141
+ allow(instance).to receive(:exec).with(beaker_command, :acceptable_exit_codes => [0, 1]).and_return(result)
142
+ end
148
143
 
149
- expect(instance.mkdir_p(dir_path)).to be(true)
150
- end
144
+ it 'returns true and creates folder structure' do
145
+ allow(result).to receive(:exit_code).and_return(0)
151
146
 
152
- it 'returns false if failed to create directory structure' do
153
- allow(result).to receive(:exit_code).and_return(1)
147
+ expect(instance.mkdir_p(dir_path)).to be(true)
148
+ end
154
149
 
155
- expect(instance.mkdir_p(dir_path)).to be(false)
156
- end
150
+ it 'returns false if failed to create directory structure' do
151
+ allow(result).to receive(:exit_code).and_return(1)
152
+
153
+ expect(instance.mkdir_p(dir_path)).to be(false)
157
154
  end
155
+ end
158
156
  end
159
157
  end
@@ -21,7 +21,7 @@ module Beaker
21
21
  end
22
22
 
23
23
  let(:opts) { @opts || {} }
24
- let(:logger) { double( 'logger' ).as_null_object }
24
+ let(:logger) { double('logger').as_null_object }
25
25
  let(:instance) { PSWindowsFileTest.new(opts, logger) }
26
26
 
27
27
  describe '#cat' do
@@ -67,14 +67,14 @@ module Beaker
67
67
  let(:name) { 'my_dir' }
68
68
 
69
69
  it 'returns the path to my_dir' do
70
- expect(Beaker::Command).to receive(:new).
71
- with('powershell.exe', array_including('-Command [System.IO.Path]::GetTempPath()')).
72
- and_return(fake_command)
70
+ expect(Beaker::Command).to receive(:new)
71
+ .with('powershell.exe', array_including('-Command [System.IO.Path]::GetTempPath()'))
72
+ .and_return(fake_command)
73
73
  expect(instance).to receive(:exec).with(instance_of(Beaker::Command)).and_return(double(stdout: tmp_path))
74
74
 
75
- expect(Beaker::Command).to receive(:new).
76
- with('powershell.exe', array_including("-Command New-Item -Path '#{tmp_path}' -Force -Name '#{name}' -ItemType 'directory'")).
77
- and_return(fake_command)
75
+ expect(Beaker::Command).to receive(:new)
76
+ .with('powershell.exe', array_including("-Command New-Item -Path '#{tmp_path}' -Force -Name '#{name}' -ItemType 'directory'"))
77
+ .and_return(fake_command)
78
78
  expect(instance).to receive(:exec).with(instance_of(Beaker::Command)).and_return(true)
79
79
 
80
80
  expect(instance.tmpdir(name)).to eq(File.join(tmp_path, name))
@@ -86,19 +86,19 @@ module Beaker
86
86
  let(:random_dir) { 'dirname' }
87
87
 
88
88
  it 'returns the path to random name dir' do
89
- expect(Beaker::Command).to receive(:new).
90
- with('powershell.exe', array_including('-Command [System.IO.Path]::GetTempPath()')).
91
- and_return(fake_command)
89
+ expect(Beaker::Command).to receive(:new)
90
+ .with('powershell.exe', array_including('-Command [System.IO.Path]::GetTempPath()'))
91
+ .and_return(fake_command)
92
92
  expect(instance).to receive(:exec).with(instance_of(Beaker::Command)).and_return(double(stdout: tmp_path))
93
93
 
94
- expect(Beaker::Command).to receive(:new).
95
- with('powershell.exe', array_including('-Command [System.IO.Path]::GetRandomFileName()')).
96
- and_return(fake_command)
94
+ expect(Beaker::Command).to receive(:new)
95
+ .with('powershell.exe', array_including('-Command [System.IO.Path]::GetRandomFileName()'))
96
+ .and_return(fake_command)
97
97
  expect(instance).to receive(:exec).with(instance_of(Beaker::Command)).and_return(double(stdout: random_dir))
98
98
 
99
- expect(Beaker::Command).to receive(:new).
100
- with('powershell.exe', array_including("-Command New-Item -Path '#{tmp_path}' -Force -Name '#{random_dir}' -ItemType 'directory'")).
101
- and_return(fake_command)
99
+ expect(Beaker::Command).to receive(:new)
100
+ .with('powershell.exe', array_including("-Command New-Item -Path '#{tmp_path}' -Force -Name '#{random_dir}' -ItemType 'directory'"))
101
+ .and_return(fake_command)
102
102
  expect(instance).to receive(:exec).with(instance_of(Beaker::Command)).and_return(true)
103
103
 
104
104
  expect(instance.tmpdir).to eq(File.join(tmp_path, random_dir))
@@ -5,66 +5,60 @@ class PSWindowsUserTest
5
5
  end
6
6
 
7
7
  describe PSWindowsUserTest do
8
- let( :wmic_output ) do <<-EOS
8
+ let(:wmic_output) do
9
+ <<~EOS
10
+ Name=Administrator
9
11
 
10
12
 
11
13
 
12
14
 
13
- Name=Administrator
14
15
 
16
+ Name=bob foo
15
17
 
16
18
 
17
19
 
18
20
 
19
- Name=bob foo
20
21
 
22
+ Name=bob-dash
21
23
 
22
24
 
23
25
 
24
26
 
25
- Name=bob-dash
26
27
 
28
+ Name=bob.foo
27
29
 
28
30
 
29
31
 
30
32
 
31
- Name=bob.foo
32
33
 
34
+ Name=cyg_server
33
35
 
34
36
 
35
37
 
36
38
 
37
- Name=cyg_server
38
39
 
39
40
 
40
41
 
41
42
 
42
-
43
-
44
-
45
-
46
- EOS
43
+ EOS
47
44
  end
48
- let( :command ) { 'cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value' }
49
- let( :host ) { double.as_null_object }
50
- let( :result ) { Beaker::Result.new( host, command ) }
45
+ let(:command) { 'cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value' }
46
+ let(:host) { double.as_null_object }
47
+ let(:result) { Beaker::Result.new(host, command) }
51
48
 
52
49
  describe '#user_list' do
53
-
54
50
  it 'returns user names list correctly' do
55
51
  result.stdout = wmic_output
56
- expect( subject ).to receive( :execute ).with( command ).and_yield(result)
57
- expect( subject.user_list ).to be === ['Administrator', 'bob foo', 'bob-dash', 'bob.foo', 'cyg_server']
52
+ expect(subject).to receive(:execute).with(command).and_yield(result)
53
+ expect(subject.user_list).to be === ['Administrator', 'bob foo', 'bob-dash', 'bob.foo', 'cyg_server']
58
54
  end
59
55
 
60
56
  it 'yields correctly with the result object' do
61
57
  result.stdout = wmic_output
62
- expect( subject ).to receive( :execute ).and_yield(result)
63
- subject.user_list { |result|
64
- expect( result.stdout ).to be === wmic_output
65
- }
58
+ expect(subject).to receive(:execute).and_yield(result)
59
+ subject.user_list do |result|
60
+ expect(result.stdout).to be === wmic_output
61
+ end
66
62
  end
67
-
68
63
  end
69
-
70
64
  end