summaryrefslogtreecommitdiff
path: root/spec/models/ci
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-07-05 13:55:10 +0000
committerDouwe Maan <douwe@gitlab.com>2018-07-05 13:55:10 +0000
commita7a1531fe5d030d47d63bfcd86a7168a8437ff86 (patch)
tree65854ce75eb6b6f6061fef114f95076fae2ab9a8 /spec/models/ci
parent9a62e72db9892708ab360c59a9f77695d9253c34 (diff)
downloadgitlab-ce-a7a1531fe5d030d47d63bfcd86a7168a8437ff86.tar.gz
Web Terminal Ci Build
Diffstat (limited to 'spec/models/ci')
-rw-r--r--spec/models/ci/build_runner_session_spec.rb36
-rw-r--r--spec/models/ci/build_spec.rb50
2 files changed, 86 insertions, 0 deletions
diff --git a/spec/models/ci/build_runner_session_spec.rb b/spec/models/ci/build_runner_session_spec.rb
new file mode 100644
index 00000000000..7183957aa50
--- /dev/null
+++ b/spec/models/ci/build_runner_session_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Ci::BuildRunnerSession, model: true do
+ let!(:build) { create(:ci_build, :with_runner_session) }
+
+ subject { build.runner_session }
+
+ it { is_expected.to belong_to(:build) }
+
+ it { is_expected.to validate_presence_of(:build) }
+ it { is_expected.to validate_presence_of(:url).with_message('must be a valid URL') }
+
+ describe '#terminal_specification' do
+ let(:terminal_specification) { subject.terminal_specification }
+
+ it 'returns empty hash if no url' do
+ subject.url = ''
+
+ expect(terminal_specification).to be_empty
+ end
+
+ context 'when url is present' do
+ it 'returns ca_pem nil if empty certificate' do
+ subject.certificate = ''
+
+ expect(terminal_specification[:ca_pem]).to be_nil
+ end
+
+ it 'adds Authorization header if authorization is present' do
+ subject.authorization = 'whatever'
+
+ expect(terminal_specification[:headers]).to include(Authorization: 'whatever')
+ end
+ end
+ end
+end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 6758adc59eb..0da1234ee3b 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -19,6 +19,7 @@ describe Ci::Build do
it { is_expected.to belong_to(:erased_by) }
it { is_expected.to have_many(:deployments) }
it { is_expected.to have_many(:trace_sections)}
+ it { is_expected.to have_one(:runner_session)}
it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to respond_to(:has_trace?) }
it { is_expected.to respond_to(:trace) }
@@ -42,6 +43,20 @@ describe Ci::Build do
end
end
+ describe 'status' do
+ context 'when transitioning to any state from running' do
+ it 'removes runner_session' do
+ %w(success drop cancel).each do |event|
+ build = FactoryBot.create(:ci_build, :running, :with_runner_session, pipeline: pipeline)
+
+ build.fire_events!(event)
+
+ expect(build.reload.runner_session).to be_nil
+ end
+ end
+ end
+ end
+
describe '.manual_actions' do
let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) }
let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) }
@@ -2605,4 +2620,39 @@ describe Ci::Build do
end
end
end
+
+ describe '#has_terminal?' do
+ let(:states) { described_class.state_machines[:status].states.keys - [:running] }
+
+ subject { build.has_terminal? }
+
+ it 'returns true if the build is running and it has a runner_session_url' do
+ build.build_runner_session(url: 'whatever')
+ build.status = :running
+
+ expect(subject).to be_truthy
+ end
+
+ context 'returns false' do
+ it 'when runner_session_url is empty' do
+ build.status = :running
+
+ expect(subject).to be_falsey
+ end
+
+ context 'unless the build is running' do
+ before do
+ build.build_runner_session(url: 'whatever')
+ end
+
+ it do
+ states.each do |state|
+ build.status = state
+
+ is_expected.to be_falsey
+ end
+ end
+ end
+ end
+ end
end