Skip to content

Commit 461d24c

Browse files
committed
Merge remote-tracking branch 'upstream/1.6.x'
2 parents 4836e85 + a1d9de2 commit 461d24c

File tree

7 files changed

+71
-25
lines changed

7 files changed

+71
-25
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ group :tests do
1212
# rubocop 0.58 throws when testing against ruby 2.1, so pin to the latest,
1313
# unless we're dealing with jruby...
1414
if RUBY_PLATFORM == 'java'
15-
# load any rubocop version that works on java for the Rakefile
15+
# load a rubocop version that works on java for the Rakefile
1616
gem 'parser', '2.3.3.1'
1717
gem 'rubocop', '0.41.2'
1818
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')

lib/puppet/resource_api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def register_type(definition)
3535
end
3636

3737
Puppet::Type.newtype(definition[:name].to_sym) do
38-
@docs = definition[:docs]
38+
@docs = definition[:desc]
3939
@type_definition = type_def
4040

4141
# Keeps a copy of the provider around. Weird naming to avoid clashes with puppet's own `provider` member

lib/puppet/resource_api/type_definition.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ def validate_schema(definition, attr_key)
101101
}
102102
end
103103

104+
# fixup desc/docs backwards compatibility
105+
if definition.key? :docs
106+
if definition[:desc]
107+
raise Puppet::DevError, '`%{name}` has both `desc` and `docs`, prefer using `desc`' % { name: definition[:name] }
108+
end
109+
definition[:desc] = definition[:docs]
110+
definition.delete(:docs)
111+
end
112+
Puppet.warning('`%{name}` has no documentation, add it using a `desc` key' % { name: definition[:name] }) unless definition.key? :desc
113+
104114
attributes.each do |key, attr|
105115
raise Puppet::DevError, "`#{definition[:name]}.#{key}` must be a Hash, not a #{attr.class}" unless attr.is_a? Hash
106116
raise Puppet::DevError, "`#{definition[:name]}.#{key}` has no type" unless attr.key? :type
107-
Puppet.warning("`#{definition[:name]}.#{key}` has no docs") unless attr.key? :desc
117+
Puppet.warning('`%{name}.%{key}` has no documentation, add it using a `desc` key' % { name: definition[:name], key: key }) unless attr.key? :desc
108118

109119
# validate the type by attempting to parse into a puppet type
110120
@data_type_cache[attributes[key][:type]] ||=

spec/puppet/resource_api/base_context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def send_log(log, msg)
1313
TestContext.new(definition)
1414
end
1515

16-
let(:definition_hash) { { name: 'some_resource', attributes: { name: { type: 'String', desc: 'message' } }, features: feature_support } }
16+
let(:definition_hash) { { name: 'some_resource', desc: 'a test resource', attributes: { name: { type: 'String', desc: 'message' } }, features: feature_support } }
1717
let(:definition) { Puppet::ResourceApi::TypeDefinition.new(definition_hash) }
1818
let(:feature_support) { [] }
1919

spec/puppet/resource_api/base_type_definition_spec.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
subject(:type) { described_class.new(definition, :attributes) }
55

66
let(:definition) do
7-
{ name: 'some_resource', attributes: {
8-
ensure: {
9-
type: 'Enum[present, absent]',
10-
desc: 'Whether this resource should be present or absent on the target system.',
11-
default: 'present',
12-
},
13-
name: {
14-
type: 'String',
15-
desc: 'The name of the resource you want to manage.',
16-
behaviour: :namevar,
17-
},
18-
prop: {
19-
type: 'Integer',
20-
desc: 'A mandatory property, that MUST NOT be validated on deleting.',
21-
},
22-
}, features: feature_support }
7+
{ name: 'some_resource',
8+
desc: 'some desc',
9+
attributes: {
10+
ensure: {
11+
type: 'Enum[present, absent]',
12+
desc: 'Whether this resource should be present or absent on the target system.',
13+
default: 'present',
14+
},
15+
name: {
16+
type: 'String',
17+
desc: 'The name of the resource you want to manage.',
18+
behaviour: :namevar,
19+
},
20+
prop: {
21+
type: 'Integer',
22+
desc: 'A mandatory property, that MUST NOT be validated on deleting.',
23+
},
24+
}, features: feature_support }
2325
end
2426
let(:feature_support) { [] }
2527

