2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe Gitlab::Ci::Config::Entry::Image do
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:entry) { described_class.new(config) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'when configuration is a string' do
|
|
|
|
let(:config) { 'ruby:2.2' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#value' do
|
|
|
|
it 'returns image hash' do
|
|
|
|
expect(entry.value).to eq({ name: 'ruby:2.2' })
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'does not append errors' do
|
|
|
|
expect(entry.errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#image' do
|
|
|
|
it "returns image's name" do
|
|
|
|
expect(entry.name).to eq 'ruby:2.2'
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#entrypoint' do
|
|
|
|
it "returns image's entrypoint" do
|
|
|
|
expect(entry.entrypoint).to be_nil
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
describe '#ports' do
|
|
|
|
it "returns image's ports" do
|
|
|
|
expect(entry.ports).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'when configuration is a hash' do
|
|
|
|
let(:config) { { name: 'ruby:2.2', entrypoint: %w(/bin/sh run) } }
|
|
|
|
|
|
|
|
describe '#value' do
|
|
|
|
it 'returns image hash' do
|
|
|
|
expect(entry.value).to eq(config)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#errors' do
|
|
|
|
it 'does not append errors' do
|
|
|
|
expect(entry.errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#image' do
|
|
|
|
it "returns image's name" do
|
|
|
|
expect(entry.name).to eq 'ruby:2.2'
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#entrypoint' do
|
|
|
|
it "returns image's entrypoint" do
|
|
|
|
expect(entry.entrypoint).to eq %w(/bin/sh run)
|
|
|
|
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) { { name: 'ruby:2.2', entrypoint: %w(/bin/sh run), 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("image 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 '#ports' do
|
|
|
|
it "returns image's ports" do
|
|
|
|
expect(entry.ports).to eq ports
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
|
|
|
let(:config) { ['ruby:2.2'] }
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'saves errors' do
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(entry.errors.first)
|
|
|
|
.to match /config should be a hash or a string/
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unexpected key is specified' do
|
|
|
|
let(:config) { { name: 'ruby:2.2', non_existing: 'test' } }
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'saves errors' do
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(entry.errors.first)
|
|
|
|
.to match /config contains unknown keys: non_existing/
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#valid?' do
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(entry).not_to be_valid
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|