Commit 00d8836c authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'refactor-monitor-specs' into 'master'

Refactor monitor tests to use a shared context

Closes #222278

See merge request gitlab-org/gitlab!40141
parents 6691e962 50acbf44
# frozen_string_literal: true
require_relative 'cluster_with_prometheus.rb'
module QA
RSpec.describe 'Monitor' do
describe 'with Prometheus in a Gitlab-managed cluster', :orchestrated, :kubernetes, :requires_admin do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
RSpec.describe 'Monitor', :orchestrated, :kubernetes, :requires_admin do
include_context "cluster with Prometheus installed"
before do
Flow::Login.sign_in_unless_signed_in
@project.visit!
end
after :all do
@cluster.remove!
end
it 'configures custom metrics' do
verify_add_custom_metric
verify_edit_custom_metric
......@@ -105,53 +92,6 @@ module QA
private
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
def verify_add_custom_metric
Page::Project::Menu.perform(&:go_to_integrations_settings)
Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration)
......@@ -199,5 +139,4 @@ module QA
end
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.configure do |rspec|
# This config option will be enabled by default on RSpec 4,
# but for reasons of backwards compatibility, you have to
# set it on RSpec 3.
#
# It causes the host group and examples to inherit metadata
# from the shared context.
rspec.shared_context_metadata_behavior = :apply_to_host_groups
end
RSpec.shared_context "cluster with Prometheus installed", shared_context: :metadata do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
after :all do
@cluster.remove!
end
end
end
# frozen_string_literal: true
require 'pathname'
require_relative 'cluster_with_prometheus.rb'
module QA
RSpec.describe 'Monitor' do
describe 'with Prometheus in a Gitlab-managed cluster', :orchestrated, :kubernetes, :requires_admin do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
after :all do
@cluster.remove!
end
RSpec.describe 'Monitor', :orchestrated, :kubernetes, :requires_admin do
include_context "cluster with Prometheus installed"
before do
Flow::Login.sign_in_unless_signed_in
......@@ -58,53 +45,6 @@ module QA
private
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
def verify_metrics(on_dashboard)
on_dashboard.wait_for_metrics
......@@ -176,5 +116,4 @@ module QA
end
end
end
end
end
# frozen_string_literal: true
#
module QA
RSpec.configure do |rspec|
# This config option will be enabled by default on RSpec 4,
# but for reasons of backwards compatibility, you have to
# set it on RSpec 3.
#
# It causes the host group and examples to inherit metadata
# from the shared context.
rspec.shared_context_metadata_behavior = :apply_to_host_groups
end
RSpec.shared_context "cluster with Prometheus installed", shared_context: :metadata do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
after :all do
@cluster.remove!
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment