summaryrefslogtreecommitdiff
path: root/qa/spec/specs/helpers/context_selector_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec/specs/helpers/context_selector_spec.rb')
-rw-r--r--qa/spec/specs/helpers/context_selector_spec.rb251
1 files changed, 214 insertions, 37 deletions
diff --git a/qa/spec/specs/helpers/context_selector_spec.rb b/qa/spec/specs/helpers/context_selector_spec.rb
index 7792d33dcf9..f0250103008 100644
--- a/qa/spec/specs/helpers/context_selector_spec.rb
+++ b/qa/spec/specs/helpers/context_selector_spec.rb
@@ -49,8 +49,10 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
it 'matches multiple subdomains' do
QA::Runtime::Scenario.define(:gitlab_address, "https://staging.gitlab.com")
- expect(described_class.context_matches?(subdomain: [:release, :staging])).to be_truthy
- expect(described_class.context_matches?(:production, subdomain: [:release, :staging])).to be_truthy
+ aggregate_failures do
+ expect(described_class.context_matches?(subdomain: [:release, :staging])).to be_truthy
+ expect(described_class.context_matches?(:production, subdomain: [:release, :staging])).to be_truthy
+ end
end
it 'matches :production' do
@@ -87,6 +89,16 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
expect(group.examples[0].execution_result.status).to eq(:passed)
end
+
+ context 'when excluding contexts' do
+ it 'can apply to contexts or descriptions' do
+ group = describe_successfully 'skips staging', except: { subdomain: :staging } do
+ it('skips staging') {}
+ end
+
+ expect(group.examples[0].execution_result.status).to eq(:pending)
+ end
+ end
end
context 'with different environment set' do
@@ -102,6 +114,16 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
expect(group.examples[0].execution_result.status).to eq(:pending)
end
+
+ context 'when excluding contexts' do
+ it 'runs against production' do
+ group = describe_successfully 'Runs in staging', :something, except: { subdomain: :staging } do
+ it('runs in staging') {}
+ end
+
+ expect(group.examples[0].execution_result.status).to eq(:passed)
+ end
+ end
end
end
@@ -113,10 +135,28 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
it('runs in any env') {}
end
- expect(group.examples[0].execution_result.status).to eq(:passed)
- expect(group.examples[1].execution_result.status).to eq(:pending)
- expect(group.examples[2].execution_result.status).to eq(:passed)
- expect(group.examples[3].execution_result.status).to eq(:passed)
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:passed)
+ expect(group.examples[1].execution_result.status).to eq(:pending)
+ expect(group.examples[2].execution_result.status).to eq(:passed)
+ expect(group.examples[3].execution_result.status).to eq(:passed)
+ end
+ end
+
+ context 'when excluding contexts' do
+ it 'skips staging' do
+ group = describe_successfully do
+ it('skips staging', except: { subdomain: :staging }) {}
+ it('runs in staging', except: :production) {}
+ it('skips staging also', except: { subdomain: %i[release staging] }) {}
+ end
+
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:pending)
+ expect(group.examples[1].execution_result.status).to eq(:passed)
+ expect(group.examples[2].execution_result.status).to eq(:pending)
+ end
+ end
end
context 'custom env' do
@@ -130,8 +170,24 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
it('does not run on release', only: :production) {}
end
- expect(group.examples.first.execution_result.status).to eq(:passed)
- expect(group.examples.last.execution_result.status).to eq(:pending)
+ aggregate_failures do
+ expect(group.examples.first.execution_result.status).to eq(:passed)
+ expect(group.examples.last.execution_result.status).to eq(:pending)
+ end
+ end
+
+ context 'when excluding contexts' do
+ it 'skips a custom environment' do
+ group = describe_successfully do
+ it('skips release gitlab net', except: { tld: '.net', subdomain: :release, domain: 'gitlab' }) {}
+ it('runs on release', except: :production) {}
+ end
+
+ aggregate_failures do
+ expect(group.examples.first.execution_result.status).to eq(:pending)
+ expect(group.examples.last.execution_result.status).to eq(:passed)
+ end
+ end
end
end
@@ -147,9 +203,27 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
it('runs in prod and staging', only: { subdomain: /(staging.)?/, domain: 'gitlab' }) {}
end
- expect(group.examples[0].execution_result.status).to eq(:passed)
- expect(group.examples[1].execution_result.status).to eq(:pending)
- expect(group.examples[2].execution_result.status).to eq(:passed)
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:passed)
+ expect(group.examples[1].execution_result.status).to eq(:pending)
+ expect(group.examples[2].execution_result.status).to eq(:passed)
+ end
+ end
+
+ context 'when excluding contexts' do
+ it 'skips production' do
+ group = describe_successfully do
+ it('skips prod', except: :production) {}
+ it('runs on prod', except: { subdomain: :staging }) {}
+ it('skips prod and staging', except: { subdomain: /(staging.)?/, domain: 'gitlab' }) {}
+ end
+
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:pending)
+ expect(group.examples[1].execution_result.status).to eq(:passed)
+ expect(group.examples[2].execution_result.status).to eq(:pending)
+ end
+ end
end
end
@@ -179,6 +253,21 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
expect(group.examples[1].execution_result.status).to eq(:passed)
end
end
+
+ context 'when excluding contexts' do
+ it 'runs in any pipeline' do
+ group = describe_successfully do
+ it('runs given a single named pipeline', except: { pipeline: :nightly }) {}
+ it('runs given an array of pipelines', except: { pipeline: [:canary, :not_nightly] }) {}
+ end
+
+ aggregate_failures do
+ group.examples.each do |example|
+ expect(example.execution_result.status).to eq(:passed)
+ end
+ end
+ end
+ end
end
context 'when a pipeline triggered from the default branch runs in gitlab-qa' do
@@ -200,6 +289,22 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
expect(group.examples[2].execution_result.status).to eq(:pending)
end
end
+
+ context 'when excluding contexts' do
+ it 'skips default branch pipelines' do
+ group = describe_successfully do
+ it('skips main pipeline given a single pipeline', except: { pipeline: :main }) {}
+ it('skips main given an array of pipelines', except: { pipeline: [:canary, :main] }) {}
+ it('runs non-default pipelines', except: { pipeline: [:nightly, :not_nightly, :not_main] }) {}
+ end
+
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:pending)
+ expect(group.examples[1].execution_result.status).to eq(:pending)
+ expect(group.examples[2].execution_result.status).to eq(:passed)
+ end
+ end
+ end
end
context 'with CI_PROJECT_NAME set' do
@@ -223,24 +328,42 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
expect(group.examples[3].execution_result.status).to eq(:pending)
end
end
+
+ context 'when excluding contexts' do
+ it 'skips designated pipeline' do
+ group = describe_successfully do
+ it('skips nightly', except: { pipeline: :nightly }) {}
+ it('runs in not_nightly', except: { pipeline: :not_nightly }) {}
+ it('skips on nightly given an array', except: { pipeline: [:canary, :nightly] }) {}
+ it('runs in not_nightly given an array', except: { pipeline: [:not_nightly, :canary] }) {}
+ end
+
+ aggregate_failures do
+ expect(group.examples[0].execution_result.status).to eq(:pending)
+ expect(group.examples[1].execution_result.status).to eq(:passed)
+ expect(group.examples[2].execution_result.status).to eq(:pending)
+ expect(group.examples[3].execution_result.status).to eq(:passed)
+ end
+ end
+ end
end
end
- context 'when excluding contexts' do
- context 'with job constraints' do
- context 'without CI_JOB_NAME set' do
- before do
- stub_env('CI_JOB_NAME', nil)
- described_class.configure_rspec
- end
+ context 'with job constraints' do
+ context 'without CI_JOB_NAME set' do
+ before do
+ stub_env('CI_JOB_NAME', nil)
+ described_class.configure_rspec
+ end
+ context 'when excluding contexts' do
it 'runs in any job' do
group = describe_successfully do
- it('runs given a single named job', exclude: { job: 'ee:instance-image' }) {}
- it('runs given a single regex pattern', exclude: { job: '.*:instance-image' }) {}
- it('runs given an array of jobs', exclude: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
- it('runs given an array of regex patterns', exclude: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
- it('runs given a mix of strings and regex patterns', exclude: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
+ it('runs given a single named job', except: { job: 'ee:instance-image' }) {}
+ it('runs given a single regex pattern', except: { job: '.*:instance-image' }) {}
+ it('runs given an array of jobs', except: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('runs given an array of regex patterns', except: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
+ it('runs given a mix of strings and regex patterns', except: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
end
aggregate_failures do
@@ -251,19 +374,39 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
end
end
- context 'with CI_JOB_NAME set' do
- before do
- stub_env('CI_JOB_NAME', 'ee:instance-image')
- described_class.configure_rspec
+ context 'when including only specific contexts' do
+ it 'runs in any job' do
+ group = describe_successfully do
+ it('runs given a single named job', only: { job: 'ee:instance-image' }) {}
+ it('runs given a single regex pattern', only: { job: '.*:instance-image' }) {}
+ it('runs given an array of jobs', only: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('runs given an array of regex patterns', only: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
+ it('runs given a mix of strings and regex patterns', only: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
+ end
+
+ aggregate_failures do
+ group.examples.each do |example|
+ expect(example.execution_result.status).to eq(:passed)
+ end
+ end
end
+ end
+ end
+
+ context 'with CI_JOB_NAME set' do
+ before do
+ stub_env('CI_JOB_NAME', 'ee:instance-image')
+ described_class.configure_rspec
+ end
+ context 'when excluding contexts' do
it 'does not run in the specified job' do
group = describe_successfully do
- it('skips given a single named job', exclude: { job: 'ee:instance-image' }) {}
- it('skips given a single regex pattern', exclude: { job: '.*:instance-image' }) {}
- it('skips given an array of jobs', exclude: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
- it('skips given an array of regex patterns', exclude: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
- it('skips given a mix of strings and regex patterns', exclude: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
+ it('skips given a single named job', except: { job: 'ee:instance-image' }) {}
+ it('skips given a single regex pattern', except: { job: '.*:instance-image' }) {}
+ it('skips given an array of jobs', except: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('skips given an array of regex patterns', except: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
+ it('skips given a mix of strings and regex patterns', except: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
end
aggregate_failures do
@@ -275,11 +418,11 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
it 'runs in jobs that do not match' do
group = describe_successfully do
- it('runs given a single named job', exclude: { job: 'ce:instance-image' }) {}
- it('runs given a single regex pattern', exclude: { job: '.*:instance-image-quarantine' }) {}
- it('runs given an array of jobs', exclude: { job: %w[ce:instance-image qa-schedules-browser_ui-3_create] }) {}
- it('runs given an array of regex patterns', exclude: { job: %w[ce:.* qa-schedules-browser_ui.*] }) {}
- it('runs given a mix of strings and regex patterns', exclude: { job: %w[ce:instance-image qa-schedules-browser_ui.*] }) {}
+ it('runs given a single named job', except: { job: 'ce:instance-image' }) {}
+ it('runs given a single regex pattern', except: { job: '.*:instance-image-quarantine' }) {}
+ it('runs given an array of jobs', except: { job: %w[ce:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('runs given an array of regex patterns', except: { job: %w[ce:.* qa-schedules-browser_ui.*] }) {}
+ it('runs given a mix of strings and regex patterns', except: { job: %w[ce:instance-image qa-schedules-browser_ui.*] }) {}
end
aggregate_failures do
@@ -289,6 +432,40 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
end
end
end
+
+ context 'when including only specific contexts' do
+ it 'runs only in the specified jobs' do
+ group = describe_successfully do
+ it('runs given a single named job', only: { job: 'ee:instance-image' }) {}
+ it('runs given a single regex pattern', only: { job: '.*:instance-image' }) {}
+ it('runs given an array of jobs', only: { job: %w[ee:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('runs given an array of regex patterns', only: { job: %w[ee:.* qa-schedules-browser_ui.*] }) {}
+ it('runs given a mix of strings and regex patterns', only: { job: %w[ee:instance-image qa-schedules-browser_ui.*] }) {}
+ end
+
+ aggregate_failures do
+ group.examples.each do |example|
+ expect(example.execution_result.status).to eq(:passed)
+ end
+ end
+ end
+
+ it 'does not run in jobs that do not match' do
+ group = describe_successfully do
+ it('skips given a single named job', only: { job: 'ce:instance-image' }) {}
+ it('skips given a single regex pattern', only: { job: '.*:instance-image-quarantine' }) {}
+ it('skips given an array of jobs', only: { job: %w[ce:instance-image qa-schedules-browser_ui-3_create] }) {}
+ it('skips given an array of regex patterns', only: { job: %w[ce:.* qa-schedules-browser_ui.*] }) {}
+ it('skips given a mix of strings and regex patterns', only: { job: %w[ce:instance-image qa-schedules-browser_ui.*] }) {}
+ end
+
+ aggregate_failures do
+ group.examples.each do |example|
+ expect(example.execution_result.status).to eq(:pending)
+ end
+ end
+ end
+ end
end
end
end