Welcome to mirror list, hosted at ThFree Co, Russian Federation.

schedule_fixing_security_scan_statuses_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f43f58d3be222a6407a4edee54764fe7a1045d31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe ScheduleFixingSecurityScanStatuses,
  :suppress_gitlab_schemas_validate_connection, :suppress_partitioning_routing_analyzer,
  feature_category: :vulnerability_management do
  let!(:namespaces) { table(:namespaces) }
  let!(:projects) { table(:projects) }
  let!(:pipelines) { table(:ci_pipelines, database: :ci) }
  let!(:builds) { table(:ci_builds, database: :ci) { |model| model.primary_key = :id } }
  let!(:security_scans) { table(:security_scans) }

  let!(:namespace) { namespaces.create!(name: "foo", path: "bar") }
  let!(:project) { projects.create!(namespace_id: namespace.id, project_namespace_id: namespace.id) }
  let!(:pipeline) do
    pipelines.create!(project_id: project.id, ref: 'master', sha: 'adf43c3a', status: 'success', partition_id: 100)
  end

  let!(:ci_build) { builds.create!(commit_id: pipeline.id, retried: false, type: 'Ci::Build', partition_id: 100) }

  let!(:security_scan_1) { security_scans.create!(build_id: ci_build.id, scan_type: 1, created_at: 91.days.ago) }
  let!(:security_scan_2) { security_scans.create!(build_id: ci_build.id, scan_type: 2) }

  let(:com?) { false }
  let(:dev_or_test_env?) { false }
  let(:migration) { described_class::MIGRATION }

  before do
    allow(::Gitlab).to receive(:com?).and_return(com?)
    allow(::Gitlab).to receive(:dev_or_test_env?).and_return(dev_or_test_env?)

    migrate!
  end

  describe '#up' do
    shared_examples_for 'scheduler for fixing the security scans status' do
      it 'schedules background job' do
        expect(migration).to have_scheduled_batched_migration(
          table_name: :security_scans,
          column_name: :id,
          interval: 2.minutes,
          batch_size: 10_000,
          max_batch_size: 50_000,
          sub_batch_size: 100,
          batch_min_value: security_scan_2.id
        )
      end
    end

    context 'when the migration does not run on GitLab.com or development environment' do
      it 'does not schedule the migration' do
        expect('FixSecurityScanStatuses').not_to have_scheduled_batched_migration
      end
    end

    context 'when the migration runs on GitLab.com' do
      let(:com?) { true }

      it_behaves_like 'scheduler for fixing the security scans status'
    end

    context 'when the migration runs on dev environment' do
      let(:dev_or_test_env?) { true }

      it_behaves_like 'scheduler for fixing the security scans status'
    end
  end

  describe '#down' do
    it 'deletes all batched migration records' do
      schema_migrate_down!

      expect(migration).not_to have_scheduled_batched_migration
    end
  end
end