From a080fb18bc0cf177eb847cd585266ee6d5feb3d0 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 6 Apr 2018 15:54:54 +0100 Subject: [PATCH 1/6] Fix misleading wording in test fixture --- spec/integration/resource_api_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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', From ae35d94a1baaabeecd982489f606f2c4203c7077 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 6 Apr 2018 15:54:54 +0100 Subject: [PATCH 2/6] Fix typo --- lib/puppet/resource_api.rb | 2 +- spec/acceptance/validation_spec.rb | 4 ++-- spec/puppet/resource_api_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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/puppet/resource_api_spec.rb b/spec/puppet/resource_api_spec.rb index b194db46..c25d2989 100644 --- a/spec/puppet/resource_api_spec.rb +++ b/spec/puppet/resource_api_spec.rb @@ -195,7 +195,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 From 7ceef47819d6cfdc6e0aaccaa5681531dab68725 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 29 Mar 2018 12:10:42 +0100 Subject: [PATCH 3/6] Add some more tests to cover different representations for values --- spec/puppet/resource_api_spec.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/puppet/resource_api_spec.rb b/spec/puppet/resource_api_spec.rb index c25d2989..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', From 1b21a4a92e2382d4b7b16f397633f53aa36c2347 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 6 Apr 2018 16:19:14 +0100 Subject: [PATCH 4/6] Document new findings from PDK-895 and PDK-911 development --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac5fe01c..7cd76475 100644 --- a/README.md +++ b/README.md @@ -192,9 +192,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: From 0779fc65d57d274e8ee792acda4f721cee26346f Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 6 Apr 2018 16:34:19 +0100 Subject: [PATCH 5/6] (PDK-885) Update docs. :init_only is now fully implemented --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7cd76475..efb62346 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,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. From bd157de9b5b1dfcfe3dfbef8bfc686f7f5b8b2fb Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 6 Apr 2018 17:12:11 +0100 Subject: [PATCH 6/6] (PDK-911) Add a note about pdk-templates --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index efb62346..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: ```