@@ -76,6 +78,7 @@
7678
let(:definition) do
7779
{
7880
name: 'some_transport',
81+
desc: 'some desc',
7982
connection_info: {
8083
username: {
8184
type: 'String',
@@ -216,10 +219,10 @@
216219
end
217220

218221
context 'when an attribute has no descrption' do
219-
let(:definition) { { name: 'some_resource', attributes: { name: { type: 'String' } } } }
222+
let(:definition) { { name: 'some_resource', desc: 'some desc', attributes: { name: { type: 'String' } } } }
220223

221224
it 'Raises a warning message' do
222-
expect(Puppet).to receive(:warning).with('`some_resource.name` has no docs')
225+
expect(Puppet).to receive(:warning).with('`some_resource.name` has no documentation, add it using a `desc` key')
223226
type
224227
end
225228
end

spec/puppet/resource_api/puppet_context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe Puppet::ResourceApi::PuppetContext do
44
subject(:context) { described_class.new(definition) }
55

6-
let(:definition) { { name: 'some_resource', attributes: {} } }
6+
let(:definition) { { name: 'some_resource', desc: 'a test resource', attributes: {} } }
77

88
describe '#device' do
99
context 'when a NetworkDevice is configured' do

spec/puppet/resource_api_spec.rb

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
context 'when registering a minimal type' do
2626
let(:definition) { { name: 'minimal', attributes: {} } }
2727

28-
it { expect { described_class.register_type(definition) }.not_to raise_error }
28+
it {
29+
expect(Puppet).to receive(:warning).with('`minimal` has no documentation, add it using a `desc` key')
30+
described_class.register_type(definition)
31+
}
2932

3033
describe 'the registered type' do
3134
subject(:type) { Puppet::Type.type(:minimal) }
@@ -40,10 +43,33 @@
4043
end
4144
end
4245

46+
context 'when registering a type with both desc and docs key' do
47+
let(:definition) { { name: 'both', desc: 'the desc', docs: 'the docs', attributes: {} } }
48+
49+
it {
50+
expect { described_class.register_type(definition) }.to raise_error Puppet::DevError, '`both` has both `desc` and `docs`, prefer using `desc`'
51+
}
52+
end
53+
54+
context 'when registering a type with a docs key' do
55+
let(:definition) { { name: 'both', docs: 'the docs', attributes: {} } }
56+
57+
it { expect { described_class.register_type(definition) }.not_to raise_error }
58+
59+
describe 'the registered type' do
60+
subject(:type) { Puppet::Type.type(:both) }
61+
62+
it { is_expected.not_to be_nil }
63+
it { is_expected.to be_respond_to :instances }
64+
it { expect(type.instance_variable_get(:@docs)).to eq 'the docs' }
65+
end
66+
end
67+
4368
context 'when registering a type with multiple attributes' do
4469
let(:definition) do
4570
{
4671
name: type_name,
72+
desc: 'a test resource',
4773
attributes: {
4874
name: {
4975
type: 'String',
@@ -747,6 +773,7 @@ def set(_context, _changes); end
747773
let(:definition) do
748774
{
749775
name: 'init_behaviour',
776+
desc: 'a test resource',
750777
attributes: {
751778
ensure: {
752779
type: 'Enum[present, absent]',
@@ -1172,7 +1199,7 @@ def set(_context, _changes); end
11721199
context 'when loading a provider that doesn\'t create the correct class' do
11731200
let(:definition) { { name: 'no_class', attributes: {} } }
11741201

1175-
it { expect { described_class.load_provider('no_class') }.to raise_error Puppet::DevError, %r{Puppet::Provider::NoClass::NoClass} }
1202+
it { expect { described_class.load_provider('no_class') }.to raise_error Puppet::DevError, %r{provider class Puppet::Provider::NoClass::NoClass not found} }
11761203
end
11771204

11781205
context 'when loading a provider that creates the correct class' do
@@ -1792,6 +1819,7 @@ def set(_context, changes) end
17921819
let(:definition) do
17931820
{
17941821
name: 'test_noop_support',
1822+
desc: 'a test resource',
17951823
features: ['no such feature'],
17961824
attributes: {},
17971825
}
@@ -1808,6 +1836,7 @@ def set(_context, changes) end
18081836
let(:definition) do
18091837
{
18101838
name: 'test_behaviour',
1839+
desc: 'a test resource',
18111840
attributes: {
18121841
id: {
18131842
type: 'String',
@@ -1824,6 +1853,7 @@ def set(_context, changes) end
18241853
let(:definition) do
18251854
{
18261855
name: 'test_behaviour',
1856+
desc: 'a test resource',
18271857
attributes: {
18281858
param: {
18291859
type: 'String',
@@ -1840,6 +1870,7 @@ def set(_context, changes) end
18401870
let(:definition) do
18411871
{
18421872
name: 'test_behaviour',
1873+
desc: 'a test resource',
18431874
attributes: {
18441875
param_ro: {
18451876
type: 'String',
@@ -1856,6 +1887,7 @@ def set(_context, changes) end
18561887
let(:definition) do
18571888
{
18581889
name: 'test_behaviour',
1890+
desc: 'a test resource',
18591891
attributes: {
18601892
param_ro: {
18611893
type: 'String',
@@ -1872,6 +1904,7 @@ def set(_context, changes) end
18721904
let(:definition) do
18731905
{
18741906
name: 'test_behaviour',
1907+
desc: 'a test resource',
18751908
attributes: {
18761909
source: {
18771910
type: 'String',

0 commit comments

Comments
 (0)