-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from da-ar/multiple_namevars
(PDK-889) Read-only support for multiple namevars
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
require 'open3' | ||
|
||
RSpec.describe 'type with multiple namevars' do | ||
let(:common_args) { '--verbose --trace --modulepath spec/fixtures' } | ||
|
||
describe 'using `puppet resource`' do | ||
it 'is returns the values correctly' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} multiple_namevar") | ||
expect(stdout_str.strip).to match %r{^multiple_namevar} | ||
expect(status).to eq 0 | ||
end | ||
it 'is returns the required resource correctly' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} multiple_namevar yum") | ||
expect(stdout_str.strip).to match %r{^multiple_namevar \{ \'yum\'} | ||
expect(stdout_str.strip).to match %r{ensure => \'present\'} | ||
expect(status).to eq 0 | ||
end | ||
it 'does not match the first namevar' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} multiple_namevar php") | ||
expect(stdout_str.strip).to match %r{^multiple_namevar \{ \'php\'} | ||
expect(stdout_str.strip).to match %r{ensure => \'absent\'} | ||
expect(status).to eq 0 | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
spec/fixtures/test_module/lib/puppet/provider/multiple_namevar/multiple_namevar.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'puppet/resource_api' | ||
require 'puppet/resource_api/simple_provider' | ||
|
||
# Implementation for the title_provider type using the Resource API. | ||
class Puppet::Provider::MultipleNamevar::MultipleNamevar < Puppet::ResourceApi::SimpleProvider | ||
|
||
def get(_context) | ||
[ | ||
{ package: 'php', manager: 'yum', ensure: 'present', }, | ||
{ package: 'php', manager: 'gem', ensure: 'present', }, | ||
{ package: 'mysql', manager: 'yum', ensure: 'present', }, | ||
{ package: 'mysql', manager: 'gem', ensure: 'present', }, | ||
{ package: 'foo', manager: 'bar', ensure: 'present', }, | ||
{ package: 'bar', manager: 'foo', ensure: 'present', }, | ||
] | ||
end | ||
|
||
def create(context, name, should) | ||
context.notice("Creating '#{name}' with #{should.inspect}") | ||
end | ||
|
||
def update(context, name, should) | ||
context.notice("Updating '#{name}' with #{should.inspect}") | ||
end | ||
|
||
def delete(context, name) | ||
context.notice("Deleting '#{name}'") | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
spec/fixtures/test_module/lib/puppet/type/multiple_namevar.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'puppet/resource_api' | ||
|
||
Puppet::ResourceApi.register_type( | ||
name: 'multiple_namevar', | ||
docs: <<-EOS, | ||
This type provides Puppet with the capabilities to manage ... | ||
EOS | ||
attributes: { | ||
ensure: { | ||
type: 'Enum[present, absent]', | ||
desc: 'Whether this resource should be present or absent on the target system.', | ||
default: 'present', | ||
}, | ||
package: { | ||
type: 'String', | ||
desc: 'The name of the file you want to manage.', | ||
behaviour: :namevar, | ||
}, | ||
manager: { | ||
type: 'String', | ||
desc: 'The directory containing the resource you want to manage.', | ||
behaviour: :namevar, | ||
}, | ||
}, | ||
) |