debian-mirror-gitlab/spec/models/ci/build_runner_session_spec.rb

67 lines
1.8 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
describe Ci::BuildRunnerSession, model: true do
let!(:build) { create(:ci_build, :with_runner_session) }
2020-01-01 13:55:28 +05:30
let(:url) { 'https://new.example.com' }
2018-11-08 19:23:39 +05:30
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') }
2020-01-01 13:55:28 +05:30
context 'nested attribute assignment' do
it 'creates a new session' do
simple_build = create(:ci_build)
simple_build.runner_session_attributes = { url: url }
simple_build.save!
session = simple_build.reload.runner_session
expect(session).to be_a(Ci::BuildRunnerSession)
expect(session.url).to eq(url)
end
it 'updates session with new attributes' do
build.runner_session_attributes = { url: url }
build.save!
expect(build.reload.runner_session.url).to eq(url)
end
end
2018-11-08 19:23:39 +05:30
describe '#terminal_specification' do
2019-07-07 11:18:12 +05:30
let(:specification) { subject.terminal_specification }
it 'returns terminal.gitlab.com protocol' do
expect(specification[:subprotocols]).to eq ['terminal.gitlab.com']
end
it 'returns a wss url' do
expect(specification[:url]).to start_with('wss://')
end
2018-11-08 19:23:39 +05:30
it 'returns empty hash if no url' do
subject.url = ''
2019-07-07 11:18:12 +05:30
expect(specification).to be_empty
2018-11-08 19:23:39 +05:30
end
context 'when url is present' do
it 'returns ca_pem nil if empty certificate' do
subject.certificate = ''
2019-07-07 11:18:12 +05:30
expect(specification[:ca_pem]).to be_nil
2018-11-08 19:23:39 +05:30
end
it 'adds Authorization header if authorization is present' do
subject.authorization = 'whatever'
2019-07-07 11:18:12 +05:30
expect(specification[:headers]).to include(Authorization: ['whatever'])
2018-11-08 19:23:39 +05:30
end
end
end
end