File: ci_templates_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (85 lines) | stat: -rw-r--r-- 3,011 bytes parent folder | download
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
79
80
81
82
83
84
85
# frozen_string_literal: true

require 'gitlab/dangerfiles/spec_helper'
require 'fast_spec_helper'
require 'rspec-parameterized'

require_relative '../../../danger/plugins/ci_templates'

RSpec.describe Tooling::Danger::CiTemplates, feature_category: :tooling do
  include_context 'with dangerfile'
  subject(:ci_templates) { fake_danger.new(helper: fake_helper) }

  let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }

  describe '#check!' do
    context 'when checking for mr labels' do
      context 'when mr does not have a ci::templates label' do
        it 'does not add the danger message, markdown and warning' do
          expect(ci_templates).not_to receive(:message)
          expect(ci_templates).not_to receive(:markdown)
          expect(ci_templates).not_to receive(:warn)

          ci_templates.check!
        end
      end

      context 'when mr has a ci::templates label' do
        before do
          allow(fake_helper).to receive(:mr_labels).and_return(['ci::templates'])
          allow(ci_templates).to receive(:message)
          allow(ci_templates).to receive(:markdown)
        end

        it 'adds the danger message and markdown' do
          expect(ci_templates).to receive(:message)
          expect(ci_templates).to receive(:markdown)

          ci_templates.check!
        end
      end
    end

    context 'when checking for changes to ci templates' do
      context 'when there are no updated ci templates' do
        it 'does not add the danger message, markdown and warning' do
          expect(ci_templates).not_to receive(:message)
          expect(ci_templates).not_to receive(:markdown)
          expect(ci_templates).not_to receive(:warn)

          ci_templates.check!
        end
      end

      context 'when there are updates to the ci templates' do
        let(:modified_files) { %w[lib/gitlab/ci/templates/ci_template.rb] }
        let(:fake_changes) { instance_double(Gitlab::Dangerfiles::Changes, files: modified_files) }

        before do
          allow(fake_changes).to receive(:by_category).with(:ci_template).and_return(fake_changes)
          allow(fake_helper).to receive(:changes).and_return(fake_changes)
          allow(ci_templates).to receive(:message)
          allow(ci_templates).to receive(:markdown)
          allow(fake_helper).to receive(:markdown_list).and_return(modified_files)
        end

        it 'adds the danger message, markdown and warning' do
          expect(ci_templates).to receive(:message)
          expect(ci_templates).to receive(:markdown)
          expect(ci_templates).to receive(:warn)

          ci_templates.check!
        end

        context 'when there are files returned by markdown_list' do
          it 'returns markdown message' do
            expect(fake_helper).to receive(:markdown_list).with(modified_files)
            expect(ci_templates).to receive(:markdown).with(/#{modified_files}/)

            ci_templates.check!
          end
        end
      end
    end
  end
end