Commit 6e032d7b authored by Lin Jen-Shin's avatar Lin Jen-Shin

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'
parent bb062ebd
...@@ -22,6 +22,16 @@ module Gitlab ...@@ -22,6 +22,16 @@ module Gitlab
entry :paths, Entry::Paths, entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.' 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 end
end end
......
...@@ -37,9 +37,7 @@ module Gitlab ...@@ -37,9 +37,7 @@ module Gitlab
# See issue #18775. # See issue #18775.
# #
if @value.nil? if @value.nil?
Entry::Unspecified.new( fabricate_unspecified
fabricate_unspecified
)
else else
fabricate(@entry, @value) fabricate(@entry, @value)
end end
...@@ -56,7 +54,7 @@ module Gitlab ...@@ -56,7 +54,7 @@ module Gitlab
fabricate(Entry::Undefined) fabricate(Entry::Undefined)
else else
fabricate(@entry, @entry.default) fabricate(@entry, @entry.default)
end end.tap(&:unspecify)
end end
def fabricate(entry, value = nil) def fabricate(entry, value = nil)
......
...@@ -11,6 +11,10 @@ module Gitlab ...@@ -11,6 +11,10 @@ module Gitlab
validations do validations do
validates :config, key: true validates :config, key: true
end end
def self.default
'default'
end
end end
end end
end end
......
...@@ -15,6 +15,7 @@ module Gitlab ...@@ -15,6 +15,7 @@ module Gitlab
@config = config @config = config
@metadata = metadata @metadata = metadata
@entries = {} @entries = {}
@specified = true
@validator = self.class.validator.new(self) @validator = self.class.validator.new(self)
@validator.validate(:new) @validator.validate(:new)
...@@ -62,14 +63,24 @@ module Gitlab ...@@ -62,14 +63,24 @@ module Gitlab
end end
end end
def unspecify
@specified = false
end
def specified? def specified?
true @specified
end end
def relevant? def relevant?
true true
end 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 def self.default
end end
......
...@@ -29,6 +29,10 @@ module Gitlab ...@@ -29,6 +29,10 @@ module Gitlab
def relevant? def relevant?
false false
end end
def inspect
"#<#{self.class.name}>"
end
end end
end end
end end
......
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 ...@@ -24,6 +24,21 @@ describe Gitlab::Ci::Config::Entry::Cache do
expect(entry).to be_valid expect(entry).to be_valid
end end
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 end
context 'when entry value is not correct' do context 'when entry value is not correct' do
......
...@@ -60,13 +60,13 @@ describe Gitlab::Ci::Config::Entry::Factory do ...@@ -60,13 +60,13 @@ describe Gitlab::Ci::Config::Entry::Factory do
end end
context 'when creating entry with nil value' do context 'when creating entry with nil value' do
it 'creates an undefined entry' do it 'creates an unspecified entry' do
entry = factory entry = factory
.value(nil) .value(nil)
.create! .create!
expect(entry) expect(entry)
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified .not_to be_specified
end end
end end
......
...@@ -186,7 +186,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -186,7 +186,7 @@ describe Gitlab::Ci::Config::Entry::Global do
it 'contains unspecified nodes' do it 'contains unspecified nodes' do
expect(global.descendants.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified .not_to be_specified
end end
end end
......
...@@ -144,7 +144,8 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -144,7 +144,8 @@ describe Gitlab::Ci::Config::Entry::Job do
script: %w[rspec], script: %w[rspec],
commands: "ls\npwd\nrspec", commands: "ls\npwd\nrspec",
stage: 'test', stage: 'test',
after_script: %w[cleanup]) after_script: %w[cleanup],
cache: { key: 'default' })
end end
end end
end end
......
...@@ -62,11 +62,13 @@ describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -62,11 +62,13 @@ describe Gitlab::Ci::Config::Entry::Jobs do
rspec: { name: :rspec, rspec: { name: :rspec,
script: %w[rspec], script: %w[rspec],
commands: 'rspec', commands: 'rspec',
stage: 'test' }, stage: 'test',
cache: { key: 'default' } },
spinach: { name: :spinach, spinach: { name: :spinach,
script: %w[spinach], script: %w[spinach],
commands: 'spinach', commands: 'spinach',
stage: 'test' }) stage: 'test',
cache: { key: 'default' } })
end end
end end
......
...@@ -31,4 +31,10 @@ describe Gitlab::Ci::Config::Entry::Key do ...@@ -31,4 +31,10 @@ describe Gitlab::Ci::Config::Entry::Key do
end end
end end
end end
describe '.default' do
it 'returns default key' do
expect(described_class.default).to eq 'default'
end
end
end end
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
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