Implement CI/CD kubernetes policy specification

This commit is contained in:
Grzegorz Bizon 2017-09-14 10:52:25 +02:00
parent bff004d44b
commit 59f87e7317
3 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,19 @@
module Gitlab
module Ci
module Build
module Policy
class Kubernetes < Policy::Specification
def initialize(spec)
unless spec.to_sym == :active
raise UnknownPolicyError
end
end
def satisfied_by?(pipeline, **_)
pipeline.has_kubernetes_active?
end
end
end
end
end
end

View file

@ -0,0 +1,28 @@
module Gitlab
module Ci
module Build
module Policy
##
# Abstract class that defines an intereface of job policy
# specification.
#
# Used for job's only/except policy configuration.
#
class Specification
UnknownPolicyError = Class.new(StandardError)
def initialize(spec)
@spec = spec
end
def satisfied_by?(pipeline, **metadata)
raise NotImplementedError
end
def self.fabricate_all(*specs)
end
end
end
end
end
end

View file

@ -0,0 +1,30 @@
require 'spec_helper'
describe Gitlab::Ci::Build::Policy::Kubernetes do
let(:pipeline) { create(:ci_pipeline, project: project) }
context 'when kubernetes service is active' do
set(:project) { create(:kubernetes_project) }
it 'is satisfied by a kubernetes pipeline' do
expect(described_class.new('active'))
.to be_satisfied_by(pipeline)
end
end
context 'when kubernetes service is inactive' do
set(:project) { create(:project) }
it 'is not satisfied by a pipeline without kubernetes available' do
expect(described_class.new('active'))
.not_to be_satisfied_by(pipeline)
end
end
context 'when kubernetes policy is invalid' do
it 'raises an error' do
expect { described_class.new('unknown') }
.to raise_error described_class::UnknownPolicyError
end
end
end