2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
RSpec.describe QA::Specs::Runner do
|
2022-07-23 23:45:48 +05:30
|
|
|
shared_examples 'excludes default skipped, and geo' do
|
|
|
|
it 'excludes the default skipped and geo tags, and includes default args' do
|
|
|
|
expect_rspec_runner_arguments(DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', *described_class::DEFAULT_TEST_PATH_ARGS])
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
before do
|
|
|
|
stub_const('DEFAULT_SKIPPED_TAGS', %w[--tag ~orchestrated --tag ~transient --tag ~sanity_feature_flags].freeze)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#perform' do
|
2018-11-20 20:47:30 +05:30
|
|
|
before do
|
|
|
|
allow(QA::Runtime::Browser).to receive(:configure!)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
QA::Runtime::Scenario.define(:gitlab_address, "http://gitlab.test")
|
2022-04-04 11:22:00 +05:30
|
|
|
QA::Runtime::Scenario.define(:klass, "QA::Scenario::Test::Instance::All")
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it_behaves_like 'excludes default skipped, and geo'
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
context 'when tty is set' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.tty = true } }
|
|
|
|
|
|
|
|
it 'sets the `--tty` flag' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
|
|
|
['--tty'] + DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', *described_class::DEFAULT_TEST_PATH_ARGS]
|
|
|
|
)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'when count_examples_only is set as an option' do
|
|
|
|
let(:out) { StringIO.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
QA::Runtime::Scenario.define(:count_examples_only, true)
|
|
|
|
out.string = '22 examples,'
|
|
|
|
allow(StringIO).to receive(:new).and_return(out)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the `--dry-run` flag' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
|
|
|
['--dry-run'] + DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', *described_class::DEFAULT_TEST_PATH_ARGS],
|
|
|
|
[$stderr, anything]
|
|
|
|
)
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'writes to file when examples are more than zero' do
|
|
|
|
allow(RSpec::Core::Runner).to receive(:run).and_return(0)
|
|
|
|
|
|
|
|
expect(File).to receive(:open).with('no_of_examples/test_instance_all.txt', 'w') { '22' }
|
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not write to file when zero examples' do
|
|
|
|
out.string = '0 examples,'
|
|
|
|
allow(RSpec::Core::Runner).to receive(:run).and_return(0)
|
|
|
|
|
|
|
|
expect(File).not_to receive(:open)
|
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises error when Rspec output does not match regex' do
|
|
|
|
out.string = '0'
|
|
|
|
allow(RSpec::Core::Runner).to receive(:run).and_return(0)
|
|
|
|
|
|
|
|
expect { subject.perform }
|
|
|
|
.to raise_error(QA::Specs::Runner::RegexMismatchError, 'Rspec output did not match regex')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when --tag is specified as an option' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.options = %w[--tag actioncable] } }
|
|
|
|
|
|
|
|
it 'includes the option value in the file name' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
|
|
|
['--dry-run', '--tag', '~geo', '--tag', 'actioncable', *described_class::DEFAULT_TEST_PATH_ARGS],
|
|
|
|
[$stderr, anything]
|
|
|
|
)
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
expect(File).to receive(:open).with('no_of_examples/test_instance_all_actioncable.txt', 'w') { '22' }
|
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
after do
|
|
|
|
QA::Runtime::Scenario.attributes.delete(:count_examples_only)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
context 'when test_metadata_only is set as an option' do
|
|
|
|
let(:rspec_config) { instance_double('RSpec::Core::Configuration') }
|
|
|
|
let(:output_file) { Pathname.new('/root/tmp/test-metadata.json') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
QA::Runtime::Scenario.define(:test_metadata_only, true)
|
|
|
|
allow(RSpec).to receive(:configure).and_yield(rspec_config)
|
|
|
|
allow(rspec_config).to receive(:add_formatter)
|
|
|
|
allow(rspec_config).to receive(:fail_if_no_examples=)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the `--dry-run` flag' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
2023-01-13 00:05:48 +05:30
|
|
|
['--dry-run', *described_class::DEFAULT_TEST_PATH_ARGS],
|
2022-07-23 23:45:48 +05:30
|
|
|
[$stderr, anything]
|
|
|
|
)
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures json formatted output to file' do
|
|
|
|
allow(QA::Runtime::Path).to receive(:qa_root).and_return('/root')
|
|
|
|
|
|
|
|
expect(rspec_config).to receive(:add_formatter)
|
|
|
|
.with(QA::Support::JsonFormatter, output_file)
|
|
|
|
expect(rspec_config).to receive(:fail_if_no_examples=)
|
|
|
|
.with(true)
|
|
|
|
|
|
|
|
allow(RSpec::Core::Runner).to receive(:run).and_return(0)
|
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
QA::Runtime::Scenario.attributes.delete(:test_metadata_only)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context 'when tags are set' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.tags = %i[orchestrated github] } }
|
|
|
|
|
|
|
|
it 'focuses on the given tags' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
|
|
|
['--tag', 'orchestrated', '--tag', 'github', '--tag', '~geo', *described_class::DEFAULT_TEST_PATH_ARGS]
|
|
|
|
)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when "--tag smoke" is set as options' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.options = %w[--tag smoke] } }
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'focuses on the given tag without excluded tags' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect_rspec_runner_arguments(['--tag', '~geo', '--tag', 'smoke', *described_class::DEFAULT_TEST_PATH_ARGS])
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when "qa/specs/features/foo" is set as options' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.options = %w[qa/specs/features/foo] } }
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'passes the given tests path and excludes the default skipped, and geo tags' do
|
|
|
|
expect_rspec_runner_arguments(DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', 'qa/specs/features/foo'])
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'when "--tag smoke" and "qa/specs/features/foo" are set as options' do
|
|
|
|
subject { described_class.new.tap { |runner| runner.options = %w[--tag smoke qa/specs/features/foo] } }
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'focuses on the given tag and includes the path without excluding the orchestrated or transient tags' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect_rspec_runner_arguments(['--tag', '~geo', '--tag', 'smoke', 'qa/specs/features/foo'])
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
context 'when SIGNUP_DISABLED is true' do
|
|
|
|
before do
|
|
|
|
allow(QA::Runtime::Env).to receive(:signup_disabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it 'includes default args and excludes the skip_signup_disabled tag' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', '--tag', '~skip_signup_disabled', *described_class::DEFAULT_TEST_PATH_ARGS])
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when running against live environment' do
|
|
|
|
before do
|
|
|
|
QA::Runtime::Scenario.define(:gitlab_address, "https://staging.gitlab.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes default args and excludes the skip_live_env tag' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', '--tag', '~skip_live_env', *described_class::DEFAULT_TEST_PATH_ARGS])
|
2021-02-22 17:27:13 +05:30
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when running against a Geo environment' do
|
|
|
|
before do
|
|
|
|
QA::Runtime::Scenario.define(:geo_secondary_address, "https://geo.staging.gitlab.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
QA::Runtime::Scenario.attributes.delete(:geo_secondary_address)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new.tap { |runner| runner.tags = %i[geo] } }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'includes the geo tag' do
|
|
|
|
expect_rspec_runner_arguments(['--tag', 'geo', *described_class::DEFAULT_TEST_PATH_ARGS])
|
2020-05-24 23:13:21 +05:30
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'testable features' do
|
|
|
|
shared_examples 'one supported feature' do |feature|
|
|
|
|
before do
|
|
|
|
QA::Runtime::Env.supported_features.each do |tag, _|
|
|
|
|
allow(QA::Runtime::Env).to receive(:can_test?).with(tag).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
allow(QA::Runtime::Env).to receive(:can_test?).with(feature).and_return(true) unless feature.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes default args and excludes all unsupported tags' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect_rspec_runner_arguments(
|
|
|
|
DEFAULT_SKIPPED_TAGS + ['--tag', '~geo', *excluded_feature_tags_except(feature),
|
|
|
|
*described_class::DEFAULT_TEST_PATH_ARGS]
|
|
|
|
)
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when only git protocol 2 is supported' do
|
|
|
|
it_behaves_like 'one supported feature', :git_protocol_v2
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when only admin features are supported' do
|
|
|
|
it_behaves_like 'one supported feature', :admin
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when no features are supported' do
|
|
|
|
it_behaves_like 'one supported feature', nil
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
context 'when all features are supported' do
|
|
|
|
before do
|
|
|
|
QA::Runtime::Env.supported_features.each do |tag, _|
|
|
|
|
allow(QA::Runtime::Env).to receive(:can_test?).with(tag).and_return(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it_behaves_like 'excludes default skipped, and geo'
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when features are not specified' do
|
2022-07-23 23:45:48 +05:30
|
|
|
it_behaves_like 'excludes default skipped, and geo'
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def excluded_feature_tags_except(tag)
|
2019-10-12 21:52:04 +05:30
|
|
|
QA::Runtime::Env.supported_features.except(tag).flat_map do |tag, _|
|
2019-09-04 21:01:54 +05:30
|
|
|
['--tag', "~requires_#{tag}"]
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
def expect_rspec_runner_arguments(arguments, std_arguments = described_class::DEFAULT_STD_ARGS)
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(RSpec::Core::Runner).to receive(:run)
|
2022-03-02 08:16:31 +05:30
|
|
|
.with(arguments, *std_arguments)
|
|
|
|
.and_return(0)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|