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

determine-qa-tests_spec.rb « scripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 043eb7f2dc98ccf631f8b323fe059546b4a14cce (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
require 'fast_spec_helper'

load File.expand_path('../../scripts/determine-qa-tests', __dir__)

RSpec.describe 'scripts/determine-qa-tests' do
  describe DetermineQATests do
    describe '.execute' do
      let(:qa_spec_files) do
        %w[qa/qa/specs/features/browser_ui/1_manage/test1.rb
           qa/qa/specs/features/browser_ui/1_manage/user/test2.rb]
      end

      let(:qa_spec_and_non_spec_files) do
        %w[qa/qa/specs/features/browser_ui/1_manage/test1.rb
           qa/qa/page/admin/menu.rb]
      end

      let(:non_qa_files) do
        %w[rubocop/code_reuse_helpers.rb
           app/components/diffs/overflow_warning_component.rb]
      end

      let(:non_qa_and_feature_flag_files) do
        %w[rubocop/code_reuse_helpers.rb
           app/components/diffs/overflow_warning_component.rb
           config/feature_flags/development/access_token_ajax.yml]
      end

      let(:qa_spec_and_non_qa_files) do
        %w[rubocop/code_reuse_helpers.rb
           app/components/diffs/overflow_warning_component.rb
           qa/qa/specs/features/browser_ui/1_manage/test1.rb]
      end

      let(:qa_non_spec_and_non_qa_files) do
        %w[rubocop/code_reuse_helpers.rb
           app/components/diffs/overflow_warning_component.rb
           qa/qa/page/admin/menu.rb]
      end

      shared_examples 'determine qa tests' do
        context 'when only qa spec files have changed' do
          it 'returns only the changed qa specs' do
            subject = described_class.new({ changed_files: qa_spec_files }.merge(labels))

            expect(subject.execute).to eql qa_spec_files.map { |path| path.delete_prefix("qa/") }.join(' ')
          end
        end

        context 'when qa spec and non spec files have changed' do
          it 'does not return any specs' do
            subject = described_class.new({ changed_files: qa_spec_and_non_spec_files }.merge(labels))
            expect(subject.execute).to be_nil
          end
        end

        context 'when non-qa and feature flag files have changed' do
          it 'does not return any specs' do
            subject = described_class.new({ changed_files: non_qa_and_feature_flag_files }.merge(labels))
            expect(subject.execute).to be_nil
          end
        end

        context 'when qa spec and non-qa files have changed' do
          it 'does not return any specs' do
            subject = described_class.new({ changed_files: qa_spec_and_non_qa_files }.merge(labels))
            expect(subject.execute).to be_nil
          end
        end

        context 'when qa non-spec and non-qa files have changed' do
          it 'does not return any specs' do
            subject = described_class.new({ changed_files: qa_non_spec_and_non_qa_files }.merge(labels))
            expect(subject.execute).to be_nil
          end
        end
      end

      context 'when a devops label is not specified' do
        let(:labels) { { mr_labels: ['type::feature'] } }

        it_behaves_like 'determine qa tests'

        context 'when only non-qa files have changed' do
          it 'does not return any specs' do
            subject = described_class.new({ changed_files: non_qa_files })
            expect(subject.execute).to be_nil
          end
        end
      end

      context 'when a devops label is specified' do
        let(:labels) { { mr_labels: %w[devops::manage type::feature] } }

        it_behaves_like 'determine qa tests'

        context 'when only non-qa files have changed' do
          it 'returns the specs for the devops label' do
            subject = described_class.new({ changed_files: non_qa_files }.merge(labels))
            allow(subject).to receive(:qa_spec_directories_for_devops_stage)
                                .and_return(['qa/qa/specs/features/browser_ui/1_manage/'])
            expect(subject.execute).to eql 'qa/specs/features/browser_ui/1_manage/'
          end
        end
      end
    end
  end
end