beaker 4.39.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +26 -13
- data/.rubocop.yml +6 -21
- data/.rubocop_todo.yml +34 -10
- data/CHANGELOG.md +22 -0
- data/Gemfile +12 -7
- data/Rakefile +99 -111
- data/acceptance/config/acceptance-options.rb +1 -1
- data/acceptance/config/base/acceptance-options.rb +2 -2
- data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
- data/acceptance/config/subcommands/acceptance-options.rb +2 -2
- data/acceptance/fixtures/module/Rakefile +1 -1
- data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
- data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
- data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
- data/acceptance/lib/helpers/test_helper.rb +4 -3
- data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
- data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
- data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
- data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
- data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
- data/acceptance/tests/base/dsl/structure_test.rb +5 -11
- data/acceptance/tests/base/host/file_test.rb +2 -2
- data/acceptance/tests/base/host/group_test.rb +0 -1
- data/acceptance/tests/base/host/host_test.rb +66 -63
- data/acceptance/tests/base/host/packages.rb +1 -2
- data/acceptance/tests/base/host/packages_unix.rb +0 -55
- data/acceptance/tests/base/host/user_test.rb +0 -1
- data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
- data/acceptance/tests/base/test_suite/export.rb +6 -9
- data/acceptance/tests/install/from_file.rb +2 -4
- data/acceptance/tests/load_path_bootstrap.rb +1 -1
- data/acceptance/tests/subcommands/destroy.rb +19 -21
- data/acceptance/tests/subcommands/exec.rb +0 -1
- data/acceptance/tests/subcommands/init.rb +2 -3
- data/acceptance/tests/subcommands/provision.rb +0 -1
- data/beaker.gemspec +4 -8
- data/docs/concepts/argument_processing_and_precedence.md +1 -10
- data/docs/how_to/debug_beaker_tests.md +12 -12
- data/docs/how_to/hosts/eos.md +2 -12
- data/docs/how_to/install_puppet.md +0 -18
- data/docs/how_to/the_beaker_dsl.md +0 -2
- data/lib/beaker/cli.rb +59 -68
- data/lib/beaker/command.rb +20 -28
- data/lib/beaker/command_factory.rb +3 -2
- data/lib/beaker/dsl/assertions.rb +6 -18
- data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
- data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
- data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
- data/lib/beaker/dsl/helpers/web_helpers.rb +19 -27
- data/lib/beaker/dsl/helpers.rb +2 -4
- data/lib/beaker/dsl/outcomes.rb +13 -15
- data/lib/beaker/dsl/patterns.rb +1 -3
- data/lib/beaker/dsl/roles.rb +17 -20
- data/lib/beaker/dsl/structure.rb +53 -65
- data/lib/beaker/dsl/test_tagging.rb +7 -10
- data/lib/beaker/dsl/wrappers.rb +15 -16
- data/lib/beaker/dsl.rb +2 -3
- data/lib/beaker/host/aix/exec.rb +1 -1
- data/lib/beaker/host/aix/file.rb +0 -1
- data/lib/beaker/host/aix/group.rb +1 -1
- data/lib/beaker/host/aix/user.rb +1 -1
- data/lib/beaker/host/aix.rb +3 -4
- data/lib/beaker/host/cisco.rb +27 -39
- data/lib/beaker/host/eos.rb +4 -30
- data/lib/beaker/host/freebsd/exec.rb +1 -1
- data/lib/beaker/host/freebsd/pkg.rb +3 -3
- data/lib/beaker/host/freebsd.rb +9 -12
- data/lib/beaker/host/mac/exec.rb +4 -4
- data/lib/beaker/host/mac/group.rb +7 -7
- data/lib/beaker/host/mac/pkg.rb +3 -106
- data/lib/beaker/host/mac/user.rb +2 -2
- data/lib/beaker/host/mac.rb +8 -9
- data/lib/beaker/host/pswindows/exec.rb +66 -70
- data/lib/beaker/host/pswindows/file.rb +3 -5
- data/lib/beaker/host/pswindows/group.rb +3 -3
- data/lib/beaker/host/pswindows/pkg.rb +12 -12
- data/lib/beaker/host/pswindows/user.rb +3 -3
- data/lib/beaker/host/pswindows.rb +4 -3
- data/lib/beaker/host/unix/exec.rb +80 -82
- data/lib/beaker/host/unix/file.rb +38 -43
- data/lib/beaker/host/unix/group.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +154 -417
- data/lib/beaker/host/unix/user.rb +2 -2
- data/lib/beaker/host/unix.rb +8 -11
- data/lib/beaker/host/windows/exec.rb +17 -17
- data/lib/beaker/host/windows/file.rb +3 -3
- data/lib/beaker/host/windows/group.rb +3 -3
- data/lib/beaker/host/windows/pkg.rb +3 -54
- data/lib/beaker/host/windows/user.rb +3 -3
- data/lib/beaker/host/windows.rb +12 -12
- data/lib/beaker/host.rb +76 -133
- data/lib/beaker/host_prebuilt_steps.rb +93 -198
- data/lib/beaker/hypervisor/noop.rb +2 -4
- data/lib/beaker/hypervisor.rb +44 -61
- data/lib/beaker/local_connection.rb +2 -4
- data/lib/beaker/logger.rb +68 -76
- data/lib/beaker/logger_junit.rb +21 -25
- data/lib/beaker/network_manager.rb +39 -42
- data/lib/beaker/options/command_line_parser.rb +12 -23
- data/lib/beaker/options/hosts_file_parser.rb +16 -24
- data/lib/beaker/options/options_file_parser.rb +3 -6
- data/lib/beaker/options/options_hash.rb +2 -7
- data/lib/beaker/options/parser.rb +86 -102
- data/lib/beaker/options/presets.rb +114 -123
- data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
- data/lib/beaker/options/validator.rb +26 -31
- data/lib/beaker/perf.rb +22 -27
- data/lib/beaker/platform.rb +38 -46
- data/lib/beaker/result.rb +7 -6
- data/lib/beaker/shared/error_handler.rb +8 -10
- data/lib/beaker/shared/fog_credentials.rb +5 -9
- data/lib/beaker/shared/host_manager.rb +36 -41
- data/lib/beaker/shared/options_resolver.rb +3 -7
- data/lib/beaker/shared/repetition.rb +2 -4
- data/lib/beaker/shared/semvar.rb +37 -41
- data/lib/beaker/shared/timed.rb +0 -3
- data/lib/beaker/shared.rb +1 -1
- data/lib/beaker/ssh_connection.rb +38 -47
- data/lib/beaker/subcommand.rb +17 -24
- data/lib/beaker/subcommands/subcommand_util.rb +4 -4
- data/lib/beaker/tasks/quick_start.rb +4 -9
- data/lib/beaker/tasks/rake_task.rb +25 -27
- data/lib/beaker/tasks/test.rb +4 -4
- data/lib/beaker/test_case.rb +15 -27
- data/lib/beaker/test_suite.rb +35 -39
- data/lib/beaker/test_suite_result.rb +45 -47
- data/lib/beaker/version.rb +1 -1
- data/lib/beaker.rb +5 -6
- data/rubocop.yml +39 -0
- data/spec/beaker/cli_spec.rb +121 -142
- data/spec/beaker/command_spec.rb +55 -59
- data/spec/beaker/dsl/assertions_spec.rb +36 -36
- data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
- data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
- data/spec/beaker/dsl/helpers/web_helpers_spec.rb +28 -34
- data/spec/beaker/dsl/outcomes_spec.rb +14 -14
- data/spec/beaker/dsl/roles_spec.rb +125 -130
- data/spec/beaker/dsl/structure_spec.rb +169 -158
- data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
- data/spec/beaker/dsl/wrappers_spec.rb +32 -33
- data/spec/beaker/host/aix_spec.rb +14 -14
- data/spec/beaker/host/cisco_spec.rb +84 -94
- data/spec/beaker/host/eos_spec.rb +15 -36
- data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
- data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
- data/spec/beaker/host/mac/exec_spec.rb +2 -3
- data/spec/beaker/host/mac/group_spec.rb +47 -56
- data/spec/beaker/host/mac/user_spec.rb +53 -62
- data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
- data/spec/beaker/host/pswindows/file_spec.rb +16 -16
- data/spec/beaker/host/pswindows/user_spec.rb +17 -23
- data/spec/beaker/host/pswindows_spec.rb +13 -13
- data/spec/beaker/host/unix/exec_spec.rb +75 -80
- data/spec/beaker/host/unix/file_spec.rb +66 -73
- data/spec/beaker/host/unix/pkg_spec.rb +155 -401
- data/spec/beaker/host/unix_spec.rb +11 -207
- data/spec/beaker/host/windows/exec_spec.rb +30 -32
- data/spec/beaker/host/windows/file_spec.rb +18 -19
- data/spec/beaker/host/windows/group_spec.rb +10 -12
- data/spec/beaker/host/windows/pkg_spec.rb +6 -9
- data/spec/beaker/host/windows/user_spec.rb +17 -23
- data/spec/beaker/host/windows_spec.rb +39 -39
- data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
- data/spec/beaker/host_spec.rb +204 -284
- data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
- data/spec/beaker/localhost_connection_spec.rb +10 -11
- data/spec/beaker/logger_junit_spec.rb +19 -30
- data/spec/beaker/logger_spec.rb +153 -136
- data/spec/beaker/network_manager_spec.rb +23 -23
- data/spec/beaker/options/command_line_parser_spec.rb +20 -23
- data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
- data/spec/beaker/options/options_file_parser_spec.rb +4 -7
- data/spec/beaker/options/options_hash_spec.rb +4 -6
- data/spec/beaker/options/parser_spec.rb +167 -167
- data/spec/beaker/options/presets_spec.rb +7 -9
- data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
- data/spec/beaker/options/validator_spec.rb +10 -11
- data/spec/beaker/perf_spec.rb +18 -21
- data/spec/beaker/platform_spec.rb +25 -36
- data/spec/beaker/shared/error_handler_spec.rb +7 -16
- data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
- data/spec/beaker/shared/host_manager_spec.rb +50 -84
- data/spec/beaker/shared/options_resolver_spec.rb +9 -12
- data/spec/beaker/shared/repetition_spec.rb +17 -24
- data/spec/beaker/shared/semvar_spec.rb +21 -26
- data/spec/beaker/ssh_connection_spec.rb +76 -83
- data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
- data/spec/beaker/subcommand_spec.rb +75 -77
- data/spec/beaker/test_case_spec.rb +25 -50
- data/spec/beaker/test_suite_spec.rb +147 -154
- data/spec/helpers.rb +48 -53
- data/spec/matchers.rb +8 -7
- data/spec/mocks.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- metadata +13 -37
- data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
- data/acceptance/tests/base/external_resources_test.rb +0 -31
- 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(
|
9
|
-
|
10
|
-
|
11
|
-
|
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(
|
16
|
-
|
17
|
-
|
18
|
-
|
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(
|
23
|
-
|
24
|
-
#{
|
25
|
-
|
24
|
+
let(:dscacheutil_list) do
|
25
|
+
<<~EOS
|
26
|
+
#{puppet1}
|
27
|
+
#{puppet2}
|
28
|
+
EOS
|
26
29
|
end
|
27
|
-
let(
|
28
|
-
let(
|
29
|
-
let(
|
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(
|
36
|
-
expect(
|
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(
|
42
|
-
subject.group_list
|
43
|
-
expect(
|
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(
|
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(
|
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(
|
73
|
-
expect(
|
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(
|
79
|
-
expect(
|
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(
|
89
|
-
expect(
|
90
|
-
subject.group_present(
|
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(
|
99
|
-
expect(
|
100
|
-
expect(
|
101
|
-
subject.group_present(
|
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(
|
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(
|
110
|
-
subject.group_present(
|
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(
|
120
|
-
subject.group_absent(
|
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(
|
130
|
-
expect(
|
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(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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(
|
31
|
-
|
32
|
-
#{
|
33
|
-
|
32
|
+
let(:dscacheutil_list) do
|
33
|
+
<<~EOS
|
34
|
+
#{puppet1}
|
35
|
+
#{puppet2}
|
36
|
+
EOS
|
34
37
|
end
|
35
|
-
let(
|
38
|
+
let(:etc_passwd_line) do
|
36
39
|
"puppet1:*:67:234::0:0:puppet1:/Users/puppet1:/bin/sh"
|
37
40
|
end
|
38
|
-
let(
|
39
|
-
let(
|
40
|
-
let(
|
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(
|
47
|
-
expect(
|
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(
|
53
|
-
subject.user_list
|
54
|
-
expect(
|
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(
|
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(
|
71
|
+
expect(subject).to receive(:execute).and_yield(result)
|
72
72
|
subject.user_get('puppet1') do |result|
|
73
|
-
expect(
|
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(
|
84
|
-
subject.user_present(
|
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(
|
94
|
-
expect(
|
95
|
-
expect(
|
96
|
-
expect(
|
97
|
-
subject.user_present(
|
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(
|
107
|
-
subject.user_absent(
|
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(
|
117
|
-
expect(
|
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(
|
127
|
-
expect(
|
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(
|
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(
|
49
|
-
expect(
|
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(
|
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(
|
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(
|
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
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
150
|
-
|
144
|
+
it 'returns true and creates folder structure' do
|
145
|
+
allow(result).to receive(:exit_code).and_return(0)
|
151
146
|
|
152
|
-
|
153
|
-
|
147
|
+
expect(instance.mkdir_p(dir_path)).to be(true)
|
148
|
+
end
|
154
149
|
|
155
|
-
|
156
|
-
|
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(
|
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(
|
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(
|
49
|
-
let(
|
50
|
-
let(
|
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(
|
57
|
-
expect(
|
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(
|
63
|
-
subject.user_list
|
64
|
-
expect(
|
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
|