diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-26 03:11:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-26 03:11:20 +0300 |
commit | 2d099cf5e6bc10b70fe79fdaf9cd1c2f51173687 (patch) | |
tree | 42f6a1fcef7a72945d7292a87a15b4d7adbe0375 /spec | |
parent | a53c0ca02cc35bd485af15b46ace3c9c2ac48c64 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/explore/projects_controller_spec.rb | 17 | ||||
-rw-r--r-- | spec/factories/design_management/versions.rb | 5 | ||||
-rw-r--r-- | spec/factories/projects.rb | 2 | ||||
-rw-r--r-- | spec/factories_spec.rb | 1 | ||||
-rw-r--r-- | spec/finders/repositories/previous_tag_finder_spec.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb | 372 | ||||
-rw-r--r-- | spec/support/helpers/design_management_test_helpers.rb | 2 |
7 files changed, 213 insertions, 193 deletions
diff --git a/spec/controllers/explore/projects_controller_spec.rb b/spec/controllers/explore/projects_controller_spec.rb index cfbd129388d..a2b62aa49d2 100644 --- a/spec/controllers/explore/projects_controller_spec.rb +++ b/spec/controllers/explore/projects_controller_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' RSpec.describe Explore::ProjectsController do shared_examples 'explore projects' do + let(:expected_default_sort) { 'latest_activity_desc' } + describe 'GET #index.json' do render_views @@ -12,6 +14,11 @@ RSpec.describe Explore::ProjectsController do end it { is_expected.to respond_with(:success) } + + it 'sets a default sort parameter' do + expect(controller.params[:sort]).to eq(expected_default_sort) + expect(assigns[:sort]).to eq(expected_default_sort) + end end describe 'GET #trending.json' do @@ -22,6 +29,11 @@ RSpec.describe Explore::ProjectsController do end it { is_expected.to respond_with(:success) } + + it 'sets a default sort parameter' do + expect(controller.params[:sort]).to eq(expected_default_sort) + expect(assigns[:sort]).to eq(expected_default_sort) + end end describe 'GET #starred.json' do @@ -32,6 +44,11 @@ RSpec.describe Explore::ProjectsController do end it { is_expected.to respond_with(:success) } + + it 'sets a default sort parameter' do + expect(controller.params[:sort]).to eq(expected_default_sort) + expect(assigns[:sort]).to eq(expected_default_sort) + end end describe 'GET #trending' do diff --git a/spec/factories/design_management/versions.rb b/spec/factories/design_management/versions.rb index 0233a3b567d..247a385bd0e 100644 --- a/spec/factories/design_management/versions.rb +++ b/spec/factories/design_management/versions.rb @@ -13,11 +13,6 @@ FactoryBot.define do deleted_designs { [] } end - # Warning: this will intentionally result in an invalid version! - trait :empty do - designs_count { 0 } - end - trait :importing do issue { nil } diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index e8e0362fc62..80392a2fece 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -194,7 +194,7 @@ FactoryBot.define do filename, content, message: "Automatically created file #{filename}", - branch_name: 'master' + branch_name: project.default_branch_or_master ) end end diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb index a297b0b72f6..4081ef7b2ce 100644 --- a/spec/factories_spec.rb +++ b/spec/factories_spec.rb @@ -13,7 +13,6 @@ RSpec.describe 'factories' do [:ci_job_artifact, :raw], [:ci_job_artifact, :gzip], [:ci_job_artifact, :correct_checksum], - [:design_version, :empty], [:environment, :non_playable], [:go_module_commit, :files], [:go_module_commit, :package], diff --git a/spec/finders/repositories/previous_tag_finder_spec.rb b/spec/finders/repositories/previous_tag_finder_spec.rb index e07eab7ec5f..b332dd158d1 100644 --- a/spec/finders/repositories/previous_tag_finder_spec.rb +++ b/spec/finders/repositories/previous_tag_finder_spec.rb @@ -13,18 +13,19 @@ RSpec.describe Repositories::PreviousTagFinder do tag2 = double(:tag2, name: 'v1.1.0') tag3 = double(:tag3, name: 'v2.0.0') tag4 = double(:tag4, name: '0.9.0') - tag5 = double(:tag4, name: 'v0.8.0-pre1') + tag5 = double(:tag5, name: 'v0.8.0-pre1') + tag6 = double(:tag6, name: 'v0.7.0') allow(project.repository) .to receive(:tags) - .and_return([tag1, tag3, tag2, tag4, tag5]) + .and_return([tag1, tag3, tag2, tag4, tag5, tag6]) expect(finder.execute('2.1.0')).to eq(tag3) expect(finder.execute('2.0.0')).to eq(tag2) expect(finder.execute('1.5.0')).to eq(tag2) expect(finder.execute('1.0.1')).to eq(tag1) expect(finder.execute('1.0.0')).to eq(tag4) - expect(finder.execute('0.9.0')).to eq(tag5) + expect(finder.execute('0.9.0')).to eq(tag6) end end diff --git a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb index f9d6fe24e70..6dfcecb853a 100644 --- a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb +++ b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb @@ -3,252 +3,260 @@ require 'spec_helper' RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do + using RSpec::Parameterized::TableSyntax + subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') } - describe 'the created pipeline' do - let(:default_branch) { 'master' } - let(:pipeline_branch) { default_branch } - let(:project) { create(:project, :auto_devops, :custom_repo, files: { 'README.md' => '' }) } - let(:user) { project.owner } - let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_branch ) } - let(:pipeline) { service.execute!(:push) } - let(:build_names) { pipeline.builds.pluck(:name) } - - before do - stub_ci_pipeline_yaml_file(template.content) - allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true) - allow(project).to receive(:default_branch).and_return(default_branch) - end + where(:default_branch) do + %w[master main] + end - shared_examples 'no Kubernetes deployment job' do - it 'does not create any Kubernetes deployment-related builds' do - expect(build_names).not_to include('production') - expect(build_names).not_to include('production_manual') - expect(build_names).not_to include('staging') - expect(build_names).not_to include('canary') - expect(build_names).not_to include('review') - expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) - end - end + with_them do + describe 'the created pipeline' do + let(:pipeline_branch) { default_branch } + let(:project) { create(:project, :auto_devops, :custom_repo, files: { 'README.md' => '' }) } + let(:user) { project.owner } + let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_branch ) } + let(:pipeline) { service.execute!(:push) } + let(:build_names) { pipeline.builds.pluck(:name) } - it 'creates a build and a test job' do - expect(build_names).to include('build', 'test') - end + before do + stub_application_setting(default_branch_name: default_branch) + stub_ci_pipeline_yaml_file(template.content) + allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true) + end - context 'when the project is set for deployment to AWS' do - let(:platform_value) { 'ECS' } - let(:review_prod_build_names) { build_names.select {|n| n.include?('review') || n.include?('production')} } + shared_examples 'no Kubernetes deployment job' do + it 'does not create any Kubernetes deployment-related builds' do + expect(build_names).not_to include('production') + expect(build_names).not_to include('production_manual') + expect(build_names).not_to include('staging') + expect(build_names).not_to include('canary') + expect(build_names).not_to include('review') + expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) + end + end - before do - create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value) + it 'creates a build and a test job' do + expect(build_names).to include('build', 'test') end - shared_examples 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do |job_name| - context 'when AUTO_DEVOPS_PLATFORM_TARGET is nil' do - let(:platform_value) { nil } + context 'when the project is set for deployment to AWS' do + let(:platform_value) { 'ECS' } + let(:review_prod_build_names) { build_names.select {|n| n.include?('review') || n.include?('production')} } - it 'does not trigger the job' do - expect(build_names).not_to include(job_name) - end + before do + create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value) end - context 'when AUTO_DEVOPS_PLATFORM_TARGET is empty' do - let(:platform_value) { '' } + shared_examples 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do |job_name| + context 'when AUTO_DEVOPS_PLATFORM_TARGET is nil' do + let(:platform_value) { nil } - it 'does not trigger the job' do - expect(build_names).not_to include(job_name) + it 'does not trigger the job' do + expect(build_names).not_to include(job_name) + end end - end - end - it_behaves_like 'no Kubernetes deployment job' + context 'when AUTO_DEVOPS_PLATFORM_TARGET is empty' do + let(:platform_value) { '' } - it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do - let(:job_name) { 'production_ecs' } - end + it 'does not trigger the job' do + expect(build_names).not_to include(job_name) + end + end + end - it 'creates an ECS deployment job for production only' do - expect(review_prod_build_names).to contain_exactly('production_ecs') - end + it_behaves_like 'no Kubernetes deployment job' - context 'with FARGATE as a launch type' do - let(:platform_value) { 'FARGATE' } + it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do + let(:job_name) { 'production_ecs' } + end - it 'creates a FARGATE deployment job for production only' do - expect(review_prod_build_names).to contain_exactly('production_fargate') + it 'creates an ECS deployment job for production only' do + expect(review_prod_build_names).to contain_exactly('production_ecs') end - end - context 'and we are not on the default branch' do - let(:platform_value) { 'ECS' } - let(:pipeline_branch) { 'patch-1' } + context 'with FARGATE as a launch type' do + let(:platform_value) { 'FARGATE' } - before do - project.repository.create_branch(pipeline_branch) + it 'creates a FARGATE deployment job for production only' do + expect(review_prod_build_names).to contain_exactly('production_fargate') + end end - %w(review_ecs review_fargate).each do |job| - it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do - let(:job_name) { job } + context 'and we are not on the default branch' do + let(:platform_value) { 'ECS' } + let(:pipeline_branch) { 'patch-1' } + + before do + project.repository.create_branch(pipeline_branch, default_branch) end - end - it 'creates an ECS deployment job for review only' do - expect(review_prod_build_names).to contain_exactly('review_ecs', 'stop_review_ecs') - end + %w(review_ecs review_fargate).each do |job| + it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do + let(:job_name) { job } + end + end - context 'with FARGATE as a launch type' do - let(:platform_value) { 'FARGATE' } + it 'creates an ECS deployment job for review only' do + expect(review_prod_build_names).to contain_exactly('review_ecs', 'stop_review_ecs') + end + + context 'with FARGATE as a launch type' do + let(:platform_value) { 'FARGATE' } - it 'creates an FARGATE deployment job for review only' do - expect(review_prod_build_names).to contain_exactly('review_fargate', 'stop_review_fargate') + it 'creates an FARGATE deployment job for review only' do + expect(review_prod_build_names).to contain_exactly('review_fargate', 'stop_review_fargate') + end end end - end - context 'and when the project has an active cluster' do - let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } + context 'and when the project has an active cluster' do + let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } - before do - allow(cluster).to receive(:active?).and_return(true) - end + before do + allow(cluster).to receive(:active?).and_return(true) + end - context 'on default branch' do - it 'triggers the deployment to Kubernetes, not to ECS' do - expect(build_names).not_to include('review') - expect(build_names).to include('production') - expect(build_names).not_to include('production_ecs') - expect(build_names).not_to include('review_ecs') + context 'on default branch' do + it 'triggers the deployment to Kubernetes, not to ECS' do + expect(build_names).not_to include('review') + expect(build_names).to include('production') + expect(build_names).not_to include('production_ecs') + expect(build_names).not_to include('review_ecs') + end end end - end - context 'when the platform target is EC2' do - let(:platform_value) { 'EC2' } + context 'when the platform target is EC2' do + let(:platform_value) { 'EC2' } - it 'contains the build_artifact job, not the build job' do - expect(build_names).to include('build_artifact') - expect(build_names).not_to include('build') + it 'contains the build_artifact job, not the build job' do + expect(build_names).to include('build_artifact') + expect(build_names).not_to include('build') + end end end - end - - context 'when the project has no active cluster' do - it 'only creates a build and a test stage' do - expect(pipeline.stages_names).to eq(%w(build test)) - end - it_behaves_like 'no Kubernetes deployment job' - end + context 'when the project has no active cluster' do + it 'only creates a build and a test stage' do + expect(pipeline.stages_names).to eq(%w(build test)) + end - context 'when the project has an active cluster' do - let!(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } - - describe 'deployment-related builds' do - context 'on default branch' do - it 'does not include rollout jobs besides production' do - expect(build_names).to include('production') - expect(build_names).not_to include('production_manual') - expect(build_names).not_to include('staging') - expect(build_names).not_to include('canary') - expect(build_names).not_to include('review') - expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) - end + it_behaves_like 'no Kubernetes deployment job' + end - context 'when STAGING_ENABLED=1' do - before do - create(:ci_variable, project: project, key: 'STAGING_ENABLED', value: '1') - end + context 'when the project has an active cluster' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } - it 'includes a staging job and a production_manual job' do - expect(build_names).not_to include('production') - expect(build_names).to include('production_manual') - expect(build_names).to include('staging') + describe 'deployment-related builds' do + context 'on default branch' do + it 'does not include rollout jobs besides production' do + expect(build_names).to include('production') + expect(build_names).not_to include('production_manual') + expect(build_names).not_to include('staging') expect(build_names).not_to include('canary') expect(build_names).not_to include('review') expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) end + + context 'when STAGING_ENABLED=1' do + before do + create(:ci_variable, project: project, key: 'STAGING_ENABLED', value: '1') + end + + it 'includes a staging job and a production_manual job' do + expect(build_names).not_to include('production') + expect(build_names).to include('production_manual') + expect(build_names).to include('staging') + expect(build_names).not_to include('canary') + expect(build_names).not_to include('review') + expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) + end + end + + context 'when CANARY_ENABLED=1' do + before do + create(:ci_variable, project: project, key: 'CANARY_ENABLED', value: '1') + end + + it 'includes a canary job and a production_manual job' do + expect(build_names).not_to include('production') + expect(build_names).to include('production_manual') + expect(build_names).not_to include('staging') + expect(build_names).to include('canary') + expect(build_names).not_to include('review') + expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) + end + end end - context 'when CANARY_ENABLED=1' do + context 'outside of default branch' do + let(:pipeline_branch) { 'patch-1' } + before do - create(:ci_variable, project: project, key: 'CANARY_ENABLED', value: '1') + project.repository.create_branch(pipeline_branch, default_branch) end - it 'includes a canary job and a production_manual job' do + it 'does not include rollout jobs besides review' do expect(build_names).not_to include('production') - expect(build_names).to include('production_manual') + expect(build_names).not_to include('production_manual') expect(build_names).not_to include('staging') - expect(build_names).to include('canary') - expect(build_names).not_to include('review') + expect(build_names).not_to include('canary') + expect(build_names).to include('review') expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) end end end - - context 'outside of default branch' do - let(:pipeline_branch) { 'patch-1' } - - before do - project.repository.create_branch(pipeline_branch) - end - - it 'does not include rollout jobs besides review' do - expect(build_names).not_to include('production') - expect(build_names).not_to include('production_manual') - expect(build_names).not_to include('staging') - expect(build_names).not_to include('canary') - expect(build_names).to include('review') - expect(build_names).not_to include(a_string_matching(/rollout \d+%/)) - end - end end end - end - describe 'build-pack detection' do - using RSpec::Parameterized::TableSyntax - - where(:case_name, :files, :variables, :include_build_names, :not_include_build_names) do - 'No match' | { 'README.md' => '' } | {} | %w() | %w(build test) - 'Buildpack' | { 'README.md' => '' } | { 'BUILDPACK_URL' => 'http://example.com' } | %w(build test) | %w() - 'Explicit set' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '1' } | %w(build test) | %w() - 'Explicit unset' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '0' } | %w() | %w(build test) - 'DOCKERFILE_PATH' | { 'README.md' => '' } | { 'DOCKERFILE_PATH' => 'Docker.file' } | %w(build test) | %w() - 'Dockerfile' | { 'Dockerfile' => '' } | {} | %w(build test) | %w() - 'Clojure' | { 'project.clj' => '' } | {} | %w(build test) | %w() - 'Go modules' | { 'go.mod' => '' } | {} | %w(build test) | %w() - 'Go gb' | { 'src/gitlab.com/gopackage.go' => '' } | {} | %w(build test) | %w() - 'Gradle' | { 'gradlew' => '' } | {} | %w(build test) | %w() - 'Java' | { 'pom.xml' => '' } | {} | %w(build test) | %w() - 'Multi-buildpack' | { '.buildpacks' => '' } | {} | %w(build test) | %w() - 'NodeJS' | { 'package.json' => '' } | {} | %w(build test) | %w() - 'PHP' | { 'composer.json' => '' } | {} | %w(build test) | %w() - 'Play' | { 'conf/application.conf' => '' } | {} | %w(build test) | %w() - 'Python' | { 'Pipfile' => '' } | {} | %w(build test) | %w() - 'Ruby' | { 'Gemfile' => '' } | {} | %w(build test) | %w() - 'Scala' | { 'build.sbt' => '' } | {} | %w(build test) | %w() - 'Static' | { '.static' => '' } | {} | %w(build test) | %w() - end + describe 'build-pack detection' do + using RSpec::Parameterized::TableSyntax + + where(:case_name, :files, :variables, :include_build_names, :not_include_build_names) do + 'No match' | { 'README.md' => '' } | {} | %w() | %w(build test) + 'Buildpack' | { 'README.md' => '' } | { 'BUILDPACK_URL' => 'http://example.com' } | %w(build test) | %w() + 'Explicit set' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '1' } | %w(build test) | %w() + 'Explicit unset' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '0' } | %w() | %w(build test) + 'DOCKERFILE_PATH' | { 'README.md' => '' } | { 'DOCKERFILE_PATH' => 'Docker.file' } | %w(build test) | %w() + 'Dockerfile' | { 'Dockerfile' => '' } | {} | %w(build test) | %w() + 'Clojure' | { 'project.clj' => '' } | {} | %w(build test) | %w() + 'Go modules' | { 'go.mod' => '' } | {} | %w(build test) | %w() + 'Go gb' | { 'src/gitlab.com/gopackage.go' => '' } | {} | %w(build test) | %w() + 'Gradle' | { 'gradlew' => '' } | {} | %w(build test) | %w() + 'Java' | { 'pom.xml' => '' } | {} | %w(build test) | %w() + 'Multi-buildpack' | { '.buildpacks' => '' } | {} | %w(build test) | %w() + 'NodeJS' | { 'package.json' => '' } | {} | %w(build test) | %w() + 'PHP' | { 'composer.json' => '' } | {} | %w(build test) | %w() + 'Play' | { 'conf/application.conf' => '' } | {} | %w(build test) | %w() + 'Python' | { 'Pipfile' => '' } | {} | %w(build test) | %w() + 'Ruby' | { 'Gemfile' => '' } | {} | %w(build test) | %w() + 'Scala' | { 'build.sbt' => '' } | {} | %w(build test) | %w() + 'Static' | { '.static' => '' } | {} | %w(build test) | %w() + end - with_them do - let(:project) { create(:project, :custom_repo, files: files) } - let(:user) { project.owner } - let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) } - let(:pipeline) { service.execute(:push) } - let(:build_names) { pipeline.builds.pluck(:name) } + with_them do + let(:project) { create(:project, :custom_repo, files: files) } + let(:user) { project.owner } + let(:service) { Ci::CreatePipelineService.new(project, user, ref: default_branch ) } + let(:pipeline) { service.execute(:push) } + let(:build_names) { pipeline.builds.pluck(:name) } - before do - stub_ci_pipeline_yaml_file(template.content) - allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true) - variables.each do |(key, value)| - create(:ci_variable, project: project, key: key, value: value) + before do + stub_application_setting(default_branch_name: default_branch) + stub_ci_pipeline_yaml_file(template.content) + allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true) + variables.each do |(key, value)| + create(:ci_variable, project: project, key: key, value: value) + end end - end - it 'creates a pipeline with the expected jobs' do - expect(build_names).to include(*include_build_names) - expect(build_names).not_to include(*not_include_build_names) + it 'creates a pipeline with the expected jobs' do + expect(build_names).to include(*include_build_names) + expect(build_names).not_to include(*not_include_build_names) + end end end end diff --git a/spec/support/helpers/design_management_test_helpers.rb b/spec/support/helpers/design_management_test_helpers.rb index db217250b17..be723a47521 100644 --- a/spec/support/helpers/design_management_test_helpers.rb +++ b/spec/support/helpers/design_management_test_helpers.rb @@ -35,7 +35,7 @@ module DesignManagementTestHelpers def act_on_designs(designs, &block) issue = designs.first.issue - version = build(:design_version, :empty, issue: issue).tap { |v| v.save!(validate: false) } + version = build(:design_version, designs_count: 0, issue: issue).tap { |v| v.save!(validate: false) } designs.each do |d| yield.create!(design: d, version: version) end |