create_project_with_auto_devops_spec.rb 6.72 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'pathname'

5
module QA
Sanad Liaquat's avatar
Sanad Liaquat committed
6
  # Transient failure issue: https://gitlab.com/gitlab-org/quality/nightly/issues/68
ddavison's avatar
ddavison committed
7 8 9 10 11
  context 'Configure' do
    def login
      Runtime::Browser.visit(:gitlab, Page::Main::Login)
      Page::Main::Login.perform(&:sign_in_using_credentials)
    end
12

ddavison's avatar
ddavison committed
13
    describe 'Auto DevOps support', :orchestrated, :kubernetes, :quarantine do
14 15 16
      context 'when rbac is enabled' do
        before(:all) do
          login
17

18 19 20 21
          @project = Resource::Project.fabricate! do |p|
            p.name = Runtime::Env.auto_devops_project_name || 'project-with-autodevops'
            p.description = 'Project with Auto DevOps'
          end
22

23 24 25 26 27 28
          # Disable code_quality check in Auto DevOps pipeline as it takes
          # too long and times out the test
          Resource::CiVariable.fabricate! do |resource|
            resource.project = @project
            resource.key = 'CODE_QUALITY_DISABLED'
            resource.value = '1'
29
          end
30

31 32 33 34 35 36 37
          # Create Auto DevOps compatible repo
          Resource::Repository::ProjectPush.fabricate! do |push|
            push.project = @project
            push.directory = Pathname
              .new(__dir__)
              .join('../../../../../fixtures/auto_devops_rack')
            push.commit_message = 'Create Auto DevOps compatible rack application'
38 39
          end

40
          # Create and connect K8s cluster
41
          @cluster = Service::KubernetesCluster.new.create!
42 43 44 45 46 47 48
          Resource::KubernetesCluster.fabricate! do |cluster|
            cluster.project = @project
            cluster.cluster = @cluster
            cluster.install_helm_tiller = true
            cluster.install_ingress = true
            cluster.install_prometheus = true
            cluster.install_runner = true
49
          end
50
        end
51

52 53 54
        after(:all) do
          @cluster&.remove!
        end
55

56 57 58 59
        it 'runs auto devops' do
          @project.visit!
          Page::Project::Menu.perform(&:click_ci_cd_pipelines)
          Page::Project::Pipeline::Index.perform(&:go_to_latest_pipeline)
60

61 62 63 64 65
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('build')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 600)
66

67 68
            job.click_element(:pipeline_path)
          end
69

70 71 72 73 74
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('test')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 600)
75

76 77
            job.click_element(:pipeline_path)
          end
78

79 80 81 82 83
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('production')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 1200)
84

85
            job.click_element(:pipeline_path)
86
          end
87

88 89 90 91 92 93 94
          Page::Project::Menu.perform(&:click_operations_environments)
          Page::Project::Operations::Environments::Index.perform do |index|
            index.go_to_environment('production')
          end
          Page::Project::Operations::Environments::Show.perform do |show|
            show.view_deployment do
              expect(page).to have_content('Hello World!')
95
            end
96 97
          end
        end
98

99 100 101 102 103 104 105
        it 'user sets application secret variable and Auto DevOps passes it to container' do
          # Set an application secret CI variable (prefixed with K8S_SECRET_)
          Resource::CiVariable.fabricate! do |resource|
            resource.project = @project
            resource.key = 'K8S_SECRET_OPTIONAL_MESSAGE'
            resource.value = 'You can see this application secret'
          end
106

107 108 109 110 111 112 113 114 115 116
          # Our current Auto DevOps implementation won't update the production
          # app if we only update a CI variable with no code change.
          #
          # Workaround: push new code and use the resultant pipeline.
          Resource::Repository::ProjectPush.fabricate! do |push|
            push.project = @project
            push.commit_message = 'Force a Deployment change by pushing new code'
            push.file_name = 'new_file.txt'
            push.file_content = 'new file contents'
          end
117

118 119
          Page::Project::Menu.perform(&:click_ci_cd_pipelines)
          Page::Project::Pipeline::Index.perform(&:go_to_latest_pipeline)
120

121 122 123 124 125
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('build')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 600)
126

127 128
            job.click_element(:pipeline_path)
          end
129

130 131 132 133 134
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('test')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 600)
135

136 137
            job.click_element(:pipeline_path)
          end
138

139 140 141 142 143 144
          Page::Project::Pipeline::Show.perform do |pipeline|
            pipeline.go_to_job('production')
          end
          Page::Project::Job::Show.perform do |job|
            expect(job).to be_successful(timeout: 1200)
          end
145

146
          Page::Project::Menu.perform(&:click_operations_environments)
147

148 149 150
          Page::Project::Operations::Environments::Index.perform do |index|
            index.go_to_environment('production')
          end
151

152 153 154 155
          Page::Project::Operations::Environments::Show.perform do |show|
            show.view_deployment do
              expect(page).to have_content('Hello World!')
              expect(page).to have_content('You can see this application secret')
156 157
            end
          end
158
        end
159 160
      end
    end
ddavison's avatar
ddavison committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

    describe 'Auto DevOps', :smoke do
      it 'enables AutoDevOps by default' do
        login

        project = Resource::Project.fabricate! do |p|
          p.name = Runtime::Env.auto_devops_project_name || 'project-with-autodevops'
          p.description = 'Project with AutoDevOps'
        end

        project.visit!

        Page::Alert::AutoDevopsAlert.perform do |alert|
          expect(alert).to have_text(/.*The Auto DevOps pipeline has been enabled.*/)
        end

        # Create AutoDevOps repo
        Resource::Repository::ProjectPush.fabricate! do |push|
          push.project = project
          push.directory = Pathname
            .new(__dir__)
            .join('../../../../../fixtures/auto_devops_rack')
          push.commit_message = 'Create AutoDevOps compatible Project'
        end

        Page::Project::Menu.perform(&:click_ci_cd_pipelines)
        Page::Project::Pipeline::Index.perform(&:go_to_latest_pipeline)

        Page::Project::Pipeline::Show.perform do |pipeline|
          expect(pipeline).to have_tag('Auto DevOps')
        end
      end
    end
194 195
  end
end