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

148 lines
3.4 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'
2020-07-28 23:09:34 +05:30
RSpec.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
2020-04-22 19:07:51 +05:30
let(:config) { 'ruby:2.7' }
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
describe '#value' do
it 'returns image hash' do
2020-04-22 19:07:51 +05:30
expect(entry.value).to eq({ name: 'ruby:2.7' })
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
2020-04-22 19:07:51 +05:30
expect(entry.name).to eq 'ruby:2.7'
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 '#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
2020-04-22 19:07:51 +05:30
let(:config) { { name: 'ruby:2.7', entrypoint: %w(/bin/sh run) } }
2017-09-10 17:25:29 +05:30
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
2020-04-22 19:07:51 +05:30
expect(entry.name).to eq 'ruby:2.7'
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' }] }
2020-04-22 19:07:51 +05:30
let(:config) { { name: 'ruby:2.7', entrypoint: %w(/bin/sh run), ports: ports } }
2021-02-22 17:27:13 +05:30
let(:entry) { described_class.new(config, with_image_ports: image_ports) }
2019-07-07 11:18:12 +05:30
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
2020-04-22 19:07:51 +05:30
let(:config) { ['ruby:2.7'] }
2017-09-10 17:25:29 +05:30
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
2020-04-22 19:07:51 +05:30
let(:config) { { name: 'ruby:2.7', non_existing: 'test' } }
2017-09-10 17:25:29 +05:30
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