summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/4_verify/ci_variable/raw_variables_defined_in_yaml_spec.rb
blob: a4849d471835feabe940bb8a82cfeba31a74b2c9 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# frozen_string_literal: true

module QA
  RSpec.describe 'Verify', :runner do
    describe 'Pipeline with raw variables in YAML', product_group: :pipeline_authoring, feature_flag: {
      name: 'ci_raw_variables_in_yaml_config',
      scope: :project
    } do
      let(:executor) { "qa-runner-#{Time.now.to_i}" }
      let(:pipeline_job_name) { 'rspec' }

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

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

      let(:commit_ci_file) do
        Resource::Repository::Commit.fabricate_via_api! do |commit|
          commit.project = project
          commit.commit_message = 'Add .gitlab-ci.yml'
          commit.add_files(
            [
              {
                file_path: '.gitlab-ci.yml',
                content: <<~YAML
                  variables:
                    VAR7:
                      value: "value 7 $CI_PIPELINE_ID"
                      expand: false
                    VAR8:
                      value: "value 8 $CI_PIPELINE_ID"
                      expand: false

                  #{pipeline_job_name}:
                    tags:
                      - #{executor}
                    script:
                      - echo "VAR1 is $VAR1"
                      - echo "VAR2 is $VAR2"
                      - echo "VAR3 is $VAR3"
                      - echo "VAR4 is $VAR4"
                      - echo "VAR5 is $VAR5"
                      - echo "VAR6 is $VAR6"
                      - echo "VAR7 is $VAR7"
                      - echo "VAR8 is $VAR8"
                    variables:
                      VAR1: "JOBID-$CI_JOB_ID"
                      VAR2: "PIPELINEID-$CI_PIPELINE_ID and $VAR1"
                      VAR3:
                        value: "PIPELINEID-$CI_PIPELINE_ID and $VAR1"
                        expand: false
                      VAR4:
                        value: "JOBID-$CI_JOB_ID"
                        expand: false
                      VAR5: "PIPELINEID-$CI_PIPELINE_ID and $VAR4"
                      VAR6:
                        value: "PIPELINEID-$CI_PIPELINE_ID and $VAR4"
                        expand: false
                      VAR7: "overridden value 7 $CI_PIPELINE_ID"
                YAML
              }
            ]
          )
        end
      end

      let(:pipeline_id) { project.pipelines.first[:id] }
      let(:job_id) { project.job_by_name(pipeline_job_name)[:id] }

      def before_do
        # TODO: Switch to use `let!` and remove this line when removing FF
        commit_ci_file

        Flow::Login.sign_in
        project.visit!
        Flow::Pipeline.visit_latest_pipeline(status: 'passed')
        Page::Project::Pipeline::Show.perform do |show|
          show.click_job(pipeline_job_name)
        end
      end

      after do
        runner&.remove_via_api!
      end

      context 'when FF is on', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/381487' do
        before do
          Runtime::Feature.enable(:ci_raw_variables_in_yaml_config, project: project)
          sleep 60

          before_do
        end

        it 'expands variables according to expand: true/false', :aggregate_failures do
          Page::Project::Job::Show.perform do |show|
            expect(show.output).to have_content("VAR1 is JOBID-#{job_id}")
            expect(show.output).to have_content("VAR2 is PIPELINEID-#{pipeline_id} and JOBID-#{job_id}")
            expect(show.output).to have_content("VAR3 is PIPELINEID-$CI_PIPELINE_ID and $VAR1")
            expect(show.output).to have_content("VAR4 is JOBID-$CI_JOB_ID")
            expect(show.output).to have_content("VAR5 is PIPELINEID-#{pipeline_id} and JOBID-$CI_JOB_ID")
            expect(show.output).to have_content("VAR6 is PIPELINEID-$CI_PIPELINE_ID and $VAR4")
            expect(show.output).to have_content("VAR7 is overridden value 7 #{pipeline_id}")
            expect(show.output).to have_content("VAR8 is value 8 $CI_PIPELINE_ID")
          end
        end
      end

      # TODO: Remove this context when FF :ci_raw_variables_in_yaml_config is removed
      # Also archive testcase and close related issue
      context 'when FF is off',
        testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/381486',
        quarantine: {
          issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/381806',
          only: { pipeline: %w[staging staging-canary staging-ref] },
          type: :waiting_on
        } do
        before do
          Runtime::Feature.disable(:ci_raw_variables_in_yaml_config, project: project)
          sleep 60

          before_do
        end

        it 'expands all variables', :aggregate_failures do
          Page::Project::Job::Show.perform do |show|
            expect(show.output).to have_content("VAR1 is JOBID-#{job_id}")
            expect(show.output).to have_content("VAR2 is PIPELINEID-#{pipeline_id} and JOBID-#{job_id}")
            expect(show.output).to have_content("VAR3 is PIPELINEID-#{pipeline_id} and JOBID-#{job_id}")
            expect(show.output).to have_content("VAR4 is JOBID-#{job_id}")
            expect(show.output).to have_content("VAR5 is PIPELINEID-#{pipeline_id} and JOBID-#{job_id}")
            expect(show.output).to have_content("VAR6 is PIPELINEID-#{pipeline_id} and JOBID-#{job_id}")
            expect(show.output).to have_content("VAR7 is overridden value 7 #{pipeline_id}")
            expect(show.output).to have_content("VAR8 is value 8 #{pipeline_id}")
          end
        end
      end
    end
  end
end