diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/support/shared_examples/lib | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/support/shared_examples/lib')
4 files changed, 253 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb b/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb new file mode 100644 index 00000000000..bdb0316bf5a --- /dev/null +++ b/spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'API::CI::Runner application context metadata' do |api_route| + it 'contains correct context metadata' do + # Avoids popping the context from the thread so we can + # check its content after the request. + allow(Labkit::Context).to receive(:pop) + + send_request + + Labkit::Context.with_context do |context| + expected_context = { + 'meta.caller_id' => api_route, + 'meta.user' => job.user.username, + 'meta.project' => job.project.full_path, + 'meta.root_namespace' => job.project.full_path_components.first + } + + expect(context.to_h).to include(expected_context) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb index af65b61021c..8cf6babe146 100644 --- a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb @@ -82,3 +82,25 @@ RSpec.shared_examples 'schedules resource mentions migration' do |resource_class end end end + +RSpec.shared_examples 'resource migration not run' do |migration_class, resource_class| + it 'does not migrate mentions' do + join = migration_class::JOIN + conditions = migration_class::QUERY_CONDITIONS + + expect do + subject.perform(resource_class.name, join, conditions, false, resource_class.minimum(:id), resource_class.maximum(:id)) + end.to change { user_mentions.count }.by(0) + end +end + +RSpec.shared_examples 'resource notes migration not run' do |migration_class, resource_class| + it 'does not migrate mentions' do + join = migration_class::JOIN + conditions = migration_class::QUERY_CONDITIONS + + expect do + subject.perform(resource_class.name, join, conditions, true, Note.minimum(:id), Note.maximum(:id)) + end.to change { user_mentions.count }.by(0) + end +end diff --git a/spec/support/shared_examples/lib/gitlab/kubernetes/network_policy_common_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/kubernetes/network_policy_common_shared_examples.rb new file mode 100644 index 00000000000..a3800f050bb --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/kubernetes/network_policy_common_shared_examples.rb @@ -0,0 +1,160 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'network policy common specs' do + let(:name) { 'example-name' } + let(:namespace) { 'example-namespace' } + let(:labels) { nil } + + describe 'as_json' do + let(:json_policy) do + { + name: name, + namespace: namespace, + creation_timestamp: nil, + manifest: YAML.dump( + { + metadata: metadata, + spec: spec + }.deep_stringify_keys + ), + is_autodevops: false, + is_enabled: true + } + end + + subject { policy.as_json } + + it { is_expected.to eq(json_policy) } + end + + describe 'autodevops?' do + subject { policy.autodevops? } + + let(:labels) { { chart: chart } } + let(:chart) { nil } + + it { is_expected.to be false } + + context 'with non-autodevops chart' do + let(:chart) { 'foo' } + + it { is_expected.to be false } + end + + context 'with autodevops chart' do + let(:chart) { 'auto-deploy-app-0.6.0' } + + it { is_expected.to be true } + end + end + + describe 'enabled?' do + subject { policy.enabled? } + + let(:selector) { nil } + + it { is_expected.to be true } + + context 'with empty selector' do + let(:selector) { {} } + + it { is_expected.to be true } + end + + context 'with nil matchLabels in selector' do + let(:selector) { { matchLabels: nil } } + + it { is_expected.to be true } + end + + context 'with empty matchLabels in selector' do + let(:selector) { { matchLabels: {} } } + + it { is_expected.to be true } + end + + context 'with disabled_by label in matchLabels in selector' do + let(:selector) do + { matchLabels: { Gitlab::Kubernetes::NetworkPolicyCommon::DISABLED_BY_LABEL => 'gitlab' } } + end + + it { is_expected.to be false } + end + end + + describe 'enable' do + subject { policy.enabled? } + + let(:selector) { nil } + + before do + policy.enable + end + + it { is_expected.to be true } + + context 'with empty selector' do + let(:selector) { {} } + + it { is_expected.to be true } + end + + context 'with nil matchLabels in selector' do + let(:selector) { { matchLabels: nil } } + + it { is_expected.to be true } + end + + context 'with empty matchLabels in selector' do + let(:selector) { { matchLabels: {} } } + + it { is_expected.to be true } + end + + context 'with disabled_by label in matchLabels in selector' do + let(:selector) do + { matchLabels: { Gitlab::Kubernetes::NetworkPolicyCommon::DISABLED_BY_LABEL => 'gitlab' } } + end + + it { is_expected.to be true } + end + end + + describe 'disable' do + subject { policy.enabled? } + + let(:selector) { nil } + + before do + policy.disable + end + + it { is_expected.to be false } + + context 'with empty selector' do + let(:selector) { {} } + + it { is_expected.to be false } + end + + context 'with nil matchLabels in selector' do + let(:selector) { { matchLabels: nil } } + + it { is_expected.to be false } + end + + context 'with empty matchLabels in selector' do + let(:selector) { { matchLabels: {} } } + + it { is_expected.to be false } + end + + context 'with disabled_by label in matchLabels in selector' do + let(:selector) do + { matchLabels: { Gitlab::Kubernetes::NetworkPolicyCommon::DISABLED_BY_LABEL => 'gitlab' } } + end + + it { is_expected.to be false } + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb new file mode 100644 index 00000000000..6b6e25ca1dd --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.shared_examples 'file template shared examples' do |filename, file_extension| + describe '.all' do + it "strips the #{file_extension} suffix" do + expect(subject.all.first.name).not_to end_with(file_extension) + end + + it 'ensures that the template name is used exactly once' do + all = subject.all.group_by(&:name) + duplicates = all.select { |_, templates| templates.length > 1 } + + expect(duplicates).to be_empty + end + end + + describe '.by_category' do + it 'returns sorted results' do + result = described_class.by_category('General') + + expect(result).to eq(result.sort) + end + end + + describe '.find' do + it 'returns nil if the file does not exist' do + expect(subject.find('nonexistent-file')).to be nil + end + + it 'returns the corresponding object of a valid file' do + template = subject.find(filename) + + expect(template).to be_a described_class + expect(template.name).to eq(filename) + end + end + + describe '#<=>' do + it 'sorts lexicographically' do + one = described_class.new("a.#{file_extension}") + other = described_class.new("z.#{file_extension}") + + expect(one.<=>(other)).to be(-1) + expect([other, one].sort).to eq([one, other]) + end + end +end |