Commit 0778cad2 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Do not use GITLAB_RELEASE env to define QA strategy

[ci skip]
parent 175a3dfd
FROM ruby:2.3
LABEL maintainer "Grzegorz Bizon <grzegorz@gitlab.com>"
ENV GITLAB_RELEASE CE
RUN sed -i "s/httpredir.debian.org/ftp.us.debian.org/" /etc/apt/sources.list && \
apt-get update && apt-get install -y --force-yes \
libqt5webkit5-dev qt5-qmake qt5-default build-essential xvfb git && \
......
......@@ -2,35 +2,32 @@ module QA
module Runtime
##
# Class that is responsible for plugging CE/EE extensions in, depending on
# environment variable GITLAB_RELEASE that should be present in the runtime
# environment.
# existence of EE module.
#
# We need that to reduce the probability of conflicts when merging
# CE to EE.
#
class Release
UnspecifiedReleaseError = Class.new(StandardError)
def initialize(version = ENV['GITLAB_RELEASE'])
@version = version.to_s.upcase
unless %w[CE EE].include?(@version)
raise UnspecifiedReleaseError, 'GITLAB_RELEASE env not defined!'
end
def initialize(variant = nil)
@version = variant || version
begin
require "qa/#{version.downcase}/strategy"
require "qa/#{@version.downcase}/strategy"
rescue LoadError
# noop
end
end
def version
File.directory?("#{__dir__}/../ee") ? :EE : :CE
end
def has_strategy?
QA.const_defined?("#{@version}::Strategy")
QA.const_defined?("QA::#{@version}::Strategy")
end
def strategy
QA.const_get("#{@version}::Strategy")
QA.const_get("QA::#{@version}::Strategy")
end
def self.method_missing(name, *args)
......
describe QA::Runtime::Release do
context 'when release version has extension strategy' do
subject { described_class.new('CE') }
let(:strategy) { spy('CE::Strategy') }
subject { described_class.new('VER') }
let(:strategy) { spy('VER::Strategy') }
before do
stub_const('QA::CE::Strategy', strategy)
stub_const('QA::EE::Strategy', strategy)
stub_const('QA::VER::Strategy', strategy)
end
describe '#has_strategy?' do
......@@ -16,11 +15,19 @@
describe '#strategy' do
it 'return the strategy constant' do
expect(subject.strategy).to eq QA::CE::Strategy
expect(subject.strategy).to eq QA::VER::Strategy
end
end
describe 'delegated class methods' do
before do
allow_any_instance_of(described_class)
.to receive(:has_strategy?).and_return(true)
allow_any_instance_of(described_class)
.to receive(:strategy).and_return(strategy)
end
it 'delegates all calls to strategy class' do
described_class.some_method(1, 2)
......@@ -31,12 +38,7 @@
end
context 'when release version does not have extension strategy' do
subject { described_class.new('CE') }
before do
hide_const('QA::CE::Strategy')
hide_const('QA::EE::Strategy')
end
subject { described_class.new('NOVER') }
describe '#has_strategy?' do
it 'returns false' do
......@@ -50,18 +52,23 @@
end
end
describe 'delegated class methods' do
describe 'does not delegate class methods' do
before do
allow_any_instance_of(described_class)
.to receive(:has_strategy?).and_return(false)
end
it 'behaves like a null object and does nothing' do
expect { described_class.some_method(2, 3) }.not_to raise_error
end
end
end
context 'when release version is invalid or unspecified' do
describe '#new' do
it 'raises an exception' do
expect { described_class.new(nil) }
.to raise_error(described_class::UnspecifiedReleaseError)
it 'returns nil' do
expect(described_class.something).to be_nil
end
it 'does not delegate to strategy object' do
expect_any_instance_of(described_class)
.not_to receive(:strategy)
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment