Commit be1011fe authored by Markus Koller's avatar Markus Koller

Merge branch 'aa-speed-up-ee-usage-data-spec' into 'master'

Speed up EE usage data specs

See merge request gitlab-org/gitlab!38775
parents 71ce21e3 57741742
......@@ -268,392 +268,392 @@ RSpec.describe Gitlab::UsageData do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
end
end
end
describe 'usage_activity_by_stage_configure' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
create(:slack_service, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
end
expect(described_class.usage_activity_by_stage_configure({})).to include(
projects_slack_notifications_active: 2,
projects_slack_slash_active: 2,
projects_with_prometheus_alerts: 2
)
expect(described_class.usage_activity_by_stage_configure(described_class.last_28_days_time_period)).to include(
projects_slack_notifications_active: 1,
projects_slack_slash_active: 1,
projects_with_prometheus_alerts: 1
)
end
end
context 'for configure' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
create(:slack_service, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to include(
projects_slack_notifications_active: 2,
projects_slack_slash_active: 2,
projects_with_prometheus_alerts: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:configure]).to include(
projects_slack_notifications_active: 1,
projects_slack_slash_active: 1,
projects_with_prometheus_alerts: 1
)
end
describe 'usage_activity_by_stage_create' do
it 'includes accurate usage_activity_by_stage data', :aggregate_failures do
for_defined_days_back do
user = create(:user)
project = create(:project, :repository_private, :github_imported,
:test_repo, creator: user)
merge_request = create(:merge_request, source_project: project)
project_rule = create(:approval_project_rule, project: project)
merge_rule = create(:approval_merge_request_rule, merge_request: merge_request)
create(:approval_merge_request_rule_source, approval_merge_request_rule: merge_rule, approval_project_rule: project_rule)
create(:project, creator: user)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
create(:approval_project_rule, project: project)
protected_branch = create(:protected_branch, project: project)
create(:approval_project_rule, protected_branches: [protected_branch], project: project)
create(:suggestion, note: create(:note, project: project))
create(:code_owner_rule, merge_request: merge_request, approvals_required: 3)
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7)
create(:approval_merge_request_rule, merge_request: merge_request)
create_list(:code_owner_rule, 3, approvals_required: 2)
create_list(:code_owner_rule, 2)
end
context 'for create' do
it 'includes accurate usage_activity_by_stage data', :aggregate_failures do
for_defined_days_back do
user = create(:user)
project = create(:project, :repository_private, :github_imported,
:test_repo, creator: user)
merge_request = create(:merge_request, source_project: project)
project_rule = create(:approval_project_rule, project: project)
merge_rule = create(:approval_merge_request_rule, merge_request: merge_request)
create(:approval_merge_request_rule_source, approval_merge_request_rule: merge_rule, approval_project_rule: project_rule)
create(:project, creator: user)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
create(:approval_project_rule, project: project)
protected_branch = create(:protected_branch, project: project)
create(:approval_project_rule, protected_branches: [protected_branch], project: project)
create(:suggestion, note: create(:note, project: project))
create(:code_owner_rule, merge_request: merge_request, approvals_required: 3)
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7)
create(:approval_merge_request_rule, merge_request: merge_request)
create_list(:code_owner_rule, 3, approvals_required: 2)
create_list(:code_owner_rule, 2)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include(
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
merge_requests_with_added_rules: 12,
merge_requests_with_optional_codeowners: 4,
merge_requests_with_required_codeowners: 8,
projects_imported_from_github: 2,
projects_with_repositories_enabled: 12,
protected_branches: 2,
suggestions: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include(
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
merge_requests_with_added_rules: 6,
merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4,
projects_imported_from_github: 1,
projects_with_repositories_enabled: 6,
protected_branches: 1,
suggestions: 1
)
end
expect(described_class.usage_activity_by_stage_create({})).to include(
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
merge_requests_with_added_rules: 12,
merge_requests_with_optional_codeowners: 4,
merge_requests_with_required_codeowners: 8,
projects_imported_from_github: 2,
projects_with_repositories_enabled: 12,
protected_branches: 2,
suggestions: 2
)
expect(described_class.usage_activity_by_stage_create(described_class.last_28_days_time_period)).to include(
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
merge_requests_with_added_rules: 6,
merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4,
projects_imported_from_github: 1,
projects_with_repositories_enabled: 6,
protected_branches: 1,
suggestions: 1
)
end
end
describe 'usage_activity_by_stage_manage' do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
ldap:
{ enabled: true, servers: ldap_server_config }
)
for_defined_days_back do
user = create(:user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
create(:cycle_analytics_group_stage)
create(:compliance_framework_project_setting)
end
context 'for manage' do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
ldap:
{ enabled: true, servers: ldap_server_config }
)
for_defined_days_back do
user = create(:user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
create(:cycle_analytics_group_stage)
create(:compliance_framework_project_setting)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include(
ldap_keys: 2,
ldap_users: 2,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
group_saml_enabled: true
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include(
ldap_keys: 1,
ldap_users: 1,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
group_saml_enabled: true
)
end
def ldap_server_config
{
'main' =>
{
'provider_name' => 'ldapmain',
'group_base' => 'ou=groups',
'admin_group' => 'my_group'
},
'secondary' =>
{
'provider_name' => 'ldapsecondary',
'group_base' => nil,
'admin_group' => nil
}
}
end
expect(described_class.usage_activity_by_stage_manage({})).to include(
ldap_keys: 2,
ldap_users: 2,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
group_saml_enabled: true
)
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
ldap_keys: 1,
ldap_users: 1,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
group_saml_enabled: true
)
end
def ldap_server_config
{
'main' =>
{
'provider_name' => 'ldapmain',
'group_base' => 'ou=groups',
'admin_group' => 'my_group'
},
'secondary' =>
{
'provider_name' => 'ldapsecondary',
'group_base' => nil,
'admin_group' => nil
}
}
end
end
describe 'usage_activity_by_stage_monitor' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user, dashboard: 'operations')
project = create(:project, creator: user)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:project_error_tracking_setting, project: project)
create(:project_tracing_setting, project: project)
end
expect(described_class.usage_activity_by_stage_monitor({})).to include(
operations_dashboard_users_with_projects_added: 2,
projects_prometheus_active: 2,
projects_with_error_tracking_enabled: 2,
projects_with_tracing_enabled: 2
)
expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include(
operations_dashboard_users_with_projects_added: 1,
projects_prometheus_active: 1,
projects_with_error_tracking_enabled: 1,
projects_with_tracing_enabled: 1
)
end
end
describe 'usage_activity_by_stage_package' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, packages: [create(:package)] )
end
expect(described_class.usage_activity_by_stage_package({})).to eq(
projects_with_packages: 2
)
expect(described_class.usage_activity_by_stage_package(described_class.last_28_days_time_period)).to eq(
projects_with_packages: 1
)
end
end
describe 'usage_activity_by_stage_plan' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
board = create(:board, project: project)
create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
create(:list, board: board, label: create(:label, project: project), user: user)
create(:epic, author: user)
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user))
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user))
end
context 'for monitor' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user, dashboard: 'operations')
project = create(:project, creator: user)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:project_error_tracking_setting, project: project)
create(:project_tracing_setting, project: project)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include(
operations_dashboard_users_with_projects_added: 2,
projects_prometheus_active: 2,
projects_with_error_tracking_enabled: 2,
projects_with_tracing_enabled: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include(
operations_dashboard_users_with_projects_added: 1,
projects_prometheus_active: 1,
projects_with_error_tracking_enabled: 1,
projects_with_tracing_enabled: 1
)
end
expect(described_class.usage_activity_by_stage_plan({})).to include(
assignee_lists: 2,
epics: 2,
label_lists: 2,
milestone_lists: 2,
projects_jira_active: 2,
projects_jira_dvcs_cloud_active: 2,
projects_jira_dvcs_server_active: 2
)
expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
assignee_lists: 1,
epics: 1,
label_lists: 1,
milestone_lists: 1,
projects_jira_active: 1,
projects_jira_dvcs_cloud_active: 1,
projects_jira_dvcs_server_active: 1
)
end
end
describe 'usage_activity_by_stage_release' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, :mirror, mirror_trigger_builds: true)
end
context 'for package' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, packages: [create(:package)] )
end
expect(described_class.uncached_data[:usage_activity_by_stage][:package]).to eq(
projects_with_packages: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:package]).to eq(
projects_with_packages: 1
)
end
expect(described_class.usage_activity_by_stage_release({})).to include(
projects_mirrored_with_pipelines_enabled: 2
)
expect(described_class.usage_activity_by_stage_release(described_class.last_28_days_time_period)).to include(
projects_mirrored_with_pipelines_enabled: 1
)
end
end
describe 'usage_activity_by_stage_secure' do
let_it_be(:user) { create(:user, group_view: :security_dashboard) }
let_it_be(:user2) { create(:user, group_view: :security_dashboard) }
let_it_be(:user3) { create(:user, group_view: :security_dashboard) }
before do
for_defined_days_back do
create(:ci_build, name: 'container_scanning', user: user)
create(:ci_build, name: 'dast', user: user)
create(:ci_build, name: 'dependency_scanning', user: user)
create(:ci_build, name: 'license_management', user: user)
create(:ci_build, name: 'sast', user: user)
create(:ci_build, name: 'secret_detection', user: user)
end
end
context 'for plan' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
board = create(:board, project: project)
create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
create(:list, board: board, label: create(:label, project: project), user: user)
create(:epic, author: user)
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user))
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user))
end
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include(
assignee_lists: 2,
epics: 2,
label_lists: 2,
milestone_lists: 2,
projects_jira_active: 2,
projects_jira_dvcs_cloud_active: 2,
projects_jira_dvcs_server_active: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include(
assignee_lists: 1,
epics: 1,
label_lists: 1,
milestone_lists: 1,
projects_jira_active: 1,
projects_jira_dvcs_cloud_active: 1,
projects_jira_dvcs_server_active: 1
)
end
it 'includes accurate usage_activity_by_stage data' do
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts pipelines that have security jobs' do
for_defined_days_back do
ds_build = create(:ci_build, name: 'retirejs', user: user, status: 'success')
ds_bundler_build = create(:ci_build, name: 'bundler-audit', user: user, commit_id: ds_build.pipeline.id, status: 'success')
secret_detection_build = create(:ci_build, name: 'secret', user: user, commit_id: ds_build.pipeline.id, status: 'success')
cs_build = create(:ci_build, name: 'klar', user: user, status: 'success')
sast_build = create(:ci_build, name: 'sast', user: user, status: 'success', retried: true)
create(:security_scan, build: ds_build, scan_type: 'dependency_scanning' )
create(:security_scan, build: ds_bundler_build, scan_type: 'dependency_scanning')
create(:security_scan, build: secret_detection_build, scan_type: 'secret_detection')
create(:security_scan, build: cs_build, scan_type: 'container_scanning')
create(:security_scan, build: sast_build, scan_type: 'sast')
end
context 'for release' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, :mirror, mirror_trigger_builds: true)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to include(
projects_mirrored_with_pipelines_enabled: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to include(
projects_mirrored_with_pipelines_enabled: 1
)
end
expect(described_class.usage_activity_by_stage_secure({})).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
user_unique_users_all_secure_scanners: 1
)
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 1,
container_scanning_pipeline: 1,
dast_pipeline: 0,
secret_detection_pipeline: 1,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts unique users correctly across multiple scanners' do
for_defined_days_back do
create(:ci_build, name: 'sast', user: user2)
create(:ci_build, name: 'dast', user: user2)
create(:ci_build, name: 'dast', user: user3)
end
context 'for secure' do
let_it_be(:user) { create(:user, group_view: :security_dashboard) }
let_it_be(:user2) { create(:user, group_view: :security_dashboard) }
let_it_be(:user3) { create(:user, group_view: :security_dashboard) }
before do
for_defined_days_back do
create(:ci_build, name: 'container_scanning', user: user)
create(:ci_build, name: 'dast', user: user)
create(:ci_build, name: 'dependency_scanning', user: user)
create(:ci_build, name: 'license_management', user: user)
create(:ci_build, name: 'sast', user: user)
create(:ci_build, name: 'secret_detection', user: user)
end
end
it 'includes accurate usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts pipelines that have security jobs' do
for_defined_days_back do
ds_build = create(:ci_build, name: 'retirejs', user: user, status: 'success')
ds_bundler_build = create(:ci_build, name: 'bundler-audit', user: user, commit_id: ds_build.pipeline.id, status: 'success')
secret_detection_build = create(:ci_build, name: 'secret', user: user, commit_id: ds_build.pipeline.id, status: 'success')
cs_build = create(:ci_build, name: 'klar', user: user, status: 'success')
sast_build = create(:ci_build, name: 'sast', user: user, status: 'success', retried: true)
create(:security_scan, build: ds_build, scan_type: 'dependency_scanning' )
create(:security_scan, build: ds_bundler_build, scan_type: 'dependency_scanning')
create(:security_scan, build: secret_detection_build, scan_type: 'secret_detection')
create(:security_scan, build: cs_build, scan_type: 'container_scanning')
create(:security_scan, build: sast_build, scan_type: 'sast')
end
expect(described_class.uncached_data[:usage_activity_by_stage][:secure]).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
user_unique_users_all_secure_scanners: 1
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 1,
container_scanning_pipeline: 1,
dast_pipeline: 0,
secret_detection_pipeline: 1,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts unique users correctly across multiple scanners' do
for_defined_days_back do
create(:ci_build, name: 'sast', user: user2)
create(:ci_build, name: 'dast', user: user2)
create(:ci_build, name: 'dast', user: user3)
end
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 3,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 2,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 3
)
end
it 'combines license_scanning into license_management' do
for_defined_days_back do
create(:ci_build, name: 'license_scanning', user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 2,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'has to resort to 0 for counting license scan' do
allow(Gitlab::Database::BatchCount).to receive(:batch_distinct_count).and_raise(ActiveRecord::StatementInvalid)
allow(::Ci::Build).to receive(:distinct_count_by).and_raise(ActiveRecord::StatementInvalid)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: -1,
user_dast_jobs: -1,
user_dependency_scanning_jobs: -1,
user_license_management_jobs: -1,
user_sast_jobs: -1,
user_secret_detection_jobs: -1,
sast_pipeline: -1,
dependency_scanning_pipeline: -1,
container_scanning_pipeline: -1,
dast_pipeline: -1,
secret_detection_pipeline: -1,
coverage_fuzzing_pipeline: -1,
user_unique_users_all_secure_scanners: -1
)
end
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 3,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 2,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 3
)
end
it 'combines license_scanning into license_management' do
for_defined_days_back do
create(:ci_build, name: 'license_scanning', user: user)
end
context 'for verify' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:github_service)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to include(
projects_reporting_ci_cd_back_to_github: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to include(
projects_reporting_ci_cd_back_to_github: 1
)
end
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 2,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'has to resort to 0 for counting license scan' do
allow(Gitlab::Database::BatchCount).to receive(:batch_distinct_count).and_raise(ActiveRecord::StatementInvalid)
allow(::Ci::Build).to receive(:distinct_count_by).and_raise(ActiveRecord::StatementInvalid)
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: -1,
user_dast_jobs: -1,
user_dependency_scanning_jobs: -1,
user_license_management_jobs: -1,
user_sast_jobs: -1,
user_secret_detection_jobs: -1,
sast_pipeline: -1,
dependency_scanning_pipeline: -1,
container_scanning_pipeline: -1,
dast_pipeline: -1,
secret_detection_pipeline: -1,
coverage_fuzzing_pipeline: -1,
user_unique_users_all_secure_scanners: -1
)
end
end
describe 'usage_activity_by_stage_verify' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:github_service)
end
expect(described_class.usage_activity_by_stage_verify({})).to include(
projects_reporting_ci_cd_back_to_github: 2
)
expect(described_class.usage_activity_by_stage_verify(described_class.last_28_days_time_period)).to include(
projects_reporting_ci_cd_back_to_github: 1
)
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