diff --git a/README.md b/README.md index ac5fe01c..6ab86ffd 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ pdk (INFO): Creating '.../example/spec/unit/puppet/provider/foo/foo_spec.rb' fro $ ``` +Note that the templates released with PDK 1.4 suffer from the fallout of [PDK-911](https://tickets.puppetlabs.com/browse/PDK-911), and need all occurrences of `:present` changed to `'present'`. This will be fixed in PDK 1.5. + The three generated files are the type, the implementation, and the unit tests. The default template contains an example that demonstrates the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider: ``` @@ -192,9 +194,8 @@ Currently working: * String * Integer, Float, Numeric * Boolean - * Enum - * Optional - * Variant + * Enum[absent, present] + * simple Optionals * The `canonicalize`, `simple_get_filter`, and `remote_resource` features. * All the logging facilities. * Executing the new provider under the following commands: @@ -204,7 +205,6 @@ Currently working: * `puppet device` (if applicable) There are still a few notable gaps between the implementation and the specification: -* The `:init_only` behaviour is not yet implemented ([PDK-885](https://tickets.puppetlabs.com/browse/PDK-885)) * Complex data types, like Array, Hash, Tuple or Struct are not yet implemented. * Only a single runtime environment (the Puppet commands) is currently implemented. diff --git a/lib/puppet/resource_api.rb b/lib/puppet/resource_api.rb index 372721e5..c8ea2daf 100644 --- a/lib/puppet/resource_api.rb +++ b/lib/puppet/resource_api.rb @@ -96,7 +96,7 @@ def feature_support?(feature) missing_attrs -= [:ensure] if @called_from_resource if missing_attrs.any? - error_msg = "The following mandatory attributes where not provided:\n * " + missing_attrs.join(", \n * ") + error_msg = "The following mandatory attributes were not provided:\n * " + missing_attrs.join(", \n * ") raise Puppet::ResourceError, error_msg end end diff --git a/spec/acceptance/validation_spec.rb b/spec/acceptance/validation_spec.rb index 12c492e8..bfe8e95c 100644 --- a/spec/acceptance/validation_spec.rb +++ b/spec/acceptance/validation_spec.rb @@ -22,13 +22,13 @@ context 'when listing an absent instance' do it 'requires params' do output, status = Open3.capture2e("puppet resource #{common_args} test_validation nope") - expect(output.strip).to match %r{Test_validation\[nope\] failed: The following mandatory attributes where not provided} + expect(output.strip).to match %r{Test_validation\[nope\] failed: The following mandatory attributes were not provided} expect(status.exitstatus).to eq 1 end it 'is not satisfied with params only' do output, status = Open3.capture2e("puppet resource #{common_args} test_validation nope param=2") - expect(output.strip).to match %r{Test_validation\[nope\] failed: The following mandatory attributes where not provided} + expect(output.strip).to match %r{Test_validation\[nope\] failed: The following mandatory attributes were not provided} expect(status.exitstatus).to eq 1 end end diff --git a/spec/integration/resource_api_spec.rb b/spec/integration/resource_api_spec.rb index 0ce2e08c..6ebb3364 100644 --- a/spec/integration/resource_api_spec.rb +++ b/spec/integration/resource_api_spec.rb @@ -15,36 +15,36 @@ }, string: { type: 'String', - desc: 'a string parameter', + desc: 'a string attribute', default: 'default value', }, boolean: { type: 'Boolean', - desc: 'a boolean parameter', + desc: 'a boolean attribute', }, integer: { type: 'Integer', - desc: 'an integer parameter', + desc: 'an integer attribute', }, float: { type: 'Float', - desc: 'a floating point parameter', + desc: 'a floating point attribute', }, ensure: { type: 'Enum[present, absent]', - desc: 'a ensure parameter', + desc: 'a ensure attribute', }, variant_pattern: { type: 'Variant[Pattern[/\A(0x)?[0-9a-fA-F]{8}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{16}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{40}\Z/]]', - desc: 'a pattern parameter', + desc: 'a pattern attribute', }, url: { type: 'Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/]', - desc: 'a hkp or http(s) url parameter', + desc: 'a hkp or http(s) url attribute', }, optional_string: { type: 'Optional[String]', - desc: 'a optional string parameter', + desc: 'a optional string attribute', }, string_param: { type: 'String', diff --git a/spec/puppet/resource_api_spec.rb b/spec/puppet/resource_api_spec.rb index b194db46..622d87e7 100644 --- a/spec/puppet/resource_api_spec.rb +++ b/spec/puppet/resource_api_spec.rb @@ -168,7 +168,30 @@ def extract_values(function) it('uses defaults correctly') { expect(instance[:test_string]).to eq 'default value' } - context 'when setting a value for the attributes' do + context 'when setting values for the attributes' do + let(:params) do + { + title: 'test', + test_string: 'somevalue', + test_boolean: true, + test_integer: -1, + test_float: -1.5, + test_ensure: 'present', + test_enum: 'a', + test_variant_pattern: 'a' * 8, + test_url: 'hkp://example.com', + } + end + + it('the test_string value is set correctly') { expect(instance[:test_string]).to eq 'somevalue' } + it('the test_integer value is set correctly') { expect(instance[:test_integer]).to eq(-1) } + it('the test_float value is set correctly') { expect(instance[:test_float]).to eq(-1.5) } + it('the test_ensure value is set correctly') { expect(instance[:test_ensure]).to eq('present') } + it('the test_variant_pattern value is set correctly') { expect(instance[:test_variant_pattern]).to eq('a' * 8) } + it('the test_url value is set correctly') { expect(instance[:test_url]).to eq('hkp://example.com') } + end + + context 'when setting string values for the attributes' do let(:params) do { title: 'test', @@ -195,7 +218,7 @@ def extract_values(function) context 'when mandatory attributes are missing' do let(:params) { { title: 'test' } } - it { expect { instance }.to raise_exception Puppet::ResourceError, %r{The following mandatory attributes where not provided} } + it { expect { instance }.to raise_exception Puppet::ResourceError, %r{The following mandatory attributes were not provided} } end describe 'different boolean values' do