diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-28 09:09:38 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-28 09:09:38 +0000 |
commit | d81f7fc0b3c75a7c95528f21d55be2dd26521f2e (patch) | |
tree | 28714988991b6b1036d935ad4fa4594e223b707b /spec | |
parent | 8b7a679616e450608f5d97a09e5287c939477aab (diff) | |
download | gitlab-ce-d81f7fc0b3c75a7c95528f21d55be2dd26521f2e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/notes/components/notes_app_spec.js | 10 | ||||
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/elasticsearch/logs/lines_spec.rb | 97 | ||||
-rw-r--r-- | spec/lib/gitlab/elasticsearch/logs/pods_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/integrations/base_chat_notification_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/integrations/prometheus_spec.rb | 43 | ||||
-rw-r--r-- | spec/requests/api/environments_spec.rb | 83 | ||||
-rw-r--r-- | spec/requests/projects/issues_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/rubocop/cop/gitlab/namespaced_class_spec.rb | 6 | ||||
-rw-r--r-- | spec/serializers/cluster_entity_spec.rb | 31 | ||||
-rw-r--r-- | spec/serializers/environment_entity_spec.rb | 48 |
11 files changed, 15 insertions, 370 deletions
diff --git a/spec/frontend/notes/components/notes_app_spec.js b/spec/frontend/notes/components/notes_app_spec.js index f4eb69e0d49..acd27dab4eb 100644 --- a/spec/frontend/notes/components/notes_app_spec.js +++ b/spec/frontend/notes/components/notes_app_spec.js @@ -217,8 +217,7 @@ describe('note_app', () => { }); afterEach(() => { - waitForDiscussionsRequest(); - resetHTMLFixture(); + return waitForDiscussionsRequest().then(() => resetHTMLFixture()); }); it('renders skeleton notes', () => { @@ -471,7 +470,7 @@ describe('note_app', () => { wrapper = shallowMount(NotesApp, { propsData, store: createStore() }); await waitForPromises(); - expect(axiosMock.history.get[0].params).toBeUndefined(); + expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 }); }); }); @@ -496,14 +495,14 @@ describe('note_app', () => { wrapper = mountWithNotesFilter(undefined); await waitForPromises(); - expect(axiosMock.history.get[0].params).toBeUndefined(); + expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 }); }); it('does not include extra query params when filter is already set to default', async () => { wrapper = mountWithNotesFilter(constants.DISCUSSION_FILTERS_DEFAULT_VALUE); await waitForPromises(); - expect(axiosMock.history.get[0].params).toBeUndefined(); + expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 }); }); it('includes extra query params when filter is not set to default', async () => { @@ -512,6 +511,7 @@ describe('note_app', () => { expect(axiosMock.history.get[0].params).toEqual({ notes_filter: constants.DISCUSSION_FILTERS_DEFAULT_VALUE, + per_page: 20, persist_filter: false, }); }); diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 38f29ac2559..bf69d24bcb9 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -1351,7 +1351,7 @@ describe('Actions Notes Store', () => { return testAction( actions.fetchDiscussions, {}, - null, + { noteableType: notesConstants.MERGE_REQUEST_NOTEABLE_TYPE }, [ { type: mutationTypes.ADD_OR_UPDATE_DISCUSSIONS, payload: { discussion } }, { type: mutationTypes.SET_FETCHING_DISCUSSIONS, payload: false }, @@ -1360,13 +1360,11 @@ describe('Actions Notes Store', () => { ); }); - it('dispatches `fetchDiscussionsBatch` action if `paginatedIssueDiscussions` feature flag is enabled', () => { - window.gon = { features: { paginatedIssueDiscussions: true } }; - + it('dispatches `fetchDiscussionsBatch` action if noteable is an Issue', () => { return testAction( actions.fetchDiscussions, { path: 'test-path', filter: 'test-filter', persistFilter: 'test-persist-filter' }, - null, + { noteableType: notesConstants.ISSUE_NOTEABLE_TYPE }, [], [ { @@ -1389,7 +1387,7 @@ describe('Actions Notes Store', () => { return testAction( actions.fetchDiscussions, { path: 'test-path', filter: 'test-filter', persistFilter: 'test-persist-filter' }, - null, + { noteableType: notesConstants.MERGE_REQUEST_NOTEABLE_TYPE }, [], [ { diff --git a/spec/lib/gitlab/elasticsearch/logs/lines_spec.rb b/spec/lib/gitlab/elasticsearch/logs/lines_spec.rb deleted file mode 100644 index f93c1aa1974..00000000000 --- a/spec/lib/gitlab/elasticsearch/logs/lines_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Elasticsearch::Logs::Lines do - let(:client) { Elasticsearch::Transport::Client } - - let(:es_message_1) { { timestamp: "2019-12-13T14:35:34.034Z", pod: "production-6866bc8974-m4sk4", message: "10.8.2.1 - - [25/Oct/2019:08:03:22 UTC] \"GET / HTTP/1.1\" 200 13" } } - let(:es_message_2) { { timestamp: "2019-12-13T14:35:35.034Z", pod: "production-6866bc8974-m4sk4", message: "10.8.2.1 - - [27/Oct/2019:23:49:54 UTC] \"GET / HTTP/1.1\" 200 13" } } - let(:es_message_3) { { timestamp: "2019-12-13T14:35:36.034Z", pod: "production-6866bc8974-m4sk4", message: "10.8.2.1 - - [04/Nov/2019:23:09:24 UTC] \"GET / HTTP/1.1\" 200 13" } } - let(:es_message_4) { { timestamp: "2019-12-13T14:35:37.034Z", pod: "production-6866bc8974-m4sk4", message: "- -\u003e /" } } - - let(:es_response) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/logs_response.json')) } - - subject { described_class.new(client) } - - let(:namespace) { "autodevops-deploy-9-production" } - let(:pod_name) { "production-6866bc8974-m4sk4" } - let(:container_name) { "auto-deploy-app" } - let(:search) { "foo +bar "} - let(:start_time) { "2019-12-13T14:35:34.034Z" } - let(:end_time) { "2019-12-13T14:35:34.034Z" } - let(:cursor) { "9999934,1572449784442" } - - let(:body) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query.json')) } - let(:body_with_container) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_container.json')) } - let(:body_with_search) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_search.json')) } - let(:body_with_times) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_times.json')) } - let(:body_with_start_time) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_start_time.json')) } - let(:body_with_end_time) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_end_time.json')) } - let(:body_with_cursor) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_cursor.json')) } - let(:body_with_filebeat_6) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/query_with_filebeat_6.json')) } - - RSpec::Matchers.define :a_hash_equal_to_json do |expected| - match do |actual| - actual.as_json == expected - end - end - - describe '#pod_logs' do - it 'returns the logs as an array' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can further filter the logs by container name' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_container)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, container_name: container_name) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can further filter the logs by search' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_search)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, search: search) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can further filter the logs by start_time and end_time' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_times)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, start_time: start_time, end_time: end_time) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can further filter the logs by only start_time' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_start_time)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, start_time: start_time) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can further filter the logs by only end_time' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_end_time)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, end_time: end_time) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can search after a cursor' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_cursor)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, cursor: cursor) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - - it 'can search on filebeat 6' do - expect(client).to receive(:search).with(body: a_hash_equal_to_json(body_with_filebeat_6)).and_return(es_response) - - result = subject.pod_logs(namespace, pod_name: pod_name, chart_above_v2: false) - expect(result).to eq(logs: [es_message_4, es_message_3, es_message_2, es_message_1], cursor: cursor) - end - end -end diff --git a/spec/lib/gitlab/elasticsearch/logs/pods_spec.rb b/spec/lib/gitlab/elasticsearch/logs/pods_spec.rb deleted file mode 100644 index 07fa0980d36..00000000000 --- a/spec/lib/gitlab/elasticsearch/logs/pods_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Elasticsearch::Logs::Pods do - let(:client) { Elasticsearch::Transport::Client } - - let(:es_query) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/pods_query.json'), symbolize_names: true) } - let(:es_response) { Gitlab::Json.parse(fixture_file('lib/elasticsearch/pods_response.json')) } - let(:namespace) { "autodevops-deploy-9-production" } - - subject { described_class.new(client) } - - describe '#pods' do - it 'returns the pods' do - expect(client).to receive(:search).with(body: es_query).and_return(es_response) - - result = subject.pods(namespace) - expect(result).to eq([ - { - name: "runner-gitlab-runner-7bbfb5dcb5-p6smb", - container_names: %w[runner-gitlab-runner] - }, - { - name: "elastic-stack-elasticsearch-master-1", - container_names: %w[elasticsearch chown sysctl] - }, - { - name: "ingress-nginx-ingress-controller-76449bcc8d-8qgl6", - container_names: %w[nginx-ingress-controller] - } - ]) - end - end -end diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb index 8cbefbb9b47..eb503e501d6 100644 --- a/spec/models/integrations/base_chat_notification_spec.rb +++ b/spec/models/integrations/base_chat_notification_spec.rb @@ -292,15 +292,15 @@ RSpec.describe Integrations::BaseChatNotification do end end - describe '#get_channel_field' do + describe '#event_channel_value' do it 'returns the channel field value for the given event' do subject.push_channel = '#pushes' - expect(subject.get_channel_field(:push)).to eq('#pushes') + expect(subject.event_channel_value(:push)).to eq('#pushes') end it 'raises an error for unsupported events' do - expect { subject.get_channel_field(:foo) }.to raise_error(NoMethodError) + expect { subject.event_channel_value(:foo) }.to raise_error(NoMethodError) end end end diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb index fbeaebfd807..ae965ed78d1 100644 --- a/spec/models/integrations/prometheus_spec.rb +++ b/spec/models/integrations/prometheus_spec.rb @@ -475,47 +475,4 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, end end end - - describe '#fields' do - let(:expected_fields) do - [ - { - type: 'checkbox', - name: 'manual_configuration', - title: s_('PrometheusService|Active'), - help: s_('PrometheusService|Select this checkbox to override the auto configuration settings with your own settings.'), - required: true - }, - { - type: 'text', - name: 'api_url', - title: 'API URL', - placeholder: s_('PrometheusService|https://prometheus.example.com/'), - help: s_('PrometheusService|The Prometheus API base URL.'), - required: true - }, - { - type: 'text', - name: 'google_iap_audience_client_id', - title: 'Google IAP Audience Client ID', - placeholder: s_('PrometheusService|IAP_CLIENT_ID.apps.googleusercontent.com'), - help: s_('PrometheusService|The ID of the IAP-secured resource.'), - autocomplete: 'off', - required: false - }, - { - type: 'textarea', - name: 'google_iap_service_account_json', - title: 'Google IAP Service Account JSON', - placeholder: s_('PrometheusService|{ "type": "service_account", "project_id": ... }'), - help: s_('PrometheusService|The contents of the credentials.json file of your service account.'), - required: false - } - ] - end - - it 'returns fields' do - expect(integration.fields).to eq(expected_fields) - end - end end diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb index 93f21c880a4..a35c1630caa 100644 --- a/spec/requests/api/environments_spec.rb +++ b/spec/requests/api/environments_spec.rb @@ -26,90 +26,7 @@ RSpec.describe API::Environments do expect(json_response.first['tier']).to eq(environment.tier) expect(json_response.first['external_url']).to eq(environment.external_url) expect(json_response.first['project']).to match_schema('public_api/v4/project') - expect(json_response.first['enable_advanced_logs_querying']).to eq(false) expect(json_response.first).not_to have_key('last_deployment') - expect(json_response.first).not_to have_key('gitlab_managed_apps_logs_path') - end - - context 'when the user can read pod logs' do - context 'with successful deployment on cluster' do - let_it_be(:deployment) { create(:deployment, :on_cluster, :success, environment: environment, project: project) } - - it 'returns environment with enable_advanced_logs_querying and logs_api_path' do - get api("/projects/#{project.id}/environments", user) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.size).to eq(1) - expect(json_response.first['gitlab_managed_apps_logs_path']).to eq( - "/#{project.full_path}/-/logs/k8s.json?cluster_id=#{deployment.cluster_id}" - ) - end - end - - context 'when elastic stack is available' do - before do - allow_next_found_instance_of(Environment) do |env| - allow(env).to receive(:elastic_stack_available?).and_return(true) - end - end - - it 'returns environment with enable_advanced_logs_querying and logs_api_path' do - get api("/projects/#{project.id}/environments", user) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.size).to eq(1) - expect(json_response.first['enable_advanced_logs_querying']).to eq(true) - expect(json_response.first['logs_api_path']).to eq( - "/#{project.full_path}/-/logs/elasticsearch.json?environment_name=#{environment.name}" - ) - end - end - - context 'when elastic stack is not available' do - before do - allow_next_found_instance_of(Environment) do |env| - allow(env).to receive(:elastic_stack_available?).and_return(false) - end - end - - it 'returns environment with enable_advanced_logs_querying logs_api_path' do - get api("/projects/#{project.id}/environments", user) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.size).to eq(1) - expect(json_response.first['enable_advanced_logs_querying']).to eq(false) - expect(json_response.first['logs_api_path']).to eq( - "/#{project.full_path}/-/logs/k8s.json?environment_name=#{environment.name}" - ) - end - end - end - - context 'when the user cannot read pod logs' do - before do - allow_next_found_instance_of(User) do |user| - allow(user).to receive(:can?).and_call_original - allow(user).to receive(:can?).with(:read_pod_logs, project).and_return(false) - end - end - - it 'does not contain enable_advanced_logs_querying' do - get api("/projects/#{project.id}/environments", user) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.size).to eq(1) - expect(json_response.first).not_to have_key('enable_advanced_logs_querying') - expect(json_response.first).not_to have_key('logs_api_path') - expect(json_response.first).not_to have_key('gitlab_managed_apps_logs_path') - end end context 'when filtering' do diff --git a/spec/requests/projects/issues_controller_spec.rb b/spec/requests/projects/issues_controller_spec.rb index 248e3e3a92b..de1d55ff5be 100644 --- a/spec/requests/projects/issues_controller_spec.rb +++ b/spec/requests/projects/issues_controller_spec.rb @@ -50,22 +50,6 @@ RSpec.describe Projects::IssuesController do a_hash_including('id' => discussion_2.id.to_s) ]) end - - context 'when paginated_issue_discussions is disabled' do - before do - stub_feature_flags(paginated_issue_discussions: false) - end - - it 'returns all discussions and ignores per_page param' do - get_discussions(per_page: 2) - - discussions = Gitlab::Json.parse(response.body) - notes = discussions.flat_map { |d| d['notes'] } - - expect(discussions.count).to eq(4) - expect(notes.count).to eq(5) - end - end end end diff --git a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb index d9209a8672c..83d0eaf4884 100644 --- a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb +++ b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb @@ -20,7 +20,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a class definition without additional namespace' do expect_offense(namespaced(<<~SOURCE)) class MyClass - ^^^^^^^^^^^^^ #{described_class::MSG} + ^^^^^^^ #{described_class::MSG} end SOURCE end @@ -28,7 +28,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a compact class definition without additional namespace' do expect_offense(<<~SOURCE, namespace: namespace) class %{namespace}::MyClass - ^{namespace}^^^^^^^^^^^^^^^ #{described_class::MSG} + ^{namespace}^^^^^^^^^ #{described_class::MSG} end SOURCE end @@ -36,7 +36,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a class definition with inheritance without additional namespace' do expect_offense(namespaced(<<~SOURCE)) class MyClass < ApplicationRecord - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} + ^^^^^^^ #{described_class::MSG} def some_method true end diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index 514828e3c69..93003e75c0c 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -56,37 +56,6 @@ RSpec.describe ClusterEntity do end end - context 'gitlab_managed_apps_logs_path' do - let(:cluster) { create(:cluster, :project) } - let(:user) { create(:user) } - - subject { described_class.new(cluster, request: request).as_json } - - before do - allow_next_instance_of(Clusters::ClusterPresenter) do |presenter| - allow(presenter).to receive(:show_path).and_return(nil) - end - end - - it 'return projects log explorer path' do - log_explorer_path = project_logs_path(cluster.project, cluster_id: cluster.id) - - expect_next_instance_of(Clusters::ClusterPresenter, cluster, current_user: user) do |presenter| - expect(presenter).to receive(:gitlab_managed_apps_logs_path).and_return(log_explorer_path) - end - - expect(subject[:gitlab_managed_apps_logs_path]).to eq(log_explorer_path) - end - - context 'when feature is disabled' do - before do - stub_feature_flags(monitor_logging: false) - end - - specify { is_expected.not_to include(:gitlab_managed_apps_logs_path) } - end - end - context 'enable_advanced_logs_querying' do let(:cluster) { create(:cluster, :project) } let(:user) { create(:user) } diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 9b6a293da16..cbe32600941 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -133,54 +133,6 @@ RSpec.describe EnvironmentEntity do end end - context 'pod_logs' do - context 'with reporter access' do - before do - project.add_reporter(user) - end - - it 'does not expose logs keys' do - expect(subject).not_to include(:logs_path) - expect(subject).not_to include(:logs_api_path) - expect(subject).not_to include(:enable_advanced_logs_querying) - end - end - - context 'with developer access' do - before do - project.add_developer(user) - end - - it 'exposes logs keys' do - expect(subject).to include(:logs_path) - expect(subject).to include(:logs_api_path) - expect(subject).to include(:enable_advanced_logs_querying) - end - - it 'uses k8s api when ES is not available' do - expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(project, environment_name: environment.name, format: :json)) - end - - it 'uses ES api when ES is available' do - allow(environment).to receive(:elastic_stack_available?).and_return(true) - - expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(project, environment_name: environment.name, format: :json)) - end - - context 'with feature flag disabled' do - before do - stub_feature_flags(monitor_logging: false) - end - - it 'does not expose logs keys' do - expect(subject).not_to include(:logs_path) - expect(subject).not_to include(:logs_api_path) - expect(subject).not_to include(:enable_advanced_logs_querying) - end - end - end - end - context 'with deployment service ready' do before do allow(environment).to receive(:has_terminals?).and_return(true) |