|
4 | 4 | subject(:type) { described_class.new(definition, :attributes) } |
5 | 5 |
|
6 | 6 | 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', |
| 7 | + { name: 'some_resource', |
| 8 | + desc: 'a test type', |
| 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 | + }, |
12 | 24 | }, |
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 } |
| 25 | + features: feature_support } |
23 | 26 | end |
24 | 27 | let(:feature_support) { [] } |
25 | 28 |
|
|
76 | 79 | let(:definition) do |
77 | 80 | { |
78 | 81 | name: 'some_transport', |
| 82 | + desc: 'a test transport', |
79 | 83 | connection_info: { |
80 | 84 | username: { |
81 | 85 | type: 'String', |
|
191 | 195 | end |
192 | 196 |
|
193 | 197 | describe '#validate_schema' do |
| 198 | + let(:definition) { { name: 'some_resource', desc: 'a test resource', attributes: attributes } } |
| 199 | + |
194 | 200 | context 'when the type definition does not have a name' do |
195 | | - let(:definition) { { attributes: 'some_string' } } |
| 201 | + let(:definition) { { desc: 'a test resource', attributes: {} } } |
196 | 202 |
|
197 | 203 | it { expect { type }.to raise_error Puppet::DevError, %r{must have a name} } |
198 | 204 | end |
199 | 205 |
|
| 206 | + context 'when the type definition does not have a desc' do |
| 207 | + let(:definition) { { name: 'some_resource', attributes: {} } } |
| 208 | + |
| 209 | + it { |
| 210 | + expect(Puppet).to receive(:warning).with('`some_resource` has no documentation, add it using a `desc` key') |
| 211 | + type |
| 212 | + } |
| 213 | + end |
| 214 | + |
200 | 215 | context 'when attributes is not a hash' do |
201 | | - let(:definition) { { name: 'some_resource', attributes: 'some_string' } } |
| 216 | + let(:attributes) { 'some_string' } |
202 | 217 |
|
203 | 218 | it { expect { type }.to raise_error Puppet::DevError, %r{`some_resource.attributes` must be a hash} } |
204 | 219 | end |
205 | 220 |
|
206 | 221 | context 'when an attribute is not a hash' do |
207 | | - let(:definition) { { name: 'some_resource', attributes: { name: 'some_string' } } } |
| 222 | + let(:attributes) { { name: 'some_string' } } |
208 | 223 |
|
209 | 224 | it { expect { type }.to raise_error Puppet::DevError, %r{`some_resource.name` must be a Hash} } |
210 | 225 | end |
211 | 226 |
|
212 | 227 | context 'when an attribute has no type' do |
213 | | - let(:definition) { { name: 'some_resource', attributes: { name: { desc: 'message' } } } } |
| 228 | + let(:attributes) { { name: { desc: 'message' } } } |
214 | 229 |
|
215 | 230 | it { expect { type }.to raise_error Puppet::DevError, %r{has no type} } |
216 | 231 | end |
217 | 232 |
|
218 | | - context 'when an attribute has no descrption' do |
219 | | - let(:definition) { { name: 'some_resource', attributes: { name: { type: 'String' } } } } |
| 233 | + context 'when an attribute has no description' do |
| 234 | + let(:attributes) { { name: { type: 'String' } } } |
220 | 235 |
|
221 | | - it 'Raises a warning message' do |
222 | | - expect(Puppet).to receive(:warning).with('`some_resource.name` has no docs') |
| 236 | + it 'raises a warning message' do |
| 237 | + expect(Puppet).to receive(:warning).with('`some_resource.name` has no documentation, add it using a `desc` key') |
223 | 238 | type |
224 | 239 | end |
225 | 240 | end |
226 | 241 |
|
227 | 242 | context 'when an attribute has an unsupported type' do |
228 | | - let(:definition) { { name: 'some_resource', attributes: { name: { type: 'basic' } } } } |
| 243 | + let(:definition) { { name: 'some_resource', desc: 'a test resource', attributes: { name: { type: 'basic' } } } } |
229 | 244 |
|
230 | 245 | it { expect { type }.to raise_error %r{<basic> is not a valid type specification} } |
231 | 246 | end |
232 | 247 |
|
| 248 | + context 'with deprecated `docs` key' do |
| 249 | + let(:definition) { { name: 'some_resource', docs: 'a test resource', attributes: {} } } |
| 250 | + |
| 251 | + it 'does not raise a warning message' do |
| 252 | + expect(Puppet).not_to receive(:warning) |
| 253 | + type |
| 254 | + end |
| 255 | + |
| 256 | + it 'exposes the documentation as `desc`' do |
| 257 | + expect(type.desc).to eq 'a test resource' |
| 258 | + end |
| 259 | + end |
| 260 | + |
| 261 | + context 'with both `docs` and `desc` key' do |
| 262 | + let(:definition) { { name: 'some_resource', desc: 'the real description', docs: 'an oversight', attributes: {} } } |
| 263 | + |
| 264 | + it { expect { type }.to raise_error Puppet::DevError, %r{`some_resource` has both `desc` and `docs`, prefer using `desc`} } |
| 265 | + end |
| 266 | + |
233 | 267 | context 'with both behavior and behaviour' do |
234 | 268 | let(:definition) do |
235 | 269 | { |
236 | 270 | name: 'bad_behaviour', |
| 271 | + desc: 'a test type', |
237 | 272 | attributes: { |
238 | 273 | name: { |
239 | 274 | type: 'String', |
|
251 | 286 | let(:definition) do |
252 | 287 | { |
253 | 288 | name: 'bad_syntax', |
| 289 | + desc: 'a test type', |
254 | 290 | attributes: { |
255 | 291 | name: { |
256 | 292 | type: 'Optional[String', |
|
0 commit comments