summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 06:07:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 06:07:58 +0000
commit9c83aadd2604e7e6cb1f84683f951e6b12872618 (patch)
treec0a14c87378e832e87580be382e1c8ccea188b71 /spec
parent23bc19cb73aad969c9636b8b935111645e809e54 (diff)
downloadgitlab-ce-9c83aadd2604e7e6cb1f84683f951e6b12872618.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap1
-rw-r--r--spec/models/ci/build_spec.rb141
-rw-r--r--spec/models/ci/processable/dependencies_spec.rb173
-rw-r--r--spec/models/deployment_spec.rb22
-rw-r--r--spec/models/environment_spec.rb9
5 files changed, 205 insertions, 141 deletions
diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
index e37043e5d4d..b8bda533072 100644
--- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
+++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
@@ -53,6 +53,7 @@ exports[`Dashboard template matches the default snapshot 1`] = `
<gl-search-box-by-type-stub
class="m-2"
+ clearbuttontitle="Clear"
value=""
/>
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index a661aa6e3a9..8c7969af177 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -730,147 +730,6 @@ describe Ci::Build do
end
end
- describe '#depends_on_builds' do
- let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
- let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
- let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') }
- let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') }
-
- it 'expects to have no dependents if this is first build' do
- expect(build.depends_on_builds).to be_empty
- end
-
- it 'expects to have one dependent if this is test' do
- expect(rspec_test.depends_on_builds.map(&:id)).to contain_exactly(build.id)
- end
-
- it 'expects to have all builds from build and test stage if this is last' do
- expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, rspec_test.id, rubocop_test.id)
- end
-
- it 'expects to have retried builds instead the original ones' do
- project.add_developer(user)
-
- retried_rspec = described_class.retry(rspec_test, user)
-
- expect(staging.depends_on_builds.map(&:id))
- .to contain_exactly(build.id, retried_rspec.id, rubocop_test.id)
- end
-
- describe '#dependencies' do
- let(:dependencies) { }
- let(:needs) { }
-
- let!(:final) do
- scheduling_type = needs.present? ? :dag : :stage
-
- create(:ci_build,
- pipeline: pipeline, name: 'final', scheduling_type: scheduling_type,
- stage_idx: 3, stage: 'deploy', options: {
- dependencies: dependencies
- }
- )
- end
-
- before do
- needs.to_a.each do |need|
- create(:ci_build_need, build: final, **need)
- end
- end
-
- subject { final.dependencies }
-
- context 'when dependencies are defined' do
- let(:dependencies) { %w(rspec staging) }
-
- it { is_expected.to contain_exactly(rspec_test, staging) }
- end
-
- context 'when needs are defined' do
- let(:needs) do
- [
- { name: 'build', artifacts: true },
- { name: 'rspec', artifacts: true },
- { name: 'staging', artifacts: true }
- ]
- end
-
- it { is_expected.to contain_exactly(build, rspec_test, staging) }
-
- context 'when ci_dag_support is disabled' do
- before do
- stub_feature_flags(ci_dag_support: false)
- end
-
- it { is_expected.to contain_exactly(build, rspec_test, rubocop_test, staging) }
- end
- end
-
- context 'when need artifacts are defined' do
- let(:needs) do
- [
- { name: 'build', artifacts: true },
- { name: 'rspec', artifacts: false },
- { name: 'staging', artifacts: true }
- ]
- end
-
- it { is_expected.to contain_exactly(build, staging) }
- end
-
- context 'when needs and dependencies are defined' do
- let(:dependencies) { %w(rspec staging) }
- let(:needs) do
- [
- { name: 'build', artifacts: true },
- { name: 'rspec', artifacts: true },
- { name: 'staging', artifacts: true }
- ]
- end
-
- it { is_expected.to contain_exactly(rspec_test, staging) }
- end
-
- context 'when needs and dependencies contradict' do
- let(:dependencies) { %w(rspec staging) }
- let(:needs) do
- [
- { name: 'build', artifacts: true },
- { name: 'rspec', artifacts: false },
- { name: 'staging', artifacts: true }
- ]
- end
-
- it { is_expected.to contain_exactly(staging) }
- end
-
- context 'when nor dependencies or needs are defined' do
- it { is_expected.to contain_exactly(build, rspec_test, rubocop_test, staging) }
- end
- end
-
- describe '#all_dependencies' do
- let!(:final_build) do
- create(:ci_build,
- pipeline: pipeline, name: 'deploy',
- stage_idx: 3, stage: 'deploy'
- )
- end
-
- subject { final_build.all_dependencies }
-
- it 'returns dependencies and cross_dependencies' do
- dependencies = [1, 2, 3]
- cross_dependencies = [3, 4]
-
- allow(final_build).to receive(:dependencies).and_return(dependencies)
- allow(final_build).to receive(:cross_dependencies).and_return(cross_dependencies)
-
- is_expected.to match(a_collection_containing_exactly(1, 2, 3, 4))
- end
- end
- end
-
describe '#triggered_by?' do
subject { build.triggered_by?(user) }
diff --git a/spec/models/ci/processable/dependencies_spec.rb b/spec/models/ci/processable/dependencies_spec.rb
new file mode 100644
index 00000000000..f115ae51f9c
--- /dev/null
+++ b/spec/models/ci/processable/dependencies_spec.rb
@@ -0,0 +1,173 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::Processable::Dependencies do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project, reload: true) { create(:project, :repository) }
+
+ let_it_be(:pipeline, reload: true) do
+ create(:ci_pipeline, project: project,
+ sha: project.commit.id,
+ ref: project.default_branch,
+ status: 'success')
+ end
+
+ let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
+ let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
+ let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') }
+ let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') }
+
+ describe '#local' do
+ subject { described_class.new(job).local }
+
+ describe 'jobs from previous stages' do
+ context 'when job is in the first stage' do
+ let(:job) { build }
+
+ it { is_expected.to be_empty }
+ end
+
+ context 'when job is in the second stage' do
+ let(:job) { rspec_test }
+
+ it 'contains all jobs from the first stage' do
+ is_expected.to contain_exactly(build)
+ end
+ end
+
+ context 'when job is in the last stage' do
+ let(:job) { staging }
+
+ it 'contains all jobs from all previous stages' do
+ is_expected.to contain_exactly(build, rspec_test, rubocop_test)
+ end
+
+ context 'when a job is retried' do
+ before do
+ project.add_developer(user)
+ end
+
+ let(:retried_job) { Ci::Build.retry(rspec_test, user) }
+
+ it 'contains the retried job instead of the original one' do
+ is_expected.to contain_exactly(build, retried_job, rubocop_test)
+ end
+ end
+ end
+ end
+
+ describe 'jobs from specified dependencies' do
+ let(:dependencies) { }
+ let(:needs) { }
+
+ let!(:job) do
+ scheduling_type = needs.present? ? :dag : :stage
+
+ create(:ci_build,
+ pipeline: pipeline,
+ name: 'final',
+ scheduling_type: scheduling_type,
+ stage_idx: 3,
+ stage: 'deploy',
+ options: { dependencies: dependencies }
+ )
+ end
+
+ before do
+ needs.to_a.each do |need|
+ create(:ci_build_need, build: job, **need)
+ end
+ end
+
+ context 'when dependencies are defined' do
+ let(:dependencies) { %w(rspec staging) }
+
+ it { is_expected.to contain_exactly(rspec_test, staging) }
+ end
+
+ context 'when needs are defined' do
+ let(:needs) do
+ [
+ { name: 'build', artifacts: true },
+ { name: 'rspec', artifacts: true },
+ { name: 'staging', artifacts: true }
+ ]
+ end
+
+ it { is_expected.to contain_exactly(build, rspec_test, staging) }
+
+ context 'when ci_dag_support is disabled' do
+ before do
+ stub_feature_flags(ci_dag_support: false)
+ end
+
+ it { is_expected.to contain_exactly(build, rspec_test, rubocop_test, staging) }
+ end
+ end
+
+ context 'when need artifacts are defined' do
+ let(:needs) do
+ [
+ { name: 'build', artifacts: true },
+ { name: 'rspec', artifacts: false },
+ { name: 'staging', artifacts: true }
+ ]
+ end
+
+ it { is_expected.to contain_exactly(build, staging) }
+ end
+
+ context 'when needs and dependencies are defined' do
+ let(:dependencies) { %w(rspec staging) }
+ let(:needs) do
+ [
+ { name: 'build', artifacts: true },
+ { name: 'rspec', artifacts: true },
+ { name: 'staging', artifacts: true }
+ ]
+ end
+
+ it { is_expected.to contain_exactly(rspec_test, staging) }
+ end
+
+ context 'when needs and dependencies contradict' do
+ let(:dependencies) { %w(rspec staging) }
+ let(:needs) do
+ [
+ { name: 'build', artifacts: true },
+ { name: 'rspec', artifacts: false },
+ { name: 'staging', artifacts: true }
+ ]
+ end
+
+ it 'returns only the intersection' do
+ is_expected.to contain_exactly(staging)
+ end
+ end
+
+ context 'when nor dependencies or needs are defined' do
+ it 'returns the jobs from previous stages' do
+ is_expected.to contain_exactly(build, rspec_test, rubocop_test, staging)
+ end
+ end
+ end
+ end
+
+ describe '#all' do
+ let!(:job) do
+ create(:ci_build, pipeline: pipeline, name: 'deploy', stage_idx: 3, stage: 'deploy')
+ end
+
+ let(:dependencies) { described_class.new(job) }
+
+ subject { dependencies.all }
+
+ it 'returns the union of all local dependencies and any cross pipeline dependencies' do
+ expect(dependencies).to receive(:local).and_return([1, 2, 3])
+ expect(dependencies).to receive(:cross_pipeline).and_return([3, 4])
+
+ expect(subject).to contain_exactly(1, 2, 3, 4)
+ end
+ end
+end
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index 86dfa586862..6eb006a5d67 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -623,4 +623,26 @@ describe Deployment do
expect(deploy.errors[:ref]).not_to be_empty
end
end
+
+ describe '.fast_destroy_all' do
+ it 'cleans path_refs for destroyed environments' do
+ project = create(:project, :repository)
+ environment = create(:environment, project: project)
+
+ destroyed_deployments = create_list(:deployment, 2, :success, environment: environment, project: project)
+ other_deployments = create_list(:deployment, 2, :success, environment: environment, project: project)
+
+ (destroyed_deployments + other_deployments).each(&:create_ref)
+
+ described_class.where(id: destroyed_deployments.map(&:id)).fast_destroy_all
+
+ destroyed_deployments.each do |deployment|
+ expect(project.commit(deployment.ref_path)).to be_nil
+ end
+
+ other_deployments.each do |deployment|
+ expect(project.commit(deployment.ref_path)).not_to be_nil
+ end
+ end
+ end
end
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 6020db09ccf..896203d8669 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -1301,4 +1301,13 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
end
+
+ describe '#destroy' do
+ it 'remove the deployment refs from gitaly' do
+ deployment = create(:deployment, :success, environment: environment, project: project)
+ deployment.create_ref
+
+ expect { environment.destroy }.to change { project.commit(deployment.ref_path) }.to(nil)
+ end
+ end
end