diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 18:09:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 18:09:14 +0300 |
commit | 9498dc957345829f29fe0bc4e55c969783b457be (patch) | |
tree | ca19b899f1eee13ad892fe18ece040347c3a1e71 /spec/controllers | |
parent | ba27dbddc7dbc42f2cc8d84e815a9ea19f87a81d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
5 files changed, 0 insertions, 396 deletions
diff --git a/spec/controllers/admin/clusters_controller_spec.rb b/spec/controllers/admin/clusters_controller_spec.rb index d04cd20f4e6..35bfb829bf7 100644 --- a/spec/controllers/admin/clusters_controller_spec.rb +++ b/spec/controllers/admin/clusters_controller_spec.rb @@ -102,39 +102,6 @@ RSpec.describe Admin::ClustersController, feature_category: :deployment_manageme end end - it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do - let(:cluster) { create(:cluster, :instance, :provided_by_gcp) } - - let(:metrics_dashboard_req_params) do - { - id: cluster.id - } - end - end - - describe 'GET #prometheus_proxy' do - let(:user) { admin } - let(:proxyable) do - create(:cluster, :instance, :provided_by_gcp) - end - - it_behaves_like 'metrics dashboard prometheus api proxy' do - context 'with anonymous user' do - let(:prometheus_body) { nil } - - before do - sign_out(admin) - end - - it 'returns 404' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - end - describe 'POST #create_user' do let(:params) do { @@ -283,41 +250,6 @@ RSpec.describe Admin::ClustersController, feature_category: :deployment_manageme let(:subject) { get_show } end - describe 'functionality' do - context 'when remove_monitor_metrics FF is disabled' do - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - render_views - - it 'responds successfully' do - get_show - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:cluster)).to eq(cluster) - end - - it 'renders integration tab view' do - get_show(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_integrations') - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'when remove_monitor_metrics FF is enabled' do - render_views - - it 'renders details tab view' do - get_show(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_details') - expect(response).to have_gitlab_http_status(:ok) - end - end - end - describe 'security' do it { expect { get_show }.to be_allowed_for(:admin) } it { expect { get_show }.to be_denied_for(:user) } diff --git a/spec/controllers/groups/clusters_controller_spec.rb b/spec/controllers/groups/clusters_controller_spec.rb index f36494c3d78..6c747d4f00f 100644 --- a/spec/controllers/groups/clusters_controller_spec.rb +++ b/spec/controllers/groups/clusters_controller_spec.rb @@ -115,46 +115,6 @@ RSpec.describe Groups::ClustersController, feature_category: :deployment_managem end end - it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do - let(:cluster) { create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) } - - let(:metrics_dashboard_req_params) do - { - id: cluster.id, - group_id: group.name - } - end - end - - describe 'GET #prometheus_proxy' do - let(:proxyable) do - create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) - end - - it_behaves_like 'metrics dashboard prometheus api proxy' do - let(:proxyable_params) do - { - id: proxyable.id.to_s, - group_id: group.name - } - end - - context 'with anonymous user' do - let(:prometheus_body) { nil } - - before do - sign_out(user) - end - - it 'returns 404' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - end - describe 'POST create for existing cluster' do let(:params) do { @@ -353,41 +313,6 @@ RSpec.describe Groups::ClustersController, feature_category: :deployment_managem let(:subject) { go } end - describe 'functionality' do - context 'when remove_monitor_metrics FF is disabled' do - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - render_views - - it 'renders view' do - go - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:cluster)).to eq(cluster) - end - - it 'renders integration tab view', :aggregate_failures do - go(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_integrations') - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'when remove_monitor_metrics FF is enabled' do - render_views - - it 'renders details tab view', :aggregate_failures do - go(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_details') - expect(response).to have_gitlab_http_status(:ok) - end - end - end - describe 'security' do it('is allowed for admin when admin mode is enabled', :enable_admin_mode) { expect { go }.to be_allowed_for(:admin) } it('is denied for admin when admin mode is disabled') { expect { go }.to be_denied_for(:admin) } diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index f976b5bfe67..bface886674 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -113,57 +113,6 @@ RSpec.describe Projects::ClustersController, feature_category: :deployment_manag end end - describe 'GET #prometheus_proxy' do - let(:proxyable) do - create(:cluster, :provided_by_gcp, projects: [project]) - end - - it_behaves_like 'metrics dashboard prometheus api proxy' do - let(:proxyable_params) do - { - id: proxyable.id.to_s, - namespace_id: project.namespace.full_path, - project_id: project.path - } - end - - context 'with anonymous user' do - let(:prometheus_body) { nil } - - before do - sign_out(user) - end - - it 'redirects to signin page' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to redirect_to(new_user_session_path) - end - end - - context 'with a public project' do - before do - project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) - project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) - end - - context 'with guest user' do - let(:prometheus_body) { nil } - - before do - project.add_guest(user) - end - - it 'returns 404' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - end - end - it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } @@ -396,41 +345,6 @@ RSpec.describe Projects::ClustersController, feature_category: :deployment_manag let(:subject) { go } end - describe 'functionality' do - context 'when remove_monitor_metrics FF is disabled' do - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - render_views - - it "renders view" do - go - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:cluster)).to eq(cluster) - end - - it 'renders integration tab view' do - go(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_integrations') - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'when remove_monitor_metrics FF is enabled' do - render_views - - it 'renders details tab view', :aggregate_failures do - go(tab: 'integrations') - - expect(response).to render_template('clusters/clusters/_details') - expect(response).to have_gitlab_http_status(:ok) - end - end - end - describe 'security' do it 'is allowed for admin when admin mode enabled', :enable_admin_mode do expect { go }.to be_allowed_for(:admin) diff --git a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb b/spec/controllers/projects/environments/prometheus_api_controller_spec.rb deleted file mode 100644 index ef2d743c82f..00000000000 --- a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb +++ /dev/null @@ -1,96 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Projects::Environments::PrometheusApiController do - let_it_be(:user) { create(:user) } - let_it_be_with_reload(:project) { create(:project) } - let_it_be(:proxyable) { create(:environment, project: project) } - - before do - project.add_reporter(user) - sign_in(user) - end - - describe 'GET #prometheus_proxy' do - it_behaves_like 'metrics dashboard prometheus api proxy' do - let(:proxyable_params) do - { - id: proxyable.id.to_s, - namespace_id: project.namespace.full_path, - project_id: project.path - } - end - - context 'with variables' do - let(:prometheus_body) { '{"status":"success"}' } - let(:pod_name) { "pod1" } - - before do - expected_params[:query] = %{up{pod_name="#{pod_name}"}} - expected_params[:variables] = { 'pod_name' => pod_name } - end - - it 'replaces variables with values' do - get :prometheus_proxy, params: prometheus_proxy_params.merge( - query: 'up{pod_name="{{pod_name}}"}', variables: { 'pod_name' => pod_name } - ) - - expect(response).to have_gitlab_http_status(:success) - expect(Prometheus::ProxyService).to have_received(:new) - .with(proxyable, 'GET', 'query', expected_params) - end - - context 'with invalid variables' do - let(:params_with_invalid_variables) do - prometheus_proxy_params.merge( - query: 'up{pod_name="{{pod_name}}"}', variables: ['a'] - ) - end - - it 'returns 400' do - get :prometheus_proxy, params: params_with_invalid_variables - - expect(response).to have_gitlab_http_status(:bad_request) - expect(Prometheus::ProxyService).not_to receive(:new) - end - end - end - - context 'with anonymous user' do - let(:prometheus_body) { nil } - - before do - sign_out(user) - end - - it 'redirects to signin page' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to redirect_to(new_user_session_path) - end - end - - context 'with a public project' do - before do - project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) - project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) - end - - context 'with guest user' do - let(:prometheus_body) { nil } - - before do - project.add_guest(user) - end - - it 'returns 404' do - get :prometheus_proxy, params: prometheus_proxy_params - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - end - end -end diff --git a/spec/controllers/projects/prometheus/alerts_controller_spec.rb b/spec/controllers/projects/prometheus/alerts_controller_spec.rb index 44292b9ce19..3e64631fbf1 100644 --- a/spec/controllers/projects/prometheus/alerts_controller_spec.rb +++ b/spec/controllers/projects/prometheus/alerts_controller_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Projects::Prometheus::AlertsController, feature_category: :incide let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:environment) { create(:environment, project: project) } - let_it_be(:metric) { create(:prometheus_metric, project: project) } before do project.add_maintainer(user) @@ -43,16 +42,6 @@ RSpec.describe Projects::Prometheus::AlertsController, feature_category: :incide end end - shared_examples 'project non-specific metric' do |status| - let(:other) { create(:prometheus_alert) } - - it "returns #{status}" do - make_request(id: other.prometheus_metric_id) - - expect(response).to have_gitlab_http_status(status) - end - end - describe 'POST #notify' do let(:alert_1) { build(:alert_management_alert, :prometheus, project: project) } let(:alert_2) { build(:alert_management_alert, :prometheus, project: project) } @@ -115,67 +104,7 @@ RSpec.describe Projects::Prometheus::AlertsController, feature_category: :incide end end - describe 'GET #metrics_dashboard', feature_category: :metrics do - let!(:alert) do - create(:prometheus_alert, project: project, environment: environment, prometheus_metric: metric) - end - - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - it 'returns a json object with the correct keys' do - get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.keys).to contain_exactly('dashboard', 'status', 'metrics_data') - end - - it 'is the correct embed' do - get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json - - title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title'] - - expect(title).to eq(metric.title) - end - - it 'finds the first alert embed without environment_id' do - get :metrics_dashboard, params: request_params(id: metric.id), format: :json - - title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title'] - - expect(title).to eq(metric.title) - end - - it 'returns 404 for non-existant alerts' do - get :metrics_dashboard, params: request_params(id: 0), format: :json - - expect(response).to have_gitlab_http_status(:not_found) - end - - it 'returns 404 when metrics dashboard feature is unavailable' do - stub_feature_flags(remove_monitor_metrics: true) - - get :metrics_dashboard, params: request_params(id: 0), format: :json - - expect(response).to have_gitlab_http_status(:not_found) - end - end - def project_params(opts = {}) opts.reverse_merge(namespace_id: project.namespace, project_id: project) end - - def request_params(opts = {}, defaults = {}) - project_params(opts.reverse_merge(defaults)) - end - - def alert_path(alert) - project_prometheus_alert_path( - project, - alert.prometheus_metric_id, - environment_id: alert.environment, - format: :json - ) - end end |