beaker 4.41.2 → 5.0.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 +23 -10
- data/.rubocop_todo.yml +34 -10
- data/CHANGELOG.md +16 -52
- data/Gemfile +12 -7
- data/HISTORY.md +605 -0
- 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 +6 -5
- 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 -7
- 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 -39
- 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 +81 -83
- data/lib/beaker/host/unix/file.rb +40 -45
- data/lib/beaker/host/unix/group.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +138 -401
- 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 +88 -196
- 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 -25
- 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 +25 -30
- data/lib/beaker/platform.rb +26 -37
- 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 +16 -28
- 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 +6 -7
- 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 +22 -31
- 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 +172 -161
- 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 +48 -57
- data/spec/beaker/host/mac/user_spec.rb +54 -63
- 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 -71
- data/spec/beaker/host/unix/pkg_spec.rb +150 -411
- 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 +168 -349
- 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 -50
- 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 +39 -45
- data/spec/matchers.rb +8 -7
- data/spec/mocks.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- metadata +8 -24
- 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,202 +5,198 @@ module Beaker
|
|
5
5
|
describe SshConnection do
|
6
6
|
subject(:connection) { described_class.new name_hash, user, ssh_opts, options }
|
7
7
|
|
8
|
-
let(
|
9
|
-
let(
|
10
|
-
let(
|
11
|
-
let(
|
12
|
-
let(
|
13
|
-
let(
|
14
|
-
let(
|
15
|
-
|
8
|
+
let(:user) { 'root' }
|
9
|
+
let(:ssh_opts) { { keepalive: true, keepalive_interval: 2 } }
|
10
|
+
let(:options) { { :logger => double('logger').as_null_object, :ssh_connection_preference => %i[ip vmhostname hostname] } }
|
11
|
+
let(:ip) { "default.ip.address" }
|
12
|
+
let(:vmhostname) { "vmhostname" }
|
13
|
+
let(:hostname) { "my_host" }
|
14
|
+
let(:name_hash) { { :ip => ip, :vmhostname => vmhostname, :hostname => hostname } }
|
16
15
|
|
17
16
|
before do
|
18
|
-
allow(
|
17
|
+
allow(subject).to receive(:sleep)
|
19
18
|
end
|
20
19
|
|
21
20
|
it 'self.connect creates connects and returns a proxy for that connection' do
|
22
|
-
expect(
|
21
|
+
expect(Net::SSH).to receive(:start).with("default.ip.address", user, ssh_opts).and_return(true)
|
23
22
|
connection_constructor = described_class.connect name_hash, user, ssh_opts, options
|
24
|
-
expect(
|
23
|
+
expect(connection_constructor).to be_a described_class
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'connect creates a new connection' do
|
28
|
-
expect(
|
27
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts).and_return(true)
|
29
28
|
connection.connect
|
30
29
|
end
|
31
30
|
|
32
31
|
it 'connect caches its connection' do
|
33
|
-
expect(
|
32
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts).once.and_return true
|
34
33
|
connection.connect
|
35
34
|
end
|
36
35
|
|
37
36
|
it 'attempts to connect by vmhostname address if ip connection fails' do
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
37
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts).and_return(false)
|
38
|
+
expect(Net::SSH).to receive(:start).with(vmhostname, user, ssh_opts).and_return(true).once
|
39
|
+
expect(Net::SSH).not_to receive(:start).with(hostname, user, ssh_opts)
|
41
40
|
connection.connect
|
42
41
|
end
|
43
42
|
|
44
43
|
it 'attempts to connect by hostname, if vmhost + ipaddress have failed' do
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
44
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts).and_return(false)
|
45
|
+
expect(Net::SSH).to receive(:start).with(vmhostname, user, ssh_opts).and_return(false)
|
46
|
+
expect(Net::SSH).to receive(:start).with(hostname, user, ssh_opts).and_return(true).once
|
48
47
|
connection.connect
|
49
|
-
|
50
48
|
end
|
51
49
|
|
52
50
|
describe '#close' do
|
53
|
-
|
54
51
|
it 'runs ssh close' do
|
55
52
|
mock_ssh = Object.new
|
56
|
-
expect(
|
53
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
57
54
|
connection.connect
|
58
55
|
|
59
|
-
allow(
|
60
|
-
expect(
|
56
|
+
allow(mock_ssh).to receive(:closed?).once.and_return(false)
|
57
|
+
expect(mock_ssh).to receive(:close).once
|
61
58
|
connection.close
|
62
59
|
end
|
63
60
|
|
64
61
|
it 'sets the @ssh variable to nil' do
|
65
62
|
mock_ssh = Object.new
|
66
|
-
expect(
|
63
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
67
64
|
connection.connect
|
68
65
|
|
69
|
-
allow(
|
70
|
-
expect(
|
66
|
+
allow(mock_ssh).to receive(:closed?).once.and_return(false)
|
67
|
+
expect(mock_ssh).to receive(:close).once
|
71
68
|
connection.close
|
72
69
|
|
73
|
-
expect(
|
70
|
+
expect(connection.instance_variable_get(:@ssh)).to be_nil
|
74
71
|
end
|
75
72
|
|
76
73
|
it 'calls ssh shutdown & re-raises if ssh close fails with an unexpected Error' do
|
77
74
|
mock_ssh = Object.new
|
78
|
-
allow(
|
79
|
-
expect(
|
75
|
+
allow(mock_ssh).to receive(:close) { raise StandardError }
|
76
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
80
77
|
connection.connect
|
81
78
|
|
82
|
-
allow(
|
83
|
-
expect(
|
84
|
-
expect{ connection.close }.to raise_error(StandardError)
|
85
|
-
expect(
|
79
|
+
allow(mock_ssh).to receive(:closed?).once.and_return(false)
|
80
|
+
expect(mock_ssh).to receive(:shutdown!).once
|
81
|
+
expect { connection.close }.to raise_error(StandardError)
|
82
|
+
expect(connection.instance_variable_get(:@ssh)).to be_nil
|
86
83
|
end
|
87
|
-
|
88
84
|
end
|
89
85
|
|
90
86
|
describe '#execute' do
|
91
87
|
it 'raises an error if it fails' do
|
92
88
|
mock_ssh = Object.new
|
93
|
-
expect(
|
89
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
94
90
|
connection.connect
|
95
91
|
|
96
|
-
allow(
|
92
|
+
allow(subject).to receive(:try_to_execute) { raise Timeout::Error }
|
97
93
|
|
98
|
-
expect{ connection.execute('ls') }.to raise_error Timeout::Error
|
94
|
+
expect { connection.execute('ls') }.to raise_error Timeout::Error
|
99
95
|
end
|
100
96
|
end
|
101
97
|
|
102
98
|
describe '#request_terminal_for' do
|
103
99
|
it 'fails correctly by raising Net::SSH::Exception' do
|
104
100
|
mock_ssh = Object.new
|
105
|
-
expect(
|
101
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
106
102
|
connection.connect
|
107
103
|
|
108
104
|
mock_channel = Object.new
|
109
|
-
allow(
|
105
|
+
allow(mock_channel).to receive(:request_pty).and_yield(nil, false)
|
110
106
|
|
111
|
-
expect{ connection.request_terminal_for mock_channel, 'ls' }.to raise_error Net::SSH::Exception
|
107
|
+
expect { connection.request_terminal_for mock_channel, 'ls' }.to raise_error Net::SSH::Exception
|
112
108
|
end
|
113
109
|
end
|
114
110
|
|
115
111
|
describe '#register_stdout_for' do
|
116
112
|
before do
|
117
113
|
@mock_ssh = Object.new
|
118
|
-
expect(
|
114
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
119
115
|
connection.connect
|
120
116
|
|
121
117
|
@data = '7 of clubs'
|
122
118
|
@mock_channel = Object.new
|
123
|
-
allow(
|
119
|
+
allow(@mock_channel).to receive(:on_data).and_yield(nil, @data)
|
124
120
|
|
125
121
|
@mock_output = Object.new
|
126
122
|
@mock_output_stdout = Object.new
|
127
123
|
@mock_output_output = Object.new
|
128
|
-
allow(
|
129
|
-
allow(
|
130
|
-
allow(
|
131
|
-
allow(
|
124
|
+
allow(@mock_output).to receive(:stdout) { @mock_output_stdout }
|
125
|
+
allow(@mock_output).to receive(:output) { @mock_output_output }
|
126
|
+
allow(@mock_output_stdout).to receive(:<<)
|
127
|
+
allow(@mock_output_output).to receive(:<<)
|
132
128
|
end
|
133
129
|
|
134
130
|
it 'puts data into stdout & output correctly' do
|
135
|
-
expect(
|
136
|
-
expect(
|
131
|
+
expect(@mock_output_stdout).to receive(:<<).with(@data)
|
132
|
+
expect(@mock_output_output).to receive(:<<).with(@data)
|
137
133
|
|
138
134
|
connection.register_stdout_for @mock_channel, @mock_output
|
139
135
|
end
|
140
136
|
|
141
137
|
it 'calls the callback if given' do
|
142
138
|
@mock_callback = Object.new
|
143
|
-
expect(
|
139
|
+
expect(@mock_callback).to receive(:[]).with(@data)
|
144
140
|
|
145
141
|
connection.register_stdout_for @mock_channel, @mock_output, @mock_callback
|
146
142
|
end
|
147
143
|
end
|
148
144
|
|
149
145
|
describe '#register_stderr_for' do
|
150
|
-
let(
|
146
|
+
let(:result) { Beaker::Result.new('hostname', 'command') }
|
151
147
|
|
152
148
|
before do
|
153
149
|
@mock_ssh = Object.new
|
154
|
-
expect(
|
150
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
155
151
|
connection.connect
|
156
152
|
|
157
153
|
@data = '3 of spades'
|
158
154
|
@mock_channel = Object.new
|
159
|
-
allow(
|
155
|
+
allow(@mock_channel).to receive(:on_extended_data).and_yield(nil, 1, @data)
|
160
156
|
end
|
161
157
|
|
162
158
|
it 'puts data into stderr & output correctly' do
|
163
|
-
expect(
|
164
|
-
expect(
|
159
|
+
expect(result.stderr).to receive(:<<).with(@data)
|
160
|
+
expect(result.output).to receive(:<<).with(@data)
|
165
161
|
|
166
162
|
connection.register_stderr_for @mock_channel, result
|
167
163
|
end
|
168
164
|
|
169
165
|
it 'calls the callback if given' do
|
170
166
|
@mock_callback = Object.new
|
171
|
-
expect(
|
167
|
+
expect(@mock_callback).to receive(:[]).with(@data)
|
172
168
|
|
173
169
|
connection.register_stderr_for @mock_channel, result, @mock_callback
|
174
170
|
end
|
175
171
|
|
176
172
|
it 'skips everything if type is not 1' do
|
177
|
-
allow(
|
173
|
+
allow(@mock_channel).to receive(:on_extended_data).and_yield(nil, '1', @data)
|
178
174
|
|
179
175
|
@mock_callback = Object.new
|
180
|
-
expect(
|
181
|
-
expect(
|
182
|
-
expect(
|
176
|
+
expect(@mock_callback).not_to receive(:[])
|
177
|
+
expect(result.stderr).not_to receive(:<<)
|
178
|
+
expect(result.output).not_to receive(:<<)
|
183
179
|
|
184
180
|
connection.register_stderr_for @mock_channel, result, @mock_callback
|
185
181
|
end
|
186
182
|
end
|
187
183
|
|
188
184
|
describe '#register_exit_code_for' do
|
189
|
-
let(
|
185
|
+
let(:result) { Beaker::Result.new('hostname', 'command') }
|
190
186
|
|
191
187
|
it 'assigns the output\'s exit code correctly from the data' do
|
192
188
|
mock_ssh = Object.new
|
193
|
-
expect(
|
189
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { mock_ssh }
|
194
190
|
connection.connect
|
195
191
|
|
196
192
|
data = '10 of jeromes'
|
197
193
|
mock_data = Object.new
|
198
|
-
allow(
|
194
|
+
allow(mock_data).to receive(:read_long) { data }
|
199
195
|
mock_channel = Object.new
|
200
|
-
allow(
|
196
|
+
allow(mock_channel).to receive(:on_request).with('exit-status').and_yield(nil, mock_data)
|
201
197
|
|
202
198
|
connection.register_exit_code_for mock_channel, result
|
203
|
-
expect(
|
199
|
+
expect(result.exit_code).to be === data
|
204
200
|
end
|
205
201
|
end
|
206
202
|
|
@@ -209,9 +205,9 @@ module Beaker
|
|
209
205
|
stdin = 'jean shorts'
|
210
206
|
mock_channel = Object.new
|
211
207
|
|
212
|
-
expect(
|
213
|
-
expect(
|
214
|
-
expect(
|
208
|
+
expect(mock_channel).to receive(:send_data).with(stdin).ordered.once
|
209
|
+
expect(mock_channel).to receive(:process).ordered.once
|
210
|
+
expect(mock_channel).to receive(:eof!).ordered.once
|
215
211
|
|
216
212
|
connection.process_stdin_for mock_channel, stdin
|
217
213
|
end
|
@@ -221,55 +217,52 @@ module Beaker
|
|
221
217
|
before do
|
222
218
|
@mock_ssh = Object.new
|
223
219
|
@mock_scp = Object.new
|
224
|
-
allow(
|
225
|
-
allow(
|
226
|
-
expect(
|
220
|
+
allow(@mock_scp).to receive(:upload!)
|
221
|
+
allow(@mock_ssh).to receive(:scp).and_return(@mock_scp)
|
222
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
227
223
|
connection.connect
|
228
224
|
end
|
229
225
|
|
230
226
|
it 'calls scp.upload!' do
|
231
|
-
expect(
|
227
|
+
expect(@mock_scp).to receive(:upload!).once
|
232
228
|
connection.scp_to '', ''
|
233
229
|
end
|
234
230
|
|
235
231
|
it 'ensures the connection closes when scp.upload! errors' do
|
236
|
-
expect(
|
232
|
+
expect(@mock_scp).to receive(:upload!).once.and_raise(RuntimeError)
|
237
233
|
expect(connection).to receive(:close).once
|
238
234
|
connection.scp_to '', ''
|
239
235
|
end
|
240
236
|
|
241
237
|
it 'returns a result object' do
|
242
|
-
expect(
|
238
|
+
expect(connection.scp_to '', '').to be_a Beaker::Result
|
243
239
|
end
|
244
|
-
|
245
240
|
end
|
246
241
|
|
247
242
|
describe '#scp_from' do
|
248
243
|
before do
|
249
244
|
@mock_ssh = Object.new
|
250
245
|
@mock_scp = Object.new
|
251
|
-
allow(
|
252
|
-
allow(
|
253
|
-
expect(
|
246
|
+
allow(@mock_scp).to receive(:download!)
|
247
|
+
allow(@mock_ssh).to receive(:scp).and_return(@mock_scp)
|
248
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
254
249
|
connection.connect
|
255
250
|
end
|
256
251
|
|
257
252
|
it 'calls scp.download!' do
|
258
|
-
expect(
|
253
|
+
expect(@mock_scp).to receive(:download!).once
|
259
254
|
connection.scp_from '', ''
|
260
255
|
end
|
261
256
|
|
262
257
|
it 'ensures the connection closes when scp.download! errors' do
|
263
|
-
expect(
|
258
|
+
expect(@mock_scp).to receive(:download!).once.and_raise(RuntimeError)
|
264
259
|
expect(connection).to receive(:close).once
|
265
260
|
connection.scp_from '', ''
|
266
261
|
end
|
267
262
|
|
268
263
|
it 'returns a result object' do
|
269
|
-
expect(
|
264
|
+
expect(connection.scp_from '', '').to be_a Beaker::Result
|
270
265
|
end
|
271
|
-
|
272
266
|
end
|
273
|
-
|
274
267
|
end
|
275
268
|
end
|
@@ -3,58 +3,57 @@ require 'spec_helper'
|
|
3
3
|
module Beaker
|
4
4
|
module Subcommands
|
5
5
|
describe SubcommandUtil do
|
6
|
-
|
7
|
-
let(:cli) {
|
6
|
+
let(:cli) do
|
8
7
|
double("cli")
|
9
|
-
|
8
|
+
end
|
10
9
|
|
11
|
-
let(:rake)
|
10
|
+
let(:rake) do
|
12
11
|
double("rake")
|
13
|
-
|
12
|
+
end
|
14
13
|
|
15
|
-
let(:file)
|
14
|
+
let(:file) do
|
16
15
|
double("file")
|
17
|
-
|
16
|
+
end
|
18
17
|
|
19
|
-
let(:store)
|
18
|
+
let(:store) do
|
20
19
|
double("store")
|
21
|
-
|
20
|
+
end
|
22
21
|
|
23
|
-
let(:host)
|
22
|
+
let(:host) do
|
24
23
|
double("host")
|
25
|
-
|
24
|
+
end
|
26
25
|
|
27
|
-
let(:hypervisors)
|
26
|
+
let(:hypervisors) do
|
28
27
|
double("hypervisors")
|
29
|
-
|
28
|
+
end
|
30
29
|
|
31
|
-
let(:hosts)
|
30
|
+
let(:hosts) do
|
32
31
|
double("hosts")
|
33
|
-
|
32
|
+
end
|
34
33
|
|
35
|
-
let(:hypervisors_object)
|
34
|
+
let(:hypervisors_object) do
|
36
35
|
double("hypervisors_object")
|
37
|
-
|
36
|
+
end
|
38
37
|
|
39
|
-
let(:hosts_object)
|
38
|
+
let(:hosts_object) do
|
40
39
|
double("hosts_object")
|
41
|
-
|
40
|
+
end
|
42
41
|
|
43
|
-
let(:network_manager)
|
42
|
+
let(:network_manager) do
|
44
43
|
double("network_manager")
|
45
|
-
|
44
|
+
end
|
46
45
|
|
47
|
-
let(:save_object)
|
46
|
+
let(:save_object) do
|
48
47
|
double("save_object")
|
49
|
-
|
48
|
+
end
|
50
49
|
|
51
|
-
let(:load_object)
|
50
|
+
let(:load_object) do
|
52
51
|
double("load_object")
|
53
|
-
|
52
|
+
end
|
54
53
|
|
55
|
-
let(:yaml_object)
|
54
|
+
let(:yaml_object) do
|
56
55
|
double("yaml_object")
|
57
|
-
|
56
|
+
end
|
58
57
|
|
59
58
|
describe 'execute_subcommand' do
|
60
59
|
it "determines if we should execute the init subcommand" do
|
@@ -78,13 +77,12 @@ module Beaker
|
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
|
-
|
82
80
|
describe 'error_with' do
|
83
81
|
it "the exit value should default to 1" do
|
84
82
|
expect(STDOUT).to receive(:puts).with("exiting").once
|
85
83
|
begin
|
86
84
|
subject.error_with("exiting")
|
87
|
-
rescue SystemExit=>e
|
85
|
+
rescue SystemExit => e
|
88
86
|
expect(e.status).to eq(1)
|
89
87
|
end
|
90
88
|
end
|
@@ -92,8 +90,8 @@ module Beaker
|
|
92
90
|
it "the exit value should return specified value" do
|
93
91
|
expect(STDOUT).to receive(:puts).with("exiting").once
|
94
92
|
begin
|
95
|
-
subject.error_with("exiting", {exit_code: 3})
|
96
|
-
rescue SystemExit=>e
|
93
|
+
subject.error_with("exiting", { exit_code: 3 })
|
94
|
+
rescue SystemExit => e
|
97
95
|
expect(e.status).to eq(3)
|
98
96
|
end
|
99
97
|
end
|
@@ -102,8 +100,8 @@ module Beaker
|
|
102
100
|
expect(STDOUT).to receive(:puts).with("exiting").once
|
103
101
|
expect(STDOUT).to receive(:puts).with("testing").once
|
104
102
|
begin
|
105
|
-
subject.error_with("exiting", {stack_trace: "testing"})
|
106
|
-
rescue SystemExit=>e
|
103
|
+
subject.error_with("exiting", { stack_trace: "testing" })
|
104
|
+
rescue SystemExit => e
|
107
105
|
expect(e.status).to eq(1)
|
108
106
|
end
|
109
107
|
end
|