summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-11-27 11:09:35 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-12-03 12:04:49 +0100
commitbf6126b1ecd63825070e391ebde86da9cd9dfd5e (patch)
tree25e6e17bdf4a44f108c9771b87bd089e1528f3d6
parente35f16074d065cc60f6cd99b4b46c09e437f129c (diff)
downloadgitlab-ce-bf6126b1ecd63825070e391ebde86da9cd9dfd5e.tar.gz
Add coverage on legacy artifacts for Ci::Build
-rw-r--r--spec/models/ci/build_spec.rb241
-rw-r--r--spec/models/project_statistics_spec.rb26
2 files changed, 190 insertions, 77 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index f8dbed91c1a..fefb54ad6f7 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -132,27 +132,55 @@ describe Ci::Build do
end
describe '#artifacts?' do
- let(:build) { create(:ci_build, :artifacts) }
+ context 'when new artifacts are used' do
+ let(:build) { create(:ci_build, :artifacts) }
- subject { build.artifacts? }
+ subject { build.artifacts? }
- context 'artifacts archive does not exist' do
- let(:build) { create(:ci_build) }
+ context 'artifacts archive does not exist' do
+ let(:build) { create(:ci_build) }
- it { is_expected.to be_falsy }
+ it { is_expected.to be_falsy }
+ end
+
+ context 'artifacts archive exists' do
+ it { is_expected.to be_truthy }
+
+ context 'is expired' do
+ let!(:build) { create(:ci_build, :artifacts, :expired) }
+
+ it { is_expected.to be_falsy }
+ end
+
+ context 'is not expired' do
+ it { is_expected.to be_truthy }
+ end
+ end
end
- context 'artifacts archive exists' do
- it { is_expected.to be_truthy }
+ context 'when legacy artifacts are used' do
+ let(:build) { create(:ci_build, :legacy_artifacts) }
+
+ subject { build.artifacts? }
- context 'is expired' do
- let!(:build) { create(:ci_build, :artifacts, :expired) }
+ context 'artifacts archive does not exist' do
+ let(:build) { create(:ci_build) }
it { is_expected.to be_falsy }
end
- context 'is not expired' do
+ context 'artifacts archive exists' do
it { is_expected.to be_truthy }
+
+ context 'is expired' do
+ let!(:build) { create(:ci_build, :legacy_artifacts, :expired) }
+
+ it { is_expected.to be_falsy }
+ end
+
+ context 'is not expired' do
+ it { is_expected.to be_truthy }
+ end
end
end
end
@@ -607,71 +635,144 @@ describe Ci::Build do
describe '#erasable?' do
subject { build.erasable? }
+
it { is_expected.to eq false }
end
end
context 'build is erasable' do
- let!(:build) { create(:ci_build, :trace, :success, :artifacts) }
+ context 'new artifacts' do
+ let!(:build) { create(:ci_build, :trace, :success, :artifacts) }
- describe '#erase' do
- before do
- build.erase(erased_by: user)
- end
+ describe '#erase' do
+ before do
+ build.erase(erased_by: user)
+ end
- context 'erased by user' do
- let!(:user) { create(:user, username: 'eraser') }
+ context 'erased by user' do
+ let!(:user) { create(:user, username: 'eraser') }
- include_examples 'erasable'
+ include_examples 'erasable'
- it 'records user who erased a build' do
- expect(build.erased_by).to eq user
+ it 'records user who erased a build' do
+ expect(build.erased_by).to eq user
+ end
end
- end
- context 'erased by system' do
- let(:user) { nil }
+ context 'erased by system' do
+ let(:user) { nil }
- include_examples 'erasable'
+ include_examples 'erasable'
- it 'does not set user who erased a build' do
- expect(build.erased_by).to be_nil
+ it 'does not set user who erased a build' do
+ expect(build.erased_by).to be_nil
+ end
end
end
- end
- describe '#erasable?' do
- subject { build.erasable? }
- it { is_expected.to be_truthy }
- end
+ describe '#erasable?' do
+ subject { build.erasable? }
+ it { is_expected.to be_truthy }
+ end
- describe '#erased?' do
- let!(:build) { create(:ci_build, :trace, :success, :artifacts) }
- subject { build.erased? }
+ describe '#erased?' do
+ let!(:build) { create(:ci_build, :trace, :success, :artifacts) }
+ subject { build.erased? }
- context 'job has not been erased' do
- it { is_expected.to be_falsey }
+ context 'job has not been erased' do
+ it { is_expected.to be_falsey }
+ end
+
+ context 'job has been erased' do
+ before do
+ build.erase
+ end
+
+ it { is_expected.to be_truthy }
+ end
end
- context 'job has been erased' do
+ context 'metadata and build trace are not available' do
+ let!(:build) { create(:ci_build, :success, :artifacts) }
+
before do
- build.erase
+ build.remove_artifacts_metadata!
end
- it { is_expected.to be_truthy }
+ describe '#erase' do
+ it 'does not raise error' do
+ expect { build.erase }.not_to raise_error
+ end
+ end
end
end
+ end
- context 'metadata and build trace are not available' do
- let!(:build) { create(:ci_build, :success, :artifacts) }
+ context 'old artifacts' do
+ context 'build is erasable' do
+ context 'new artifacts' do
+ let!(:build) { create(:ci_build, :trace, :success, :legacy_artifacts) }
- before do
- build.remove_artifacts_metadata!
- end
+ describe '#erase' do
+ before do
+ build.erase(erased_by: user)
+ end
- describe '#erase' do
- it 'does not raise error' do
- expect { build.erase }.not_to raise_error
+ context 'erased by user' do
+ let!(:user) { create(:user, username: 'eraser') }
+
+ include_examples 'erasable'
+
+ it 'records user who erased a build' do
+ expect(build.erased_by).to eq user
+ end
+ end
+
+ context 'erased by system' do
+ let(:user) { nil }
+
+ include_examples 'erasable'
+
+ it 'does not set user who erased a build' do
+ expect(build.erased_by).to be_nil
+ end
+ end
+ end
+
+ describe '#erasable?' do
+ subject { build.erasable? }
+ it { is_expected.to be_truthy }
+ end
+
+ describe '#erased?' do
+ let!(:build) { create(:ci_build, :trace, :success, :legacy_artifacts) }
+ subject { build.erased? }
+
+ context 'job has not been erased' do
+ it { is_expected.to be_falsey }
+ end
+
+ context 'job has been erased' do
+ before do
+ build.erase
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ context 'metadata and build trace are not available' do
+ let!(:build) { create(:ci_build, :success, :legacy_artifacts) }
+
+ before do
+ build.remove_artifacts_metadata!
+ end
+
+ describe '#erase' do
+ it 'does not raise error' do
+ expect { build.erase }.not_to raise_error
+ end
+ end
end
end
end
@@ -917,9 +1018,9 @@ describe Ci::Build do
describe '#merge_request' do
def create_mr(build, pipeline, factory: :merge_request, created_at: Time.now)
create(factory, source_project: pipeline.project,
- target_project: pipeline.project,
- source_branch: build.ref,
- created_at: created_at)
+ target_project: pipeline.project,
+ source_branch: build.ref,
+ created_at: created_at)
end
context 'when a MR has a reference to the pipeline' do
@@ -1218,7 +1319,7 @@ describe Ci::Build do
context 'when `when` is undefined' do
before do
build.when = nil
- end
+ end
context 'use from gitlab-ci.yml' do
let(:pipeline) { create(:ci_pipeline) }
@@ -1236,10 +1337,10 @@ describe Ci::Build do
context 'when config does not have a questioned job' do
let(:config) do
YAML.dump({
- test_other: {
- script: 'Hello World'
- }
- })
+ test_other: {
+ script: 'Hello World'
+ }
+ })
end
it { is_expected.to eq('on_success') }
@@ -1248,18 +1349,18 @@ describe Ci::Build do
context 'when config has `when`' do
let(:config) do
YAML.dump({
- test: {
- script: 'Hello World',
- when: 'always'
- }
- })
+ test: {
+ script: 'Hello World',
+ when: 'always'
+ }
+ })
end
it { is_expected.to eq('always') }
end
end
end
- end
+ end
describe '#variables' do
let(:container_registry_enabled) { false }
@@ -1333,10 +1434,10 @@ describe Ci::Build do
let!(:environment) do
create(:environment,
- project: build.project,
- name: 'production',
- slug: 'prod-slug',
- external_url: '')
+ project: build.project,
+ name: 'production',
+ slug: 'prod-slug',
+ external_url: '')
end
before do
@@ -1362,7 +1463,7 @@ describe Ci::Build do
before do
environment_variables <<
- { key: 'CI_ENVIRONMENT_URL', value: url, public: true }
+ { key: 'CI_ENVIRONMENT_URL', value: url, public: true }
end
context 'when the URL was set from the job' do
@@ -1560,8 +1661,8 @@ describe Ci::Build do
let!(:pipeline_schedule_variable) do
create(:ci_pipeline_schedule_variable,
- key: 'SCHEDULE_VARIABLE_KEY',
- pipeline_schedule: pipeline_schedule)
+ key: 'SCHEDULE_VARIABLE_KEY',
+ pipeline_schedule: pipeline_schedule)
end
before do
@@ -1703,8 +1804,8 @@ describe Ci::Build do
allow_any_instance_of(Project)
.to receive(:secret_variables_for)
.with(ref: 'master', environment: nil) do
- [create(:ci_variable, key: 'secret', value: 'value')]
- end
+ [create(:ci_variable, key: 'secret', value: 'value')]
+ end
allow_any_instance_of(Ci::Pipeline)
.to receive(:predefined_variables) { [pipeline_pre_var] }
diff --git a/spec/models/project_statistics_spec.rb b/spec/models/project_statistics_spec.rb
index 4496f91fc5e..e78ed1df821 100644
--- a/spec/models/project_statistics_spec.rb
+++ b/spec/models/project_statistics_spec.rb
@@ -133,17 +133,29 @@ describe ProjectStatistics do
describe '#update_build_artifacts_size' do
let!(:pipeline) { create(:ci_pipeline, project: project) }
- let!(:ci_build) { create(:ci_build, pipeline: pipeline, artifacts_size: 45.megabytes) }
- before do
- create(:ci_build, pipeline: pipeline, artifacts_size: 56.megabytes)
- create(:ci_job_artifact, :archive, project: pipeline.project, job: ci_build)
+ context 'when new job artifacts are calculated' do
+ let(:ci_build) { create(:ci_build, pipeline: pipeline) }
+
+ before do
+ create(:ci_job_artifact, :archive, project: pipeline.project, job: ci_build)
+ end
+
+ it "stores the size of related build artifacts" do
+ statistics.update_build_artifacts_size
- statistics.update_build_artifacts_size
+ expect(statistics.build_artifacts_size).to be(106365)
+ end
end
- it "stores the size of related build artifacts" do
- expect(statistics.build_artifacts_size).to eq(106012541)
+ context 'when legacy artifacts are used' do
+ let!(:ci_build) { create(:ci_build, pipeline: pipeline, artifacts_size: 10.megabytes) }
+
+ it "stores the size of related build artifacts" do
+ statistics.update_build_artifacts_size
+
+ expect(statistics.build_artifacts_size).to eq(10.megabytes)
+ end
end
end