diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-16 21:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-16 21:09:11 +0300 |
commit | 7ff36fc6e9f0f5dffb41bfc79b4f07b2ce93e1c7 (patch) | |
tree | 7339fa1c323a7584a2e2edacb8e32c7d5781511e /spec | |
parent | d7b1354b396d2e579fd6fe3c18a28b6ffe934f09 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
13 files changed, 39 insertions, 758 deletions
diff --git a/spec/frontend/__helpers__/vuex_action_helper.js b/spec/frontend/__helpers__/vuex_action_helper.js index 474fd528df6..ab2637d6024 100644 --- a/spec/frontend/__helpers__/vuex_action_helper.js +++ b/spec/frontend/__helpers__/vuex_action_helper.js @@ -93,8 +93,13 @@ export default ( payload, ); - // eslint-disable-next-line no-restricted-syntax - return (result || new Promise((resolve) => setImmediate(resolve))) + return ( + result || + new Promise((resolve) => { + // eslint-disable-next-line no-restricted-syntax + setImmediate(resolve); + }) + ) .catch((error) => { validateResults(); throw error; diff --git a/spec/frontend/__helpers__/wait_for_promises.js b/spec/frontend/__helpers__/wait_for_promises.js index 2fd1cc6ba0d..753c3c5d92b 100644 --- a/spec/frontend/__helpers__/wait_for_promises.js +++ b/spec/frontend/__helpers__/wait_for_promises.js @@ -1 +1,4 @@ -export default () => new Promise((resolve) => requestAnimationFrame(resolve)); +export default () => + new Promise((resolve) => { + requestAnimationFrame(resolve); + }); diff --git a/spec/frontend/boards/project_select_spec.js b/spec/frontend/boards/project_select_spec.js index 7206fb83212..bd79060c54f 100644 --- a/spec/frontend/boards/project_select_spec.js +++ b/spec/frontend/boards/project_select_spec.js @@ -8,6 +8,7 @@ import { import { mount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; +import waitForPromises from 'helpers/wait_for_promises'; import ProjectSelect from '~/boards/components/project_select.vue'; import defaultState from '~/boards/stores/state'; @@ -29,8 +30,6 @@ describe('ProjectSelect component', () => { const findInMenuLoadingIcon = () => wrapper.find("[data-testid='dropdown-text-loading-icon']"); const findEmptySearchMessage = () => wrapper.find("[data-testid='empty-result-message']"); - const waitRAF = () => new Promise((resolve) => requestAnimationFrame(resolve)); - const createStore = ({ state, activeGroupProjects }) => { Vue.use(Vuex); @@ -134,7 +133,7 @@ describe('ProjectSelect component', () => { const dropdownToggle = findGlDropdown().find('.dropdown-toggle'); await dropdownToggle.trigger('click'); - await waitRAF(); + await waitForPromises(); await nextTick(); const searchInput = findGlDropdown().findComponent(GlFormInput).element; diff --git a/spec/frontend/ide/components/new_dropdown/upload_spec.js b/spec/frontend/ide/components/new_dropdown/upload_spec.js index 5a7419d6dce..3eafe9e7ccb 100644 --- a/spec/frontend/ide/components/new_dropdown/upload_spec.js +++ b/spec/frontend/ide/components/new_dropdown/upload_spec.js @@ -70,7 +70,9 @@ describe('new dropdown upload', () => { }); it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', async () => { - const waitForCreate = new Promise((resolve) => vm.$on('create', resolve)); + const waitForCreate = new Promise((resolve) => { + vm.$on('create', resolve); + }); vm.createFile(textTarget, textFile); diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 75a53c61ee6..ecb213590ad 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -254,7 +254,9 @@ describe('Actions Notes Store', () => { jest.advanceTimersByTime(time); } - return new Promise((resolve) => requestAnimationFrame(resolve)); + return new Promise((resolve) => { + requestAnimationFrame(resolve); + }); }; const advanceXMoreIntervals = async (number) => { const timeoutLength = pollInterval * number; diff --git a/spec/frontend/runner/mock_data.js b/spec/frontend/runner/mock_data.js index e4351e9c90c..1c2333b552c 100644 --- a/spec/frontend/runner/mock_data.js +++ b/spec/frontend/runner/mock_data.js @@ -1,13 +1,5 @@ // Fixtures generated by: spec/frontend/fixtures/runner.rb -// List queries -import runnersData from 'test_fixtures/graphql/runner/list/admin_runners.query.graphql.json'; -import runnersDataPaginated from 'test_fixtures/graphql/runner/list/admin_runners.query.graphql.paginated.json'; -import runnersCountData from 'test_fixtures/graphql/runner/list/admin_runners_count.query.graphql.json'; -import groupRunnersData from 'test_fixtures/graphql/runner/list/group_runners.query.graphql.json'; -import groupRunnersDataPaginated from 'test_fixtures/graphql/runner/list/group_runners.query.graphql.paginated.json'; -import groupRunnersCountData from 'test_fixtures/graphql/runner/list/group_runners_count.query.graphql.json'; - // Show runner queries import runnerData from 'test_fixtures/graphql/runner/show/runner.query.graphql.json'; import runnerWithGroupData from 'test_fixtures/graphql/runner/show/runner.query.graphql.with_group.json'; @@ -17,6 +9,14 @@ import runnerJobsData from 'test_fixtures/graphql/runner/show/runner_jobs.query. // Edit runner queries import runnerFormData from 'test_fixtures/graphql/runner/edit/runner_form.query.graphql.json'; +// List queries +import runnersData from 'test_fixtures/graphql/runner/list/admin_runners.query.graphql.json'; +import runnersDataPaginated from 'test_fixtures/graphql/runner/list/admin_runners.query.graphql.paginated.json'; +import runnersCountData from 'test_fixtures/graphql/runner/list/admin_runners_count.query.graphql.json'; +import groupRunnersData from 'test_fixtures/graphql/runner/list/group_runners.query.graphql.json'; +import groupRunnersDataPaginated from 'test_fixtures/graphql/runner/list/group_runners.query.graphql.paginated.json'; +import groupRunnersCountData from 'test_fixtures/graphql/runner/list/group_runners_count.query.graphql.json'; + // Other mock data export const onlineContactTimeoutSecs = 2 * 60 * 60; export const staleTimeoutSecs = 5259492; // Ruby's `2.months` diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js index 3ffb99314d6..e44bc8771f5 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js @@ -232,9 +232,7 @@ describe('FilteredSearchBarRoot', () => { }); it('initializes `recentSearchesPromise` prop with a promise by using `recentSearchesService.fetch()`', () => { - jest - .spyOn(wrapper.vm.recentSearchesService, 'fetch') - .mockReturnValue(new Promise(() => [])); + jest.spyOn(wrapper.vm.recentSearchesService, 'fetch').mockResolvedValue([]); wrapper.vm.setupRecentSearch(); diff --git a/spec/frontend_integration/ide/helpers/ide_helper.js b/spec/frontend_integration/ide/helpers/ide_helper.js index 00ce39a5598..8c5ff816c74 100644 --- a/spec/frontend_integration/ide/helpers/ide_helper.js +++ b/spec/frontend_integration/ide/helpers/ide_helper.js @@ -24,13 +24,19 @@ export const switchLeftSidebarTab = (name) => { export const getStatusBar = () => document.querySelector('.ide-status-bar'); export const waitForMonacoEditor = () => - new Promise((resolve) => monacoEditor.onDidCreateEditor(resolve)); + new Promise((resolve) => { + monacoEditor.onDidCreateEditor(resolve); + }); export const waitForEditorDispose = (instance) => - new Promise((resolve) => instance.onDidDispose(resolve)); + new Promise((resolve) => { + instance.onDidDispose(resolve); + }); export const waitForEditorModelChange = (instance) => - new Promise((resolve) => instance.onDidChangeModel(resolve)); + new Promise((resolve) => { + instance.onDidChangeModel(resolve); + }); export const findMonacoEditor = () => screen.findAllByLabelText(/Editor content;/).then(([x]) => x.closest('.monaco-editor')); diff --git a/spec/graphql/types/root_storage_statistics_type_spec.rb b/spec/graphql/types/root_storage_statistics_type_spec.rb index 7818be6ee02..07c8378e7a6 100644 --- a/spec/graphql/types/root_storage_statistics_type_spec.rb +++ b/spec/graphql/types/root_storage_statistics_type_spec.rb @@ -8,7 +8,8 @@ RSpec.describe GitlabSchema.types['RootStorageStatistics'] do it 'has all the required fields' do expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, :build_artifacts_size, :packages_size, :wiki_size, :snippets_size, - :pipeline_artifacts_size, :uploads_size, :dependency_proxy_size) + :pipeline_artifacts_size, :uploads_size, :dependency_proxy_size, + :container_registry_size) end specify { expect(described_class).to require_graphql_authorizations(:read_statistics) } diff --git a/spec/lib/gitlab/kubernetes/cilium_network_policy_spec.rb b/spec/lib/gitlab/kubernetes/cilium_network_policy_spec.rb deleted file mode 100644 index ec1f46100a4..00000000000 --- a/spec/lib/gitlab/kubernetes/cilium_network_policy_spec.rb +++ /dev/null @@ -1,274 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do - let(:policy) do - described_class.new( - name: name, - namespace: namespace, - description: description, - selector: selector, - ingress: ingress, - egress: egress, - labels: labels, - resource_version: resource_version, - annotations: annotations - ) - end - - let(:resource) do - ::Kubeclient::Resource.new( - apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION, - kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND, - metadata: { name: name, namespace: namespace, resourceVersion: resource_version, annotations: annotations }, - spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: egress }, - description: description - ) - end - - let(:selector) { endpoint_selector } - let(:labels) { nil } - let(:name) { 'example-name' } - let(:namespace) { 'example-namespace' } - let(:endpoint_selector) { { matchLabels: { role: 'db' } } } - let(:description) { 'example-description' } - let(:partial_class_name) { described_class.name.split('::').last } - let(:resource_version) { 101 } - let(:annotations) { { 'app.gitlab.com/alert': 'true' } } - let(:ingress) do - [ - { - fromEndpoints: [ - { matchLabels: { project: 'myproject' } } - ] - } - ] - end - - let(:egress) do - [ - { - ports: [{ port: 5978 }] - } - ] - end - - include_examples 'network policy common specs' - - describe '.from_yaml' do - let(:manifest) do - <<~POLICY - apiVersion: cilium.io/v2 - kind: CiliumNetworkPolicy - description: example-description - metadata: - name: example-name - namespace: example-namespace - resourceVersion: 101 - annotations: - app.gitlab.com/alert: "true" - spec: - endpointSelector: - matchLabels: - role: db - ingress: - - fromEndpoints: - - matchLabels: - project: myproject - egress: - - ports: - - port: 5978 - POLICY - end - - subject { Gitlab::Kubernetes::CiliumNetworkPolicy.from_yaml(manifest)&.generate } - - it { is_expected.to eq(resource) } - - context 'with nil manifest' do - let(:manifest) { nil } - - it { is_expected.to be_nil } - end - - context 'with invalid manifest' do - let(:manifest) { "\tfoo: bar" } - - it { is_expected.to be_nil } - end - - context 'with manifest without metadata' do - let(:manifest) do - <<~POLICY - apiVersion: cilium.io/v2 - kind: CiliumNetworkPolicy - spec: - endpointSelector: - matchLabels: - role: db - ingress: - - fromEndpoints: - matchLabels: - project: myproject - POLICY - end - - it { is_expected.to be_nil } - end - - context 'with manifest without spec' do - let(:manifest) do - <<~POLICY - apiVersion: cilium.io/v2 - kind: CiliumNetworkPolicy - metadata: - name: example-name - namespace: example-namespace - POLICY - end - - it { is_expected.to be_nil } - end - - context 'with disallowed class' do - let(:manifest) do - <<~POLICY - apiVersion: cilium.io/v2 - kind: CiliumNetworkPolicy - metadata: - name: example-name - namespace: example-namespace - creationTimestamp: 2020-04-14T00:08:30Z - spec: - endpointSelector: - matchLabels: - role: db - ingress: - - fromEndpoints: - matchLabels: - project: myproject - POLICY - end - - it { is_expected.to be_nil } - end - end - - describe '.from_resource' do - let(:resource) do - ::Kubeclient::Resource.new( - description: description, - metadata: { - name: name, namespace: namespace, creationTimestamp: '2020-04-14T00:08:30Z', - labels: { app: 'foo' }, resourceVersion: resource_version, annotations: annotations - }, - spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: nil, labels: nil } - ) - end - - let(:generated_resource) do - ::Kubeclient::Resource.new( - apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION, - kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND, - description: description, - metadata: { name: name, namespace: namespace, resourceVersion: resource_version, labels: { app: 'foo' }, annotations: annotations }, - spec: { endpointSelector: endpoint_selector, ingress: ingress } - ) - end - - subject { Gitlab::Kubernetes::CiliumNetworkPolicy.from_resource(resource)&.generate } - - it { is_expected.to eq(generated_resource) } - - context 'with nil resource' do - let(:resource) { nil } - - it { is_expected.to be_nil } - end - - context 'with resource without metadata' do - let(:resource) do - ::Kubeclient::Resource.new( - spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: nil, labels: nil } - ) - end - - it { is_expected.to be_nil } - end - - context 'with resource without spec' do - let(:resource) do - ::Kubeclient::Resource.new( - metadata: { name: name, namespace: namespace, uid: '128cf288-7de4-11ea-aceb-42010a800089', resourceVersion: resource_version } - ) - end - - it { is_expected.to be_nil } - end - - context 'with environment_ids' do - subject { Gitlab::Kubernetes::CiliumNetworkPolicy.from_resource(resource, [1, 2, 3]) } - - it 'includes environment_ids in as_json result' do - expect(subject.as_json).to include(environment_ids: [1, 2, 3]) - end - end - end - - describe '#resource' do - subject { policy.resource } - - let(:resource) do - { - apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION, - kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND, - metadata: { name: name, namespace: namespace, resourceVersion: resource_version, annotations: annotations }, - spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: egress }, - description: description - } - end - - it { is_expected.to eq(resource) } - - context 'with labels' do - let(:labels) { { app: 'foo' } } - - before do - resource[:metadata][:labels] = { app: 'foo' } - end - - it { is_expected.to eq(resource) } - end - - context 'without resource_version' do - let(:resource_version) { nil } - - before do - resource[:metadata].delete(:resourceVersion) - end - - it { is_expected.to eq(resource) } - end - - context 'with nil egress' do - let(:egress) { nil } - - before do - resource[:spec].delete(:egress) - end - - it { is_expected.to eq(resource) } - end - - context 'without annotations' do - let(:annotations) { nil } - - before do - resource[:metadata].delete(:annotations) - end - - it { is_expected.to eq(resource) } - end - end -end diff --git a/spec/lib/gitlab/kubernetes/kube_client_spec.rb b/spec/lib/gitlab/kubernetes/kube_client_spec.rb index 521f13dc9cc..dfd5092b54d 100644 --- a/spec/lib/gitlab/kubernetes/kube_client_spec.rb +++ b/spec/lib/gitlab/kubernetes/kube_client_spec.rb @@ -227,20 +227,6 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do end end - describe '#cilium_networking_client' do - subject { client.cilium_networking_client } - - it_behaves_like 'a Kubeclient' - - it 'has the cilium API group endpoint' do - expect(subject.api_endpoint.to_s).to match(%r{\/apis\/cilium.io\Z}) - end - - it 'has the api_version' do - expect(subject.instance_variable_get(:@api_version)).to eq('v2') - end - end - describe '#metrics_client' do subject { client.metrics_client } @@ -428,56 +414,6 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do end end - describe 'networking API group' do - let(:networking_client) { client.networking_client } - - [ - :create_network_policy, - :get_network_policies, - :get_network_policy, - :update_network_policy, - :delete_network_policy - ].each do |method| - describe "##{method}" do - include_examples 'redirection not allowed', method - include_examples 'dns rebinding not allowed', method - - it 'delegates to the networking client' do - expect(client).to delegate_method(method).to(:networking_client) - end - - it 'responds to the method' do - expect(client).to respond_to method - end - end - end - end - - describe 'cilium API group' do - let(:cilium_networking_client) { client.cilium_networking_client } - - [ - :create_cilium_network_policy, - :get_cilium_network_policies, - :get_cilium_network_policy, - :update_cilium_network_policy, - :delete_cilium_network_policy - ].each do |method| - describe "##{method}" do - include_examples 'redirection not allowed', method - include_examples 'dns rebinding not allowed', method - - it 'delegates to the cilium client' do - expect(client).to delegate_method(method).to(:cilium_networking_client) - end - - it 'responds to the method' do - expect(client).to respond_to method - end - end - end - end - describe 'non-entity methods' do it 'does not proxy for non-entity methods' do expect(client).not_to respond_to :proxy_url diff --git a/spec/lib/gitlab/kubernetes/network_policy_spec.rb b/spec/lib/gitlab/kubernetes/network_policy_spec.rb deleted file mode 100644 index 2cba37a1302..00000000000 --- a/spec/lib/gitlab/kubernetes/network_policy_spec.rb +++ /dev/null @@ -1,235 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Kubernetes::NetworkPolicy do - let(:policy) do - described_class.new( - name: name, - namespace: namespace, - selector: selector, - ingress: ingress, - labels: labels - ) - end - - let(:resource) do - ::Kubeclient::Resource.new( - kind: Gitlab::Kubernetes::NetworkPolicy::KIND, - metadata: { name: name, namespace: namespace }, - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - ) - end - - let(:selector) { pod_selector } - let(:labels) { nil } - let(:name) { 'example-name' } - let(:namespace) { 'example-namespace' } - let(:pod_selector) { { matchLabels: { role: 'db' } } } - - let(:ingress) do - [ - { - from: [ - { namespaceSelector: { matchLabels: { project: 'myproject' } } } - ] - } - ] - end - - let(:egress) do - [ - { - ports: [{ port: 5978 }] - } - ] - end - - include_examples 'network policy common specs' - - describe '.from_yaml' do - let(:manifest) do - <<~POLICY - apiVersion: networking.k8s.io/v1 - kind: NetworkPolicy - metadata: - name: example-name - namespace: example-namespace - spec: - podSelector: - matchLabels: - role: db - policyTypes: - - Ingress - ingress: - - from: - - namespaceSelector: - matchLabels: - project: myproject - POLICY - end - - subject { Gitlab::Kubernetes::NetworkPolicy.from_yaml(manifest)&.generate } - - it { is_expected.to eq(resource) } - - context 'with nil manifest' do - let(:manifest) { nil } - - it { is_expected.to be_nil } - end - - context 'with invalid manifest' do - let(:manifest) { "\tfoo: bar" } - - it { is_expected.to be_nil } - end - - context 'with manifest without metadata' do - let(:manifest) do - <<~POLICY - apiVersion: networking.k8s.io/v1 - kind: NetworkPolicy - spec: - podSelector: - matchLabels: - role: db - policyTypes: - - Ingress - ingress: - - from: - - namespaceSelector: - matchLabels: - project: myproject - POLICY - end - - it { is_expected.to be_nil } - end - - context 'with manifest without spec' do - let(:manifest) do - <<~POLICY - apiVersion: networking.k8s.io/v1 - kind: NetworkPolicy - metadata: - name: example-name - namespace: example-namespace - POLICY - end - - it { is_expected.to be_nil } - end - - context 'with disallowed class' do - let(:manifest) do - <<~POLICY - apiVersion: networking.k8s.io/v1 - kind: NetworkPolicy - metadata: - name: example-name - namespace: example-namespace - creationTimestamp: 2020-04-14T00:08:30Z - spec: - podSelector: - matchLabels: - role: db - policyTypes: - - Ingress - ingress: - - from: - - namespaceSelector: - matchLabels: - project: myproject - POLICY - end - - it { is_expected.to be_nil } - end - end - - describe '.from_resource' do - let(:resource) do - ::Kubeclient::Resource.new( - metadata: { - name: name, namespace: namespace, creationTimestamp: '2020-04-14T00:08:30Z', - labels: { app: 'foo' }, resourceVersion: '4990' - }, - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - ) - end - - let(:generated_resource) do - ::Kubeclient::Resource.new( - kind: Gitlab::Kubernetes::NetworkPolicy::KIND, - metadata: { name: name, namespace: namespace, labels: { app: 'foo' } }, - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - ) - end - - subject { Gitlab::Kubernetes::NetworkPolicy.from_resource(resource)&.generate } - - it { is_expected.to eq(generated_resource) } - - context 'with nil resource' do - let(:resource) { nil } - - it { is_expected.to be_nil } - end - - context 'with resource without metadata' do - let(:resource) do - ::Kubeclient::Resource.new( - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - ) - end - - it { is_expected.to be_nil } - end - - context 'with resource without spec' do - let(:resource) do - ::Kubeclient::Resource.new( - metadata: { name: name, namespace: namespace, uid: '128cf288-7de4-11ea-aceb-42010a800089', resourceVersion: '4990' } - ) - end - - it { is_expected.to be_nil } - end - - context 'with environment_ids' do - subject { Gitlab::Kubernetes::NetworkPolicy.from_resource(resource, [1, 2, 3]) } - - it 'includes environment_ids in as_json result' do - expect(subject.as_json).to include(environment_ids: [1, 2, 3]) - end - end - end - - describe '#resource' do - subject { policy.resource } - - let(:resource) do - { - kind: Gitlab::Kubernetes::NetworkPolicy::KIND, - metadata: { name: name, namespace: namespace }, - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - } - end - - it { is_expected.to eq(resource) } - - context 'with labels' do - let(:labels) { { app: 'foo' } } - let(:resource) do - { - kind: Gitlab::Kubernetes::NetworkPolicy::KIND, - metadata: { name: name, namespace: namespace, labels: { app: 'foo' } }, - spec: { podSelector: pod_selector, policyTypes: %w(Ingress), ingress: ingress, egress: nil } - } - end - - it { is_expected.to eq(resource) } - end - 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 deleted file mode 100644 index 2633a89eeee..00000000000 --- a/spec/support/shared_examples/lib/gitlab/kubernetes/network_policy_common_shared_examples.rb +++ /dev/null @@ -1,162 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'network policy common specs' do - let(:name) { 'example-name' } - let(:namespace) { 'example-namespace' } - let(:labels) { nil } - - describe '#generate' do - subject { policy.generate } - - it { is_expected.to eq(Kubeclient::Resource.new(policy.resource)) } - end - - describe 'as_json' do - let(:json_policy) do - { - name: name, - namespace: namespace, - creation_timestamp: nil, - manifest: YAML.dump(policy.resource.deep_stringify_keys), - is_autodevops: false, - is_enabled: true, - environment_ids: [] - } - 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 |