diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/features/pipelines_spec.rb | 15 | ||||
| -rw-r--r-- | spec/lib/ci/charts_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/ci/pipeline_spec.rb | 99 | ||||
| -rw-r--r-- | spec/requests/api/builds_spec.rb | 12 | ||||
| -rw-r--r-- | spec/services/ci/image_for_build_service_spec.rb | 2 |
5 files changed, 77 insertions, 68 deletions
diff --git a/spec/features/pipelines_spec.rb b/spec/features/pipelines_spec.rb index f88b8f8e60b..4e75f888176 100644 --- a/spec/features/pipelines_spec.rb +++ b/spec/features/pipelines_spec.rb @@ -12,7 +12,7 @@ describe "Pipelines" do end describe 'GET /:project/pipelines' do - let!(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', status: 'running') } + let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: 'master', status: 'running') } [:all, :running, :branches].each do |scope| context "displaying #{scope}" do @@ -31,10 +31,10 @@ describe "Pipelines" do end context 'cancelable pipeline' do - let!(:running) { create(:ci_build, :running, pipeline: pipeline, stage: 'test', commands: 'test') } + let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') } before do - pipeline.reload_status! + build.run visit namespace_project_pipelines_path(project.namespace, project) end @@ -50,10 +50,10 @@ describe "Pipelines" do end context 'retryable pipelines' do - let!(:failed) { create(:ci_build, :failed, pipeline: pipeline, stage: 'test', commands: 'test') } + let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') } before do - pipeline.reload_status! + build.drop visit namespace_project_pipelines_path(project.namespace, project) end @@ -87,7 +87,6 @@ describe "Pipelines" do let!(:running) { create(:generic_commit_status, status: 'running', pipeline: pipeline, stage: 'test') } before do - pipeline.reload_status! visit namespace_project_pipelines_path(project.namespace, project) end @@ -101,10 +100,10 @@ describe "Pipelines" do end context 'when failed' do - let!(:failed) { create(:generic_commit_status, status: 'failed', pipeline: pipeline, stage: 'test') } + let!(:status) { create(:generic_commit_status, :pending, pipeline: pipeline, stage: 'test') } before do - pipeline.reload_status! + status.drop visit namespace_project_pipelines_path(project.namespace, project) end diff --git a/spec/lib/ci/charts_spec.rb b/spec/lib/ci/charts_spec.rb index 2cd6b00dad6..fb6cc398307 100644 --- a/spec/lib/ci/charts_spec.rb +++ b/spec/lib/ci/charts_spec.rb @@ -2,22 +2,23 @@ require 'spec_helper' describe Ci::Charts, lib: true do context "build_times" do + let(:project) { create(:empty_project) } + let(:chart) { Ci::Charts::BuildTime.new(project) } + + subject { chart.build_times } + before do - @pipeline = FactoryGirl.create(:ci_pipeline) - FactoryGirl.create(:ci_build, pipeline: @pipeline) - @pipeline.reload_status! + create(:ci_empty_pipeline, project: project, duration: 120) end it 'returns build times in minutes' do - chart = Ci::Charts::BuildTime.new(@pipeline.project) - expect(chart.build_times).to eq([2]) + is_expected.to contain_exactly(2) end it 'handles nil build times' do - create(:ci_pipeline, duration: nil, project: @pipeline.project) + create(:ci_empty_pipeline, project: project, duration: nil) - chart = Ci::Charts::BuildTime.new(@pipeline.project) - expect(chart.build_times).to eq([2, 0]) + is_expected.to contain_exactly(2, 0) end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index fdb579ab45c..adfe4bdd0c8 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Ci::Pipeline, models: true do let(:project) { FactoryGirl.create :empty_project } - let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project } + let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project } it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:user) } @@ -51,25 +51,6 @@ describe Ci::Pipeline, models: true do end end - describe "#finished_at" do - let(:pipeline) { FactoryGirl.create :ci_pipeline } - - it "returns finished_at of latest build" do - build = FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 60 - FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 120 - pipeline.reload_status! - - expect(pipeline.finished_at.to_i).to eq(build.finished_at.to_i) - end - - it "returns nil if there is no finished build" do - FactoryGirl.create :ci_not_started_build, pipeline: pipeline - pipeline.reload_status! - - expect(pipeline.finished_at).to be_nil - end - end - describe "coverage" do let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" } let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project } @@ -139,33 +120,18 @@ describe Ci::Pipeline, models: true do end end - describe '#reload_status!' do - let(:pipeline) { create :ci_empty_pipeline, project: project } - - context 'dependent objects' do - let(:commit_status) { create :commit_status, :pending, pipeline: pipeline } + describe '#duration' do + let(:current) { Time.now.change(usec: 0) } + let!(:build) { create :ci_build, name: 'build1', pipeline: pipeline, started_at: current - 60, finished_at: current } + let!(:build2) { create :ci_build, name: 'build2', pipeline: pipeline, started_at: current - 60, finished_at: current } - it 'executes reload_status! after succeeding dependent object' do - expect(pipeline).to receive(:reload_status!).and_return(true) - - commit_status.success - end + before do + build.skip + build2.skip end - context 'updates' do - let(:current) { Time.now.change(usec: 0) } - let(:build) { FactoryGirl.create :ci_build, pipeline: pipeline, started_at: current - 120, finished_at: current - 60 } - - before do - build - pipeline.reload_status! - end - - [:status, :started_at, :finished_at, :duration].each do |param| - it "#{param}" do - expect(pipeline.send(param)).to eq(build.send(param)) - end - end + it 'matches sum of builds duration' do + expect(pipeline.reload.duration).to eq(build.duration + build2.duration) end end @@ -254,4 +220,49 @@ describe Ci::Pipeline, models: true do end end end + + describe '#status' do + let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') } + + subject { pipeline.reload.status } + + context 'on queuing' do + before { build.queue } + + it { is_expected.to eq('pending') } + end + + context 'on run' do + before do + build.queue + build.run + end + + it { is_expected.to eq('running') } + end + + context 'on drop' do + before do + build.drop + end + + it { is_expected.to eq('failed') } + end + + context 'on success' do + before do + build.success + end + + it { is_expected.to eq('success') } + end + + context 'on cancel' do + before do + build.cancel + end + + it { is_expected.to eq('canceled') } + end + end end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index a4cdd8f3140..41503885dd9 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -9,7 +9,7 @@ describe API::API, api: true do let!(:developer) { create(:project_member, :developer, user: user, project: project) } let(:reporter) { create(:project_member, :reporter, project: project) } let(:guest) { create(:project_member, :guest, project: project) } - let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } + let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } let!(:build) { create(:ci_build, pipeline: pipeline) } describe 'GET /projects/:id/builds ' do @@ -174,7 +174,11 @@ describe API::API, api: true do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do let(:api_user) { reporter.user } - let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } + let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) } + + before do + build.success + end def path_for_ref(ref = pipeline.ref, job = build.name) api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user) @@ -238,10 +242,6 @@ describe API::API, api: true do it { expect(response.headers).to include(download_headers) } end - before do - pipeline.reload_status! - end - context 'with regular branch' do before do pipeline.update(ref: 'master', diff --git a/spec/services/ci/image_for_build_service_spec.rb b/spec/services/ci/image_for_build_service_spec.rb index 259062406c7..c931c3e4829 100644 --- a/spec/services/ci/image_for_build_service_spec.rb +++ b/spec/services/ci/image_for_build_service_spec.rb @@ -14,7 +14,6 @@ module Ci context 'branch name' do before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) } before { build.run! } - before { pipeline.reload_status! } let(:image) { service.execute(project, ref: 'master') } it { expect(image).to be_kind_of(OpenStruct) } @@ -32,7 +31,6 @@ module Ci context 'commit sha' do before { build.run! } - before { pipeline.reload_status! } let(:image) { service.execute(project, sha: build.sha) } it { expect(image).to be_kind_of(OpenStruct) } |
