beaker 4.40.1 → 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 +13 -11
- 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 -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 +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/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 +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 +7 -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
@@ -3,21 +3,20 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module Beaker
|
5
5
|
describe TestSuite do
|
6
|
-
|
7
6
|
context 'new' do
|
8
7
|
let(:test_dir) { 'tmp/tests' }
|
9
8
|
|
10
|
-
let(:options) { {'name' => create_files(@files)} }
|
9
|
+
let(:options) { { 'name' => create_files(@files) } }
|
11
10
|
let(:rb_test) { File.expand_path(test_dir + '/my_ruby_file.rb') }
|
12
11
|
let(:pl_test) { File.expand_path(test_dir + '/my_perl_file.pl') }
|
13
12
|
let(:sh_test) { File.expand_path(test_dir + '/my_shell_file.sh') }
|
14
13
|
|
15
14
|
it 'fails without test files' do
|
16
|
-
expect { described_class.new('name', 'hosts',
|
15
|
+
expect { described_class.new('name', 'hosts', {}, Time.now, :stop_on_error) }.to raise_error
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'includes specific files as test file when explicitly passed' do
|
20
|
-
@files = [
|
19
|
+
@files = [rb_test]
|
21
20
|
ts = described_class.new('name', 'hosts', options, Time.now, :stop_on_error)
|
22
21
|
|
23
22
|
tfs = ts.instance_variable_get(:@test_files)
|
@@ -25,21 +24,21 @@ module Beaker
|
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'defaults to :slow fail_mode if not provided through parameter or options' do
|
28
|
-
@files = [
|
27
|
+
@files = [rb_test]
|
29
28
|
ts = described_class.new('name', 'hosts', options, Time.now)
|
30
29
|
tfm = ts.instance_variable_get(:@fail_mode)
|
31
30
|
expect(tfm).to be == :slow
|
32
31
|
end
|
33
32
|
|
34
33
|
it 'uses provided parameter fail_mode' do
|
35
|
-
@files = [
|
34
|
+
@files = [rb_test]
|
36
35
|
ts = described_class.new('name', 'hosts', options, Time.now, :fast)
|
37
36
|
tfm = ts.instance_variable_get(:@fail_mode)
|
38
37
|
expect(tfm).to be == :fast
|
39
38
|
end
|
40
39
|
|
41
40
|
it 'uses options fail_mode if fail_mode parameter is not provided' do
|
42
|
-
@files = [
|
41
|
+
@files = [rb_test]
|
43
42
|
options[:fail_mode] = :fast
|
44
43
|
ts = described_class.new('name', 'hosts', options, Time.now)
|
45
44
|
tfm = ts.instance_variable_get(:@fail_mode)
|
@@ -48,252 +47,249 @@ module Beaker
|
|
48
47
|
end
|
49
48
|
|
50
49
|
context 'run' do
|
51
|
-
|
52
|
-
let( :options ) { make_opts.merge({ :logger => double().as_null_object, 'name' => create_files(@files), :log_dated_dir => '.', :xml_dated_dir => '.'}) }
|
50
|
+
let(:options) { make_opts.merge({ :logger => double.as_null_object, 'name' => create_files(@files), :log_dated_dir => '.', :xml_dated_dir => '.' }) }
|
53
51
|
let(:broken_script) { "raise RuntimeError" }
|
54
52
|
let(:fail_script) { "raise Beaker::DSL::Outcomes::FailTest" }
|
55
53
|
let(:okay_script) { "true" }
|
56
54
|
let(:rb_test) { 'my_ruby_file.rb' }
|
57
55
|
let(:pl_test) { '/my_perl_file.pl' }
|
58
56
|
let(:sh_test) { '/my_shell_file.sh' }
|
59
|
-
let(:hosts) { make_hosts
|
57
|
+
let(:hosts) { make_hosts }
|
60
58
|
|
61
59
|
it 'fails fast if fail_mode != :slow and runtime error is raised' do
|
62
|
-
allow(
|
63
|
-
@files = [
|
64
|
-
File.
|
65
|
-
File.
|
66
|
-
File.
|
60
|
+
allow(Logger).to receive('new')
|
61
|
+
@files = [rb_test, pl_test, sh_test]
|
62
|
+
File.write(rb_test, broken_script)
|
63
|
+
File.write(pl_test, okay_script)
|
64
|
+
File.write(sh_test, okay_script)
|
67
65
|
|
68
|
-
ts = described_class.new(
|
69
|
-
tsr = ts.instance_variable_get(
|
70
|
-
allow(
|
71
|
-
allow(
|
66
|
+
ts = described_class.new('name', hosts, options, Time.now, :stop)
|
67
|
+
tsr = ts.instance_variable_get(:@test_suite_results)
|
68
|
+
allow(tsr).to receive(:write_junit_xml).and_return(true)
|
69
|
+
allow(tsr).to receive(:summarize).and_return(true)
|
72
70
|
|
73
71
|
ts.run
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
|
72
|
+
expect(tsr.errored_tests).to be === 1
|
73
|
+
expect(tsr.failed_tests).to be === 0
|
74
|
+
expect(tsr.test_count).to be === 1
|
75
|
+
expect(tsr.passed_tests).to be === 0
|
79
76
|
end
|
80
77
|
|
81
78
|
it 'fails fast if fail_mode != :slow and fail test is raised' do
|
82
|
-
allow(
|
83
|
-
@files = [
|
84
|
-
File.
|
85
|
-
File.
|
86
|
-
File.
|
79
|
+
allow(Logger).to receive('new')
|
80
|
+
@files = [rb_test, pl_test, sh_test]
|
81
|
+
File.write(rb_test, fail_script)
|
82
|
+
File.write(pl_test, okay_script)
|
83
|
+
File.write(sh_test, okay_script)
|
87
84
|
|
88
|
-
ts = described_class.new(
|
89
|
-
tsr = ts.instance_variable_get(
|
90
|
-
allow(
|
91
|
-
allow(
|
85
|
+
ts = described_class.new('name', hosts, options, Time.now, :stop)
|
86
|
+
tsr = ts.instance_variable_get(:@test_suite_results)
|
87
|
+
allow(tsr).to receive(:write_junit_xml).and_return(true)
|
88
|
+
allow(tsr).to receive(:summarize).and_return(true)
|
92
89
|
|
93
90
|
ts.run
|
94
|
-
expect(
|
95
|
-
expect(
|
96
|
-
expect(
|
97
|
-
expect(
|
98
|
-
|
91
|
+
expect(tsr.errored_tests).to be === 0
|
92
|
+
expect(tsr.failed_tests).to be === 1
|
93
|
+
expect(tsr.test_count).to be === 1
|
94
|
+
expect(tsr.passed_tests).to be === 0
|
99
95
|
end
|
100
96
|
|
101
97
|
it 'fails slow if fail_mode = :slow, even if a test fails and there is a runtime error' do
|
102
|
-
allow(
|
103
|
-
@files = [
|
104
|
-
File.
|
105
|
-
File.
|
106
|
-
File.
|
98
|
+
allow(Logger).to receive('new')
|
99
|
+
@files = [rb_test, pl_test, sh_test]
|
100
|
+
File.write(rb_test, broken_script)
|
101
|
+
File.write(pl_test, fail_script)
|
102
|
+
File.write(sh_test, okay_script)
|
107
103
|
|
108
|
-
ts = described_class.new(
|
109
|
-
tsr = ts.instance_variable_get(
|
110
|
-
allow(
|
111
|
-
allow(
|
104
|
+
ts = described_class.new('name', hosts, options, Time.now, :slow)
|
105
|
+
tsr = ts.instance_variable_get(:@test_suite_results)
|
106
|
+
allow(tsr).to receive(:write_junit_xml).and_return(true)
|
107
|
+
allow(tsr).to receive(:summarize).and_return(true)
|
112
108
|
|
113
109
|
ts.run
|
114
|
-
expect(
|
115
|
-
expect(
|
116
|
-
expect(
|
117
|
-
expect(
|
118
|
-
|
110
|
+
expect(tsr.errored_tests).to be === 1
|
111
|
+
expect(tsr.failed_tests).to be === 1
|
112
|
+
expect(tsr.test_count).to be === 3
|
113
|
+
expect(tsr.passed_tests).to be === 1
|
119
114
|
end
|
120
115
|
end
|
121
116
|
|
122
117
|
describe TestSuiteResult do
|
123
|
-
|
124
|
-
let(
|
125
|
-
let(
|
126
|
-
let(
|
127
|
-
let(
|
128
|
-
let(
|
129
|
-
let( :test_suite_result ) { described_class.new( options, "my_suite") }
|
118
|
+
let(:options) { make_opts.merge({ :logger => double.as_null_object }) }
|
119
|
+
let(:hosts) { make_hosts }
|
120
|
+
let(:testcase1) { Beaker::TestCase.new(hosts, options[:logger], options) }
|
121
|
+
let(:testcase2) { Beaker::TestCase.new(hosts, options[:logger], options) }
|
122
|
+
let(:testcase3) { Beaker::TestCase.new(hosts, options[:logger], options) }
|
123
|
+
let(:test_suite_result) { described_class.new(options, "my_suite") }
|
130
124
|
|
131
125
|
it 'supports adding test cases' do
|
132
|
-
expect(
|
133
|
-
test_suite_result.add_test_case(
|
134
|
-
expect(
|
126
|
+
expect(test_suite_result.test_count).to be === 0
|
127
|
+
test_suite_result.add_test_case(testcase1)
|
128
|
+
expect(test_suite_result.test_count).to be === 1
|
135
129
|
end
|
136
130
|
|
137
131
|
it 'calculates passed tests' do
|
138
132
|
testcase1.instance_variable_set(:@test_status, :pass)
|
139
133
|
testcase2.instance_variable_set(:@test_status, :pass)
|
140
134
|
testcase3.instance_variable_set(:@test_status, :fail)
|
141
|
-
test_suite_result.add_test_case(
|
142
|
-
test_suite_result.add_test_case(
|
143
|
-
test_suite_result.add_test_case(
|
144
|
-
expect(
|
135
|
+
test_suite_result.add_test_case(testcase1)
|
136
|
+
test_suite_result.add_test_case(testcase2)
|
137
|
+
test_suite_result.add_test_case(testcase3)
|
138
|
+
expect(test_suite_result.passed_tests).to be == 2
|
145
139
|
end
|
146
140
|
|
147
141
|
it 'calculates failed tests' do
|
148
142
|
testcase1.instance_variable_set(:@test_status, :pass)
|
149
143
|
testcase2.instance_variable_set(:@test_status, :pass)
|
150
144
|
testcase3.instance_variable_set(:@test_status, :fail)
|
151
|
-
test_suite_result.add_test_case(
|
152
|
-
test_suite_result.add_test_case(
|
153
|
-
test_suite_result.add_test_case(
|
154
|
-
expect(
|
145
|
+
test_suite_result.add_test_case(testcase1)
|
146
|
+
test_suite_result.add_test_case(testcase2)
|
147
|
+
test_suite_result.add_test_case(testcase3)
|
148
|
+
expect(test_suite_result.failed_tests).to be == 1
|
155
149
|
end
|
156
150
|
|
157
151
|
it 'calculates errored tests' do
|
158
152
|
testcase1.instance_variable_set(:@test_status, :error)
|
159
153
|
testcase2.instance_variable_set(:@test_status, :pass)
|
160
154
|
testcase3.instance_variable_set(:@test_status, :fail)
|
161
|
-
test_suite_result.add_test_case(
|
162
|
-
test_suite_result.add_test_case(
|
163
|
-
test_suite_result.add_test_case(
|
164
|
-
expect(
|
155
|
+
test_suite_result.add_test_case(testcase1)
|
156
|
+
test_suite_result.add_test_case(testcase2)
|
157
|
+
test_suite_result.add_test_case(testcase3)
|
158
|
+
expect(test_suite_result.errored_tests).to be == 1
|
165
159
|
end
|
166
160
|
|
167
161
|
it 'calculates skipped tests' do
|
168
162
|
testcase1.instance_variable_set(:@test_status, :error)
|
169
163
|
testcase2.instance_variable_set(:@test_status, :skip)
|
170
164
|
testcase3.instance_variable_set(:@test_status, :fail)
|
171
|
-
test_suite_result.add_test_case(
|
172
|
-
test_suite_result.add_test_case(
|
173
|
-
test_suite_result.add_test_case(
|
174
|
-
expect(
|
165
|
+
test_suite_result.add_test_case(testcase1)
|
166
|
+
test_suite_result.add_test_case(testcase2)
|
167
|
+
test_suite_result.add_test_case(testcase3)
|
168
|
+
expect(test_suite_result.skipped_tests).to be == 1
|
175
169
|
end
|
176
170
|
|
177
171
|
it 'calculates pending tests' do
|
178
172
|
testcase1.instance_variable_set(:@test_status, :error)
|
179
173
|
testcase2.instance_variable_set(:@test_status, :pending)
|
180
174
|
testcase3.instance_variable_set(:@test_status, :fail)
|
181
|
-
test_suite_result.add_test_case(
|
182
|
-
test_suite_result.add_test_case(
|
183
|
-
test_suite_result.add_test_case(
|
184
|
-
expect(
|
175
|
+
test_suite_result.add_test_case(testcase1)
|
176
|
+
test_suite_result.add_test_case(testcase2)
|
177
|
+
test_suite_result.add_test_case(testcase3)
|
178
|
+
expect(test_suite_result.pending_tests).to be == 1
|
185
179
|
end
|
186
180
|
|
187
181
|
it 'calculates sum_failed as a sum of errored and failed TestCases' do
|
188
182
|
testcase1.instance_variable_set(:@test_status, :error)
|
189
183
|
testcase2.instance_variable_set(:@test_status, :pending)
|
190
184
|
testcase3.instance_variable_set(:@test_status, :fail)
|
191
|
-
test_suite_result.add_test_case(
|
192
|
-
test_suite_result.add_test_case(
|
193
|
-
test_suite_result.add_test_case(
|
194
|
-
expect(
|
185
|
+
test_suite_result.add_test_case(testcase1)
|
186
|
+
test_suite_result.add_test_case(testcase2)
|
187
|
+
test_suite_result.add_test_case(testcase3)
|
188
|
+
expect(test_suite_result.sum_failed).to be == 2
|
195
189
|
end
|
196
190
|
|
197
191
|
it 'reports success with no errors/failures' do
|
198
192
|
testcase1.instance_variable_set(:@test_status, :pass)
|
199
193
|
testcase2.instance_variable_set(:@test_status, :pending)
|
200
194
|
testcase3.instance_variable_set(:@test_status, :fail)
|
201
|
-
test_suite_result.add_test_case(
|
202
|
-
test_suite_result.add_test_case(
|
203
|
-
test_suite_result.add_test_case(
|
204
|
-
expect(
|
195
|
+
test_suite_result.add_test_case(testcase1)
|
196
|
+
test_suite_result.add_test_case(testcase2)
|
197
|
+
test_suite_result.add_test_case(testcase3)
|
198
|
+
expect(test_suite_result.success?).to be == false
|
205
199
|
end
|
206
200
|
|
207
201
|
it 'reports failed if any tests error/fail' do
|
208
202
|
testcase1.instance_variable_set(:@test_status, :pass)
|
209
203
|
testcase2.instance_variable_set(:@test_status, :pending)
|
210
204
|
testcase3.instance_variable_set(:@test_status, :fail)
|
211
|
-
test_suite_result.add_test_case(
|
212
|
-
test_suite_result.add_test_case(
|
213
|
-
test_suite_result.add_test_case(
|
214
|
-
expect(
|
205
|
+
test_suite_result.add_test_case(testcase1)
|
206
|
+
test_suite_result.add_test_case(testcase2)
|
207
|
+
test_suite_result.add_test_case(testcase3)
|
208
|
+
expect(test_suite_result.failed?).to be == true
|
215
209
|
end
|
216
210
|
|
217
211
|
it 'can calculate the sum of all TestCase runtimes' do
|
218
212
|
testcase1.instance_variable_set(:@runtime, 1)
|
219
213
|
testcase2.instance_variable_set(:@runtime, 10)
|
220
214
|
testcase3.instance_variable_set(:@runtime, 100)
|
221
|
-
test_suite_result.add_test_case(
|
222
|
-
test_suite_result.add_test_case(
|
223
|
-
test_suite_result.add_test_case(
|
224
|
-
expect(
|
215
|
+
test_suite_result.add_test_case(testcase1)
|
216
|
+
test_suite_result.add_test_case(testcase2)
|
217
|
+
test_suite_result.add_test_case(testcase3)
|
218
|
+
expect(test_suite_result.elapsed_time).to be == 111
|
225
219
|
end
|
226
220
|
|
227
221
|
describe '#print_test_result' do
|
228
222
|
it 'prints the test result without the line number if no file path' do
|
229
|
-
tc = Beaker::TestCase.new(
|
223
|
+
tc = Beaker::TestCase.new(hosts, options[:logger], options)
|
230
224
|
ex = StandardError.new('failed')
|
231
225
|
allow(ex).to receive(:backtrace).and_return(['path_to_test_file.rb line 1 - blah'])
|
232
226
|
tc.instance_variable_set(:@exception, ex)
|
233
|
-
test_suite_result.add_test_case(
|
227
|
+
test_suite_result.add_test_case(tc)
|
234
228
|
expect(test_suite_result.print_test_result(tc)).not_to match(/Test line:/)
|
235
|
-
expect{ test_suite_result.print_test_result(tc) }.not_to raise_error
|
229
|
+
expect { test_suite_result.print_test_result(tc) }.not_to raise_error
|
236
230
|
end
|
237
231
|
|
238
232
|
it 'prints the test result and line number from test case file on failure' do
|
239
|
-
tc = Beaker::TestCase.new(
|
233
|
+
tc = Beaker::TestCase.new(hosts, options[:logger], options, 'path_to_test_file.rb')
|
240
234
|
ex = StandardError.new('failed')
|
241
235
|
allow(ex).to receive(:backtrace).and_return(['path_to_test_file.rb line 1 - blah'])
|
242
236
|
tc.instance_variable_set(:@exception, ex)
|
243
|
-
test_suite_result.add_test_case(
|
237
|
+
test_suite_result.add_test_case(tc)
|
244
238
|
expect(test_suite_result.print_test_result(tc)).to match(/Test line:/)
|
245
|
-
expect{ test_suite_result.print_test_result(tc) }.not_to raise_error
|
239
|
+
expect { test_suite_result.print_test_result(tc) }.not_to raise_error
|
246
240
|
end
|
247
241
|
end
|
248
242
|
|
249
243
|
describe '#write_junit_xml' do
|
250
|
-
let(:options)
|
251
|
-
|
252
|
-
|
253
|
-
|
244
|
+
let(:options) do
|
245
|
+
make_opts.merge({ :logger => double.as_null_object,
|
246
|
+
'name' => create_files(@files),
|
247
|
+
:log_dated_dir => '.',
|
248
|
+
:xml_dated_dir => '.', })
|
249
|
+
end
|
254
250
|
let(:rb_test) { 'my_ruby_file.rb' }
|
255
251
|
|
256
252
|
before do
|
257
|
-
@files = [
|
258
|
-
@ts = Beaker::TestSuite.new(
|
259
|
-
@tsr = @ts.instance_variable_get(
|
260
|
-
allow(
|
261
|
-
allow(
|
253
|
+
@files = [rb_test, rb_test, rb_test]
|
254
|
+
@ts = Beaker::TestSuite.new('name', hosts, options, Time.now, :fast)
|
255
|
+
@tsr = @ts.instance_variable_get(:@test_suite_results)
|
256
|
+
allow(@tsr).to receive(:start_time).and_return(0)
|
257
|
+
allow(@tsr).to receive(:stop_time).and_return(10)
|
262
258
|
@test_cases = []
|
263
259
|
@files.each_with_index do |_file, _index|
|
264
|
-
tc = Beaker::TestCase.new(
|
265
|
-
allow(
|
260
|
+
tc = Beaker::TestCase.new(hosts, options[:logger], options, rb_test)
|
261
|
+
allow(tc).to receive(:sublog).and_return(false)
|
266
262
|
@test_cases << tc
|
267
263
|
end
|
268
264
|
@rexml_mock = REXML::Element.new("testsuites")
|
269
|
-
allow(REXML::Element).to receive(
|
270
|
-
allow(
|
265
|
+
allow(REXML::Element).to receive(:add_element).and_call_original
|
266
|
+
allow(LoggerJunit).to receive(:write_xml).and_yield(Object.new, @rexml_mock)
|
271
267
|
end
|
272
268
|
|
273
269
|
it 'doesn\'t re-order test cases themselves on time_sort' do
|
274
|
-
expect(
|
270
|
+
expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
|
275
271
|
|
276
|
-
@test_cases.each_with_index do |tc,index|
|
272
|
+
@test_cases.each_with_index do |tc, index|
|
277
273
|
tc.instance_variable_set(:@runtime, 3**index)
|
278
|
-
@tsr.add_test_case(
|
274
|
+
@tsr.add_test_case(tc)
|
279
275
|
end
|
280
276
|
|
281
|
-
original_testcase_order = test_suite_result.instance_variable_get(
|
277
|
+
original_testcase_order = test_suite_result.instance_variable_get(:@test_cases).dup
|
282
278
|
time_sort = true
|
283
|
-
@tsr.write_junit_xml(
|
284
|
-
after_testcase_order = test_suite_result.instance_variable_get(
|
285
|
-
expect(
|
279
|
+
@tsr.write_junit_xml('fakeFilePath07', 'fakeFileToLink09', time_sort)
|
280
|
+
after_testcase_order = test_suite_result.instance_variable_get(:@test_cases).dup
|
281
|
+
expect(after_testcase_order).to be === original_testcase_order
|
286
282
|
end
|
287
283
|
|
288
284
|
it 'writes @export nested hashes properly' do
|
289
|
-
expect(
|
290
|
-
inner_value = {'second' => '2nd'}
|
285
|
+
expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
|
286
|
+
inner_value = { 'second' => '2nd' }
|
291
287
|
@test_cases.each do |tc|
|
292
288
|
tc.instance_variable_set(:@runtime, 0)
|
293
|
-
tc.instance_variable_set(:@exports, [{'oh hey' => 'hai', 'first' => inner_value}])
|
294
|
-
@tsr.add_test_case(
|
289
|
+
tc.instance_variable_set(:@exports, [{ 'oh hey' => 'hai', 'first' => inner_value }])
|
290
|
+
@tsr.add_test_case(tc)
|
295
291
|
end
|
296
|
-
@tsr.write_junit_xml(
|
292
|
+
@tsr.write_junit_xml('fakeFilePath08')
|
297
293
|
@rexml_mock.elements.each("//testcase") do |e|
|
298
294
|
expect(e.attributes["oh_hey"].to_s).to eq('hai')
|
299
295
|
expect(e.attributes["first"]).to eq(inner_value.to_s)
|
@@ -301,13 +297,13 @@ module Beaker
|
|
301
297
|
end
|
302
298
|
|
303
299
|
it 'writes @export array of hashes properly' do
|
304
|
-
expect(
|
300
|
+
expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
|
305
301
|
@test_cases.each do |tc|
|
306
302
|
tc.instance_variable_set(:@runtime, 0)
|
307
|
-
tc.instance_variable_set(:@exports, [{:yes => 'hello'}, {:uh => 'sher'}])
|
308
|
-
@tsr.add_test_case(
|
303
|
+
tc.instance_variable_set(:@exports, [{ :yes => 'hello' }, { :uh => 'sher' }])
|
304
|
+
@tsr.add_test_case(tc)
|
309
305
|
end
|
310
|
-
@tsr.write_junit_xml(
|
306
|
+
@tsr.write_junit_xml('fakeFilePath08')
|
311
307
|
@rexml_mock.elements.each("//testcase") do |e|
|
312
308
|
expect(e.attributes["yes"].to_s).to eq('hello')
|
313
309
|
expect(e.attributes["uh"].to_s).to eq('sher')
|
@@ -315,13 +311,13 @@ module Beaker
|
|
315
311
|
end
|
316
312
|
|
317
313
|
it 'writes @export hashes per test case properly' do
|
318
|
-
expect(
|
319
|
-
@test_cases.each_with_index do |tc,index|
|
314
|
+
expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
|
315
|
+
@test_cases.each_with_index do |tc, index|
|
320
316
|
tc.instance_variable_set(:@runtime, 0)
|
321
|
-
tc.instance_variable_set(:@exports, [{"yes_#{index}" => "hello#{index}"}])
|
322
|
-
@tsr.add_test_case(
|
317
|
+
tc.instance_variable_set(:@exports, [{ "yes_#{index}" => "hello#{index}" }])
|
318
|
+
@tsr.add_test_case(tc)
|
323
319
|
end
|
324
|
-
@tsr.write_junit_xml(
|
320
|
+
@tsr.write_junit_xml('fakeFilePath08')
|
325
321
|
index = 0
|
326
322
|
@rexml_mock.elements.each("//testcase") do |e|
|
327
323
|
expect(e.attributes["yes_#{index}"]).to eq("hello#{index}")
|
@@ -329,15 +325,14 @@ module Beaker
|
|
329
325
|
end
|
330
326
|
end
|
331
327
|
end
|
332
|
-
|
333
328
|
end
|
334
329
|
|
335
330
|
describe '#log_path' do
|
336
|
-
let(
|
337
|
-
let(
|
338
|
-
let(
|
339
|
-
let(
|
340
|
-
let(
|
331
|
+
let(:sh_test) { '/my_shell_file.sh' }
|
332
|
+
let(:files) { @files ? @files : [sh_test] }
|
333
|
+
let(:options) { make_opts.merge({ :logger => double.as_null_object, 'name' => create_files(files) }) }
|
334
|
+
let(:hosts) { make_hosts }
|
335
|
+
let(:testsuite) { described_class.new('name', hosts, options, Time.now, :stop) }
|
341
336
|
|
342
337
|
it 'returns the simple joining of the log dir & file as required' do
|
343
338
|
expect(testsuite.log_path('foo.txt', 'man/date')).to be === 'man/date/foo.txt'
|
@@ -347,15 +342,15 @@ module Beaker
|
|
347
342
|
# the base directory is where the latest symlink itself should live
|
348
343
|
|
349
344
|
it 'in the usual case' do
|
350
|
-
expect(
|
345
|
+
expect(File).not_to be_symlink('man/latest')
|
351
346
|
testsuite.log_path('foo.txt', 'man/date')
|
352
|
-
expect(
|
347
|
+
expect(File).to be_symlink('man/latest')
|
353
348
|
end
|
354
349
|
|
355
350
|
it 'if given a nested directory' do
|
356
|
-
expect(
|
351
|
+
expect(File).not_to be_symlink('a/latest')
|
357
352
|
testsuite.log_path('foo.txt', 'a/b/c/d/e/f')
|
358
|
-
expect(
|
353
|
+
expect(File).to be_symlink('a/latest')
|
359
354
|
end
|
360
355
|
end
|
361
356
|
|
@@ -363,19 +358,17 @@ module Beaker
|
|
363
358
|
# the symlink directory is where the symlink points to
|
364
359
|
|
365
360
|
it 'in the usual case' do
|
366
|
-
expect(
|
361
|
+
expect(File).not_to be_symlink('d/latest')
|
367
362
|
testsuite.log_path('foo.txt', 'd/e')
|
368
|
-
expect(
|
363
|
+
expect(File.readlink('d/latest')).to be === 'e'
|
369
364
|
end
|
370
365
|
|
371
366
|
it 'if given a nested directory' do
|
372
|
-
expect(
|
367
|
+
expect(File).not_to be_symlink('f/latest')
|
373
368
|
testsuite.log_path('foo.txt', 'f/g/h/i/j/k')
|
374
|
-
expect(
|
369
|
+
expect(File.readlink('f/latest')).to be === 'g/h/i/j/k'
|
375
370
|
end
|
376
371
|
end
|
377
|
-
|
378
372
|
end
|
379
|
-
|
380
373
|
end
|
381
374
|
end
|