debian-mirror-gitlab/spec/lib/gitlab/ci/config/entry/services_spec.rb

125 lines
3.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe Gitlab::Ci::Config::Entry::Services do
2016-08-24 12:49:21 +05:30
let(:entry) { described_class.new(config) }
2017-09-10 17:25:29 +05:30
before do
entry.compose!
end
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
context 'when configuration is valid' do
let(:config) { ['postgresql:9.5', { name: 'postgresql:9.1', alias: 'postgres_old' }] }
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
2016-08-24 12:49:21 +05:30
end
end
2017-09-10 17:25:29 +05:30
describe '#value' do
it 'returns valid array' do
expect(entry.value).to eq([{ name: 'postgresql:9.5' }, { name: 'postgresql:9.1', alias: 'postgres_old' }])
2016-08-24 12:49:21 +05:30
end
2017-09-10 17:25:29 +05:30
end
end
context 'when configuration is invalid' do
let(:config) { 'postgresql:9.5' }
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
describe '#valid?' do
it 'is invalid' do
expect(entry).not_to be_valid
2016-08-24 12:49:21 +05:30
end
end
end
2019-07-07 11:18:12 +05:30
context 'when configuration has ports' do
let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] }
let(:config) { ['postgresql:9.5', { name: 'postgresql:9.1', alias: 'postgres_old', ports: ports }] }
let(:entry) { described_class.new(config, { with_image_ports: image_ports }) }
let(:image_ports) { false }
context 'when with_image_ports metadata is not enabled' do
describe '#valid?' do
it 'is not valid' do
expect(entry).not_to be_valid
expect(entry.errors).to include("service config contains disallowed keys: ports")
end
end
end
context 'when with_image_ports metadata is enabled' do
let(:image_ports) { true }
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
describe '#value' do
it 'returns valid array' do
expect(entry.value).to eq([{ name: 'postgresql:9.5' }, { name: 'postgresql:9.1', alias: 'postgres_old', ports: ports }])
end
end
describe 'services alias' do
context 'when they are not unique' do
let(:config) do
['postgresql:9.5',
{ name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] },
{ name: 'ruby', alias: 'postgres_old', ports: [81] }]
end
describe '#valid?' do
it 'is invalid' do
expect(entry).not_to be_valid
expect(entry.errors).to include("services config alias must be unique in services with ports")
end
end
end
context 'when they are unique' do
let(:config) do
['postgresql:9.5',
{ name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] },
{ name: 'ruby', alias: 'ruby', ports: [81] }]
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when one of the duplicated alias is in a service without ports' do
let(:config) do
['postgresql:9.5',
{ name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] },
{ name: 'ruby', alias: 'postgres_old' }]
end
it 'is valid' do
expect(entry).to be_valid
end
end
context 'when there are not any ports' do
let(:config) do
['postgresql:9.5',
{ name: 'postgresql:9.1', alias: 'postgres_old' },
{ name: 'ruby', alias: 'postgres_old' }]
end
it 'is valid' do
expect(entry).to be_valid
end
end
end
end
end
2016-08-24 12:49:21 +05:30
end