summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/4_verify/pipeline/trigger_matrix_spec.rb
blob: 94ac857f0fea0a531b123f248b8f266606353c14 (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
110
# frozen_string_literal: true

module QA
  RSpec.describe 'Verify', :runner do
    describe 'Trigger matrix' do
      let(:executor) { "qa-runner-#{Faker::Alphanumeric.alphanumeric(8)}" }

      let(:project) do
        Resource::Project.fabricate_via_api! do |project|
          project.name = 'project-with-pipeline'
        end
      end

      let!(:runner) do
        Resource::Runner.fabricate! do |runner|
          runner.project = project
          runner.name = executor
          runner.tags = [executor]
        end
      end

      before do
        Flow::Login.sign_in
        add_ci_files
        project.visit!
        Flow::Pipeline.visit_latest_pipeline(pipeline_condition: 'succeeded')
      end

      after do
        runner.remove_via_api!
        project.remove_via_api!
      end

      it 'creates 2 trigger jobs and passes corresponding matrix variables', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/348000' do
        Page::Project::Pipeline::Show.perform do |parent_pipeline|
          trigger_title1 = 'deploy: [ovh, monitoring]'
          trigger_title2 = 'deploy: [ovh, app]'

          aggregate_failures 'Creates two child pipelines' do
            expect(parent_pipeline).to have_child_pipeline(title: trigger_title1)
            expect(parent_pipeline).to have_child_pipeline(title: trigger_title2)
          end

          # Only check output of one of the child pipelines, should be sufficient
          parent_pipeline.expand_child_pipeline(title: trigger_title1)
          parent_pipeline.click_job('test_vars')
        end

        Page::Project::Job::Show.perform do |show|
          Support::Waiter.wait_until { show.successful? }

          aggregate_failures 'Job output has the correct variables' do
            expect(show.output).to have_content('ovh')
            expect(show.output).to have_content('monitoring')
          end
        end
      end

      private

      def add_ci_files
        Resource::Repository::Commit.fabricate_via_api! do |commit|
          commit.project = project
          commit.commit_message = 'Add parent and child pipelines CI files.'
          commit.add_files(
            [
              child_ci_file,
              parent_ci_file
            ]
          )
        end
      end

      def parent_ci_file
        {
          file_path: '.gitlab-ci.yml',
          content: <<~YAML
            test:
              stage: test
              script: echo test
              tags: [#{executor}]

            deploy:
              stage: deploy
              trigger:
                include: child.yml
              parallel:
                matrix:
                  - PROVIDER: ovh
                    STACK: [monitoring, app]

          YAML
        }
      end

      def child_ci_file
        {
          file_path: 'child.yml',
          content: <<~YAML
            test_vars:
              script:
                - echo $PROVIDER
                - echo $STACK
              tags: [#{executor}]
          YAML
        }
      end
    end
  end
end