debian-mirror-gitlab/spec/lib/gitlab/ci/build/image_spec.rb

136 lines
4.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Build::Image do
2017-08-17 22:00:37 +05:30
let(:job) { create(:ci_build, :no_options) }
describe '#from_image' do
subject { described_class.from_image(job) }
context 'when image is defined in job' do
2020-04-22 19:07:51 +05:30
let(:image_name) { 'ruby:2.7' }
2017-08-17 22:00:37 +05:30
let(:job) { create(:ci_build, options: { image: image_name } ) }
2017-09-10 17:25:29 +05:30
context 'when image is defined as string' do
it 'fabricates an object of the proper class' do
is_expected.to be_kind_of(described_class)
end
it 'populates fabricated object with the proper name attribute' do
expect(subject.name).to eq(image_name)
end
2019-07-07 11:18:12 +05:30
it 'does not populate the ports' do
expect(subject.ports).to be_empty
end
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context 'when image is defined as hash' do
let(:entrypoint) { '/bin/sh' }
2019-07-07 11:18:12 +05:30
let(:job) { create(:ci_build, options: { image: { name: image_name, entrypoint: entrypoint, ports: [80] } } ) }
2017-09-10 17:25:29 +05:30
it 'fabricates an object of the proper class' do
is_expected.to be_kind_of(described_class)
end
it 'populates fabricated object with the proper attributes' do
expect(subject.name).to eq(image_name)
expect(subject.entrypoint).to eq(entrypoint)
end
2019-07-07 11:18:12 +05:30
it 'populates the ports' do
port = subject.ports.first
expect(port.number).to eq 80
expect(port.protocol).to eq 'http'
expect(port.name).to eq 'default_port'
end
2017-08-17 22:00:37 +05:30
end
context 'when image name is empty' do
let(:image_name) { '' }
it 'does not fabricate an object' do
is_expected.to be_nil
end
end
end
context 'when image is not defined in job' do
it 'does not fabricate an object' do
is_expected.to be_nil
end
end
end
describe '#from_services' do
subject { described_class.from_services(job) }
context 'when services are defined in job' do
let(:service_image_name) { 'postgres' }
let(:job) { create(:ci_build, options: { services: [service_image_name] }) }
2017-09-10 17:25:29 +05:30
context 'when service is defined as string' do
it 'fabricates an non-empty array of objects' do
is_expected.to be_kind_of(Array)
is_expected.not_to be_empty
end
it 'populates fabricated objects with the proper name attributes' do
expect(subject.first).to be_kind_of(described_class)
expect(subject.first.name).to eq(service_image_name)
end
2019-07-07 11:18:12 +05:30
it 'does not populate the ports' do
expect(subject.first.ports).to be_empty
end
2017-09-10 17:25:29 +05:30
end
context 'when service is defined as hash' do
let(:service_entrypoint) { '/bin/sh' }
let(:service_alias) { 'db' }
let(:service_command) { 'sleep 30' }
let(:job) do
create(:ci_build, options: { services: [{ name: service_image_name, entrypoint: service_entrypoint,
2019-07-07 11:18:12 +05:30
alias: service_alias, command: service_command, ports: [80] }] })
2017-09-10 17:25:29 +05:30
end
it 'fabricates an non-empty array of objects' do
is_expected.to be_kind_of(Array)
is_expected.not_to be_empty
expect(subject.first).to be_kind_of(described_class)
end
it 'populates fabricated objects with the proper attributes' do
expect(subject.first.name).to eq(service_image_name)
expect(subject.first.entrypoint).to eq(service_entrypoint)
expect(subject.first.alias).to eq(service_alias)
expect(subject.first.command).to eq(service_command)
2019-07-07 11:18:12 +05:30
port = subject.first.ports.first
expect(port.number).to eq 80
expect(port.protocol).to eq 'http'
expect(port.name).to eq 'default_port'
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
end
context 'when service image name is empty' do
let(:service_image_name) { '' }
it 'fabricates an empty array' do
is_expected.to be_kind_of(Array)
is_expected.to be_empty
end
end
end
context 'when services are not defined in job' do
it 'fabricates an empty array' do
is_expected.to be_kind_of(Array)
is_expected.to be_empty
end
end
end
end