Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes #56

Merged
merged 6 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/resource_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/integration/resource_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
27 changes: 25 additions & 2 deletions spec/puppet/resource_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down