Set default cache key for jobs, detail:
* Replace Unspecified with a field so that it's less surprising * Define inspect for Node for easy debugging (and avoid building a very huge string potentially from built-in inspect) * Set default cache key to 'default'
This commit is contained in:
parent
bb062ebdb6
commit
6e032d7ba0
13 changed files with 62 additions and 62 deletions
|
@ -22,6 +22,16 @@ module Gitlab
|
|||
|
||||
entry :paths, Entry::Paths,
|
||||
description: 'Specify which paths should be cached across builds.'
|
||||
|
||||
helpers :key
|
||||
|
||||
def self.default
|
||||
{ key: Entry::Key.default }
|
||||
end
|
||||
|
||||
def value
|
||||
super.merge(key: key_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,9 +37,7 @@ module Gitlab
|
|||
# See issue #18775.
|
||||
#
|
||||
if @value.nil?
|
||||
Entry::Unspecified.new(
|
||||
fabricate_unspecified
|
||||
)
|
||||
fabricate_unspecified
|
||||
else
|
||||
fabricate(@entry, @value)
|
||||
end
|
||||
|
@ -56,7 +54,7 @@ module Gitlab
|
|||
fabricate(Entry::Undefined)
|
||||
else
|
||||
fabricate(@entry, @entry.default)
|
||||
end
|
||||
end.tap(&:unspecify)
|
||||
end
|
||||
|
||||
def fabricate(entry, value = nil)
|
||||
|
|
|
@ -11,6 +11,10 @@ module Gitlab
|
|||
validations do
|
||||
validates :config, key: true
|
||||
end
|
||||
|
||||
def self.default
|
||||
'default'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,7 @@ module Gitlab
|
|||
@config = config
|
||||
@metadata = metadata
|
||||
@entries = {}
|
||||
@specified = true
|
||||
|
||||
@validator = self.class.validator.new(self)
|
||||
@validator.validate(:new)
|
||||
|
@ -62,14 +63,24 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def unspecify
|
||||
@specified = false
|
||||
end
|
||||
|
||||
def specified?
|
||||
true
|
||||
@specified
|
||||
end
|
||||
|
||||
def relevant?
|
||||
true
|
||||
end
|
||||
|
||||
def inspect
|
||||
val = if leaf? then config else descendants end
|
||||
unspecified = if specified? then '' else '(unspecified) ' end
|
||||
"#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>"
|
||||
end
|
||||
|
||||
def self.default
|
||||
end
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ module Gitlab
|
|||
def relevant?
|
||||
false
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#<#{self.class.name}>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
module Gitlab
|
||||
module Ci
|
||||
class Config
|
||||
module Entry
|
||||
##
|
||||
# This class represents an unspecified entry.
|
||||
#
|
||||
# It decorates original entry adding method that indicates it is
|
||||
# unspecified.
|
||||
#
|
||||
class Unspecified < SimpleDelegator
|
||||
def specified?
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,6 +24,21 @@ describe Gitlab::Ci::Config::Entry::Cache do
|
|||
expect(entry).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'when key is missing' do
|
||||
let(:config) do
|
||||
{ untracked: true,
|
||||
paths: ['some/path/'] }
|
||||
end
|
||||
|
||||
describe '#value' do
|
||||
it 'sets key with the default' do
|
||||
value = config.merge(key: Gitlab::Ci::Config::Entry::Key.default)
|
||||
|
||||
expect(entry.value).to eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when entry value is not correct' do
|
||||
|
|
|
@ -60,13 +60,13 @@ describe Gitlab::Ci::Config::Entry::Factory do
|
|||
end
|
||||
|
||||
context 'when creating entry with nil value' do
|
||||
it 'creates an undefined entry' do
|
||||
it 'creates an unspecified entry' do
|
||||
entry = factory
|
||||
.value(nil)
|
||||
.create!
|
||||
|
||||
expect(entry)
|
||||
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
|
||||
.not_to be_specified
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ describe Gitlab::Ci::Config::Entry::Global do
|
|||
|
||||
it 'contains unspecified nodes' do
|
||||
expect(global.descendants.first)
|
||||
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
|
||||
.not_to be_specified
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -144,7 +144,8 @@ describe Gitlab::Ci::Config::Entry::Job do
|
|||
script: %w[rspec],
|
||||
commands: "ls\npwd\nrspec",
|
||||
stage: 'test',
|
||||
after_script: %w[cleanup])
|
||||
after_script: %w[cleanup],
|
||||
cache: { key: 'default' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,11 +62,13 @@ describe Gitlab::Ci::Config::Entry::Jobs do
|
|||
rspec: { name: :rspec,
|
||||
script: %w[rspec],
|
||||
commands: 'rspec',
|
||||
stage: 'test' },
|
||||
stage: 'test',
|
||||
cache: { key: 'default' } },
|
||||
spinach: { name: :spinach,
|
||||
script: %w[spinach],
|
||||
commands: 'spinach',
|
||||
stage: 'test' })
|
||||
stage: 'test',
|
||||
cache: { key: 'default' } })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,4 +31,10 @@ describe Gitlab::Ci::Config::Entry::Key do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.default' do
|
||||
it 'returns default key' do
|
||||
expect(described_class.default).to eq 'default'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Ci::Config::Entry::Unspecified do
|
||||
let(:unspecified) { described_class.new(entry) }
|
||||
let(:entry) { spy('Entry') }
|
||||
|
||||
describe '#valid?' do
|
||||
it 'delegates method to entry' do
|
||||
expect(unspecified.valid?).to eq entry
|
||||
end
|
||||
end
|
||||
|
||||
describe '#errors' do
|
||||
it 'delegates method to entry' do
|
||||
expect(unspecified.errors).to eq entry
|
||||
end
|
||||
end
|
||||
|
||||
describe '#value' do
|
||||
it 'delegates method to entry' do
|
||||
expect(unspecified.value).to eq entry
|
||||
end
|
||||
end
|
||||
|
||||
describe '#specified?' do
|
||||
it 'is always false' do
|
||||
allow(entry).to receive(:specified?).and_return(true)
|
||||
|
||||
expect(unspecified.specified?).to be false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue