2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
require 'spec_helper'
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Config::Entry::Image do
|
2022-07-23 23:45:48 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_docker_image_pull_policy: true)
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
entry.compose!
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
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
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:config) { 'image:1.0' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#value' do
|
|
|
|
it 'returns image hash' do
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(entry.value).to eq({ name: 'image:1.0' })
|
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
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(entry.name).to eq 'image:1.0'
|
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
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
describe '#pull_policy' do
|
|
|
|
it "returns nil" do
|
|
|
|
expect(entry.pull_policy).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
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:config) { { name: 'image:1.0', 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
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(entry.name).to eq 'image:1.0'
|
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' }] }
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:config) { { name: 'image:1.0', 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
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
context 'when configuration has pull_policy' do
|
|
|
|
let(:config) { { name: 'image:1.0', pull_policy: 'if-not-present' } }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the feature flag ci_docker_image_pull_policy is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_docker_image_pull_policy: false)
|
2022-08-13 15:12:31 +05:30
|
|
|
entry.compose!
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include('image config contains unknown keys: pull_policy')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#value' do
|
|
|
|
it "returns value" do
|
|
|
|
expect(entry.value).to eq(
|
|
|
|
name: 'image:1.0',
|
|
|
|
pull_policy: ['if-not-present']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the feature flag ci_docker_image_pull_policy is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_docker_image_pull_policy: false)
|
2022-08-13 15:12:31 +05:30
|
|
|
entry.compose!
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(entry.value).to eq(
|
|
|
|
name: 'image:1.0'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:config) { ['image:1.0'] }
|
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
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:config) { { name: 'image:1.0', 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
|