diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-09-07 17:28:30 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-09-07 17:28:30 +0000 |
commit | f88659d005b1ad4d07755e0f296c22d424d3e1bd (patch) | |
tree | 09e8b4ff0d9cc90faa99a25f7fb622c50a6dced8 /spec | |
parent | 45510326d0ebec81539b855ec7789c8bb092eb67 (diff) | |
parent | 12ddc28f844fe63446a16ac908b09ed7b13c71ef (diff) | |
download | gitlab-ce-f88659d005b1ad4d07755e0f296c22d424d3e1bd.tar.gz |
Merge branch 'zj-auto-devops-table' into 'master'
Implement the implied CI/CD config for AutoDevOps
Closes #34777
See merge request !13923
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/project_auto_devops.rb | 7 | ||||
-rw-r--r-- | spec/features/projects/settings/pipelines_settings_spec.rb | 10 | ||||
-rw-r--r-- | spec/javascripts/commit/pipelines/pipelines_spec.js | 4 | ||||
-rw-r--r-- | spec/javascripts/pipelines/pipeline_url_spec.js | 27 | ||||
-rw-r--r-- | spec/javascripts/pipelines/pipelines_table_row_spec.js | 2 | ||||
-rw-r--r-- | spec/javascripts/pipelines/pipelines_table_spec.js | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 8 | ||||
-rw-r--r-- | spec/models/application_setting_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 114 | ||||
-rw-r--r-- | spec/models/project_auto_devops_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 130 | ||||
-rw-r--r-- | spec/serializers/pipeline_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 2 |
15 files changed, 350 insertions, 8 deletions
diff --git a/spec/factories/project_auto_devops.rb b/spec/factories/project_auto_devops.rb new file mode 100644 index 00000000000..8d124dc2381 --- /dev/null +++ b/spec/factories/project_auto_devops.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :project_auto_devops do + project + enabled true + domain "example.com" + end +end diff --git a/spec/features/projects/settings/pipelines_settings_spec.rb b/spec/features/projects/settings/pipelines_settings_spec.rb index 232d796a200..975d204e75e 100644 --- a/spec/features/projects/settings/pipelines_settings_spec.rb +++ b/spec/features/projects/settings/pipelines_settings_spec.rb @@ -41,5 +41,15 @@ feature "Pipelines settings" do checkbox = find_field('project_auto_cancel_pending_pipelines') expect(checkbox).to be_checked end + + scenario 'update auto devops settings' do + fill_in('project_auto_devops_attributes_domain', with: 'test.com') + page.choose('project_auto_devops_attributes_enabled_false') + click_on 'Save changes' + + expect(page.status_code).to eq(200) + expect(project.auto_devops).to be_present + expect(project.auto_devops).not_to be_enabled + end end end diff --git a/spec/javascripts/commit/pipelines/pipelines_spec.js b/spec/javascripts/commit/pipelines/pipelines_spec.js index a34cadec0ab..454f187ccbc 100644 --- a/spec/javascripts/commit/pipelines/pipelines_spec.js +++ b/spec/javascripts/commit/pipelines/pipelines_spec.js @@ -29,6 +29,7 @@ describe('Pipelines table in Commits and Merge requests', () => { propsData: { endpoint: 'endpoint', helpPagePath: 'foo', + autoDevopsHelpPath: 'foo', }, }).$mount(); }); @@ -64,6 +65,7 @@ describe('Pipelines table in Commits and Merge requests', () => { propsData: { endpoint: 'endpoint', helpPagePath: 'foo', + autoDevopsHelpPath: 'foo', }, }).$mount(); }); @@ -115,6 +117,7 @@ describe('Pipelines table in Commits and Merge requests', () => { propsData: { endpoint: 'endpoint', helpPagePath: 'foo', + autoDevopsHelpPath: 'foo', }, }).$mount(); element.appendChild(this.component.$el); @@ -136,6 +139,7 @@ describe('Pipelines table in Commits and Merge requests', () => { propsData: { endpoint: 'endpoint', helpPagePath: 'foo', + autoDevopsHelpPath: 'foo', }, }).$mount(); }); diff --git a/spec/javascripts/pipelines/pipeline_url_spec.js b/spec/javascripts/pipelines/pipeline_url_spec.js index 3c4b20a5f06..256fdbe743c 100644 --- a/spec/javascripts/pipelines/pipeline_url_spec.js +++ b/spec/javascripts/pipelines/pipeline_url_spec.js @@ -16,6 +16,7 @@ describe('Pipeline Url Component', () => { path: 'foo', flags: {}, }, + autoDevopsHelpPath: 'foo', }, }).$mount(); @@ -30,6 +31,7 @@ describe('Pipeline Url Component', () => { path: 'foo', flags: {}, }, + autoDevopsHelpPath: 'foo', }, }).$mount(); @@ -50,6 +52,7 @@ describe('Pipeline Url Component', () => { path: '/', }, }, + autoDevopsHelpPath: 'foo', }; const component = new PipelineUrlComponent({ @@ -73,6 +76,7 @@ describe('Pipeline Url Component', () => { path: 'foo', flags: {}, }, + autoDevopsHelpPath: 'foo', }, }).$mount(); @@ -91,6 +95,7 @@ describe('Pipeline Url Component', () => { stuck: true, }, }, + autoDevopsHelpPath: 'foo', }, }).$mount(); @@ -98,4 +103,26 @@ describe('Pipeline Url Component', () => { expect(component.$el.querySelector('.js-pipeline-url-yaml').textContent).toContain('yaml invalid'); expect(component.$el.querySelector('.js-pipeline-url-stuck').textContent).toContain('stuck'); }); + + it('should render a badge for autodevops', () => { + const component = new PipelineUrlComponent({ + propsData: { + pipeline: { + id: 1, + path: 'foo', + flags: { + latest: true, + yaml_errors: true, + stuck: true, + auto_devops: true, + }, + }, + autoDevopsHelpPath: 'foo', + }, + }).$mount(); + + expect( + component.$el.querySelector('.js-pipeline-url-autodevops').textContent.trim(), + ).toEqual('Auto DevOps'); + }); }); diff --git a/spec/javascripts/pipelines/pipelines_table_row_spec.js b/spec/javascripts/pipelines/pipelines_table_row_spec.js index 7ce39dca112..d7456a48bc1 100644 --- a/spec/javascripts/pipelines/pipelines_table_row_spec.js +++ b/spec/javascripts/pipelines/pipelines_table_row_spec.js @@ -9,7 +9,7 @@ describe('Pipelines Table Row', () => { el: document.querySelector('.test-dom-element'), propsData: { pipeline, - service: {}, + autoDevopsHelpPath: 'foo', }, }).$mount(); }; diff --git a/spec/javascripts/pipelines/pipelines_table_spec.js b/spec/javascripts/pipelines/pipelines_table_spec.js index 3afe89c8db4..4f5eb42eb35 100644 --- a/spec/javascripts/pipelines/pipelines_table_spec.js +++ b/spec/javascripts/pipelines/pipelines_table_spec.js @@ -22,6 +22,7 @@ describe('Pipelines Table', () => { component = new PipelinesTableComponent({ propsData: { pipelines: [], + autoDevopsHelpPath: 'foo', }, }).$mount(); }); @@ -47,6 +48,7 @@ describe('Pipelines Table', () => { const component = new PipelinesTableComponent({ propsData: { pipelines: [], + autoDevopsHelpPath: 'foo', }, }).$mount(); expect(component.$el.querySelectorAll('.commit.gl-responsive-table-row').length).toEqual(0); @@ -58,6 +60,7 @@ describe('Pipelines Table', () => { const component = new PipelinesTableComponent({ propsData: { pipelines: [pipeline], + autoDevopsHelpPath: 'foo', }, }).$mount(); diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index beed4e77e8b..3fb8edeb701 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -256,6 +256,7 @@ project: - environments - deployments - project_feature +- auto_devops - pages_domains - authorized_users - project_authorizations diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 1613b968bb6..899d17d97c2 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -223,6 +223,7 @@ Ci::Pipeline: - lock_version - auto_canceled_by_id - pipeline_schedule_id +- config_source - protected Ci::Stage: - id @@ -466,3 +467,10 @@ Timelog: - user_id - created_at - updated_at +ProjectAutoDevops: +- id +- enabled +- domain +- project_id +- created_at +- updated_at diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index f921545668d..c7a9eabdf06 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -5,6 +5,7 @@ describe ApplicationSetting do it { expect(setting).to be_valid } it { expect(setting.uuid).to be_present } + it { expect(setting).to have_db_column(:auto_devops_enabled) } describe 'validations' do let(:http) { 'http://example.com' } diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 08d22f166e4..c2c9f1c12d1 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1688,6 +1688,30 @@ describe Ci::Build do { key: 'secret', value: 'value', public: false }]) end end + + context 'when using auto devops' do + context 'and is enabled' do + before do + project.create_auto_devops!(enabled: true, domain: 'example.com') + end + + it "includes AUTO_DEVOPS_DOMAIN" do + is_expected.to include( + { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }) + end + end + + context 'and is disabled' do + before do + project.create_auto_devops!(enabled: false, domain: 'example.com') + end + + it "includes AUTO_DEVOPS_DOMAIN" do + is_expected.not_to include( + { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }) + end + end + end end describe 'state transition: any => [:pending]' do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 84656ffe0b9..95da97b7bc5 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -799,14 +799,118 @@ describe Ci::Pipeline, :mailer do end end + describe '#set_config_source' do + context 'on object initialisation' do + context 'when pipelines does not contain needed data' do + let(:pipeline) do + Ci::Pipeline.new + end + + it 'defines source to be unknown' do + expect(pipeline).to be_unknown_source + end + end + + context 'when pipeline contains all needed data' do + let(:pipeline) do + Ci::Pipeline.new( + project: project, + sha: '1234', + ref: 'master', + source: :push) + end + + context 'when the repository has a config file' do + before do + allow(project.repository).to receive(:gitlab_ci_yml_for) + .and_return('config') + end + + it 'defines source to be from repository' do + expect(pipeline).to be_repository_source + end + + context 'when loading an object' do + let(:new_pipeline) { Ci::Pipeline.find(pipeline.id) } + + it 'does not redefine the source' do + # force to overwrite the source + pipeline.unknown_source! + + expect(new_pipeline).to be_unknown_source + end + end + end + + context 'when the repository does not have a config file' do + let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content } + + context 'auto devops enabled' do + before do + stub_application_setting(auto_devops_enabled: true) + allow(project).to receive(:ci_config_path) { 'custom' } + end + + it 'defines source to be auto devops' do + subject + + expect(pipeline).to be_auto_devops_source + end + end + end + end + end + end + describe '#ci_yaml_file' do - it 'reports error if the file is not found' do - allow(pipeline.project).to receive(:ci_config_path) { 'custom' } + let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content } + + context 'the source is unknown' do + before do + pipeline.unknown_source! + end + + it 'returns the configuration if found' do + allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for) + .and_return('config') + + expect(pipeline.ci_yaml_file).to be_a(String) + expect(pipeline.ci_yaml_file).not_to eq(implied_yml) + expect(pipeline.yaml_errors).to be_nil + end + + it 'sets yaml errors if not found' do + expect(pipeline.ci_yaml_file).to be_nil + expect(pipeline.yaml_errors) + .to start_with('Failed to load CI/CD config file') + end + end + + context 'the source is the repository' do + before do + pipeline.repository_source! + end - pipeline.ci_yaml_file + it 'returns the configuration if found' do + allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for) + .and_return('config') - expect(pipeline.yaml_errors) - .to eq('Failed to load CI/CD config file at custom') + expect(pipeline.ci_yaml_file).to be_a(String) + expect(pipeline.ci_yaml_file).not_to eq(implied_yml) + expect(pipeline.yaml_errors).to be_nil + end + end + + context 'when the source is auto_devops_source' do + before do + stub_application_setting(auto_devops_enabled: true) + pipeline.auto_devops_source! + end + + it 'finds the implied config' do + expect(pipeline.ci_yaml_file).to eq(implied_yml) + expect(pipeline.yaml_errors).to be_nil + end end end diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb new file mode 100644 index 00000000000..ca13af4d73e --- /dev/null +++ b/spec/models/project_auto_devops_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe ProjectAutoDevops do + set(:project) { build(:project) } + + it { is_expected.to belong_to(:project) } + + it { is_expected.to respond_to(:created_at) } + it { is_expected.to respond_to(:updated_at) } + + describe 'variables' do + let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) } + + context 'when domain is defined' do + let(:domain) { 'example.com' } + + it 'returns AUTO_DEVOPS_DOMAIN' do + expect(auto_devops.variables).to include( + { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }) + end + end + end +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1f7c6a82b91..75c99b62150 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -53,6 +53,7 @@ describe Project do it { is_expected.to have_one(:import_data).class_name('ProjectImportData') } it { is_expected.to have_one(:last_event).class_name('Event') } it { is_expected.to have_one(:forked_from_project).through(:forked_project_link) } + it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') } it { is_expected.to have_many(:commit_statuses) } it { is_expected.to have_many(:pipelines) } it { is_expected.to have_many(:builds) } @@ -2508,4 +2509,133 @@ describe Project do end end end + + describe '#has_ci?' do + set(:project) { create(:project) } + let(:repository) { double } + + before do + expect(project).to receive(:repository) { repository } + end + + context 'when has .gitlab-ci.yml' do + before do + expect(repository).to receive(:gitlab_ci_yml) { 'content' } + end + + it "CI is available" do + expect(project).to have_ci + end + end + + context 'when there is no .gitlab-ci.yml' do + before do + expect(repository).to receive(:gitlab_ci_yml) { nil } + end + + it "CI is not available" do + expect(project).not_to have_ci + end + + context 'when auto devops is enabled' do + before do + stub_application_setting(auto_devops_enabled: true) + end + + it "CI is available" do + expect(project).to have_ci + end + end + end + end + + describe '#auto_devops_enabled?' do + set(:project) { create(:project) } + + subject { project.auto_devops_enabled? } + + context 'when enabled in settings' do + before do + stub_application_setting(auto_devops_enabled: true) + end + + it 'auto devops is implicitly enabled' do + expect(project.auto_devops).to be_nil + expect(project).to be_auto_devops_enabled + end + + context 'when explicitly enabled' do + before do + create(:project_auto_devops, project: project) + end + + it "auto devops is enabled" do + expect(project).to be_auto_devops_enabled + end + end + + context 'when explicitly disabled' do + before do + create(:project_auto_devops, project: project, enabled: false) + end + + it "auto devops is disabled" do + expect(project).not_to be_auto_devops_enabled + end + end + end + + context 'when disabled in settings' do + before do + stub_application_setting(auto_devops_enabled: false) + end + + it 'auto devops is implicitly disabled' do + expect(project.auto_devops).to be_nil + expect(project).not_to be_auto_devops_enabled + end + + context 'when explicitly enabled' do + before do + create(:project_auto_devops, project: project) + end + + it "auto devops is enabled" do + expect(project).to be_auto_devops_enabled + end + end + end + end + + context '#auto_devops_variables' do + set(:project) { create(:project) } + + subject { project.auto_devops_variables } + + context 'when enabled in settings' do + before do + stub_application_setting(auto_devops_enabled: true) + end + + context 'when domain is empty' do + before do + create(:project_auto_devops, project: project, domain: nil) + end + + it 'variables are empty' do + is_expected.to be_empty + end + end + + context 'when domain is configured' do + before do + create(:project_auto_devops, project: project, domain: 'example.com') + end + + it "variables are not empty" do + is_expected.not_to be_empty + end + end + end + end end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index 881f2b6bfd8..f8df461bc81 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -36,7 +36,7 @@ describe PipelineEntity do it 'contains flags' do expect(subject).to include :flags expect(subject[:flags]) - .to include :latest, :stuck, + .to include :latest, :stuck, :auto_devops, :yaml_errors, :retryable, :cancelable end end diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 009d67a3fbe..4c2ff08039c 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Ci::CreatePipelineService do - let(:project) { create(:project, :repository) } + set(:project) { create(:project, :repository) } let(:user) { create(:admin) } let(:ref_name) { 'refs/heads/master' } |