-
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 #37 from da-ar/simple_get_filter
(PDK-512) Add support for simple_get_filter
- Loading branch information
Showing
9 changed files
with
250 additions
and
13 deletions.
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
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,39 @@ | ||
require 'spec_helper' | ||
|
||
require 'open3' | ||
require 'tempfile' | ||
|
||
RSpec.describe 'exercising simple_get_filter' do | ||
let(:common_args) { '--verbose --debug --trace --modulepath spec/fixtures' } | ||
|
||
describe 'using `puppet resource`' do | ||
context 'when using `get` to access all resources' do | ||
it 'does not receive names array' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter") | ||
|
||
expect(stdout_str.strip).to match %r{^test_simple_get_filter \{ \"bar\"} | ||
expect(stdout_str.strip).to match %r{^test_simple_get_filter \{ \"foo\"} | ||
expect(status).to eq 0 | ||
end | ||
end | ||
|
||
context 'when using `get` to access a specific resource' do | ||
it 'does not receive names array' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter foo") | ||
|
||
expect(stdout_str.strip).to match %r{test_string\s*=>\s*'default'} | ||
expect(status).to eq 0 | ||
end | ||
end | ||
|
||
context 'when using `get` to access a specific resource' do | ||
it 'receives names array' do | ||
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter foo ensure=absent") | ||
|
||
expect(stdout_str.strip).to match %r{ensure\s*=>\s*'absent'} | ||
expect(stdout_str.strip).to match %r{test_string\s*=>\s*'foo found'} | ||
expect(status).to eq 0 | ||
end | ||
end | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
...fixtures/test_module/lib/puppet/provider/test_simple_get_filter/test_simple_get_filter.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,47 @@ | ||
require 'puppet/resource_api' | ||
require 'puppet/resource_api/simple_provider' | ||
|
||
# Implementation for the test_simple_get_filter type using the Resource API. | ||
class Puppet::Provider::TestSimpleGetFilter::TestSimpleGetFilter < Puppet::ResourceApi::SimpleProvider | ||
def get(_context, names = nil) | ||
if names.nil? | ||
[ | ||
{ | ||
name: 'bar', | ||
ensure: :present, | ||
test_string: 'default' | ||
}, | ||
{ | ||
name: 'foo', | ||
ensure: :present, | ||
test_string: 'default' | ||
}, | ||
] | ||
elsif names.include?('foo') | ||
[ | ||
{ | ||
name: 'foo', | ||
ensure: :absent, | ||
test_string: 'foo found' | ||
} | ||
] | ||
else | ||
[ | ||
{ | ||
name: 'foo', | ||
ensure: :present, | ||
test_string: 'not foo' | ||
} | ||
] | ||
end | ||
end | ||
|
||
def create(_context, _name, _should) | ||
end | ||
|
||
def update(_context, _name, _should) | ||
end | ||
|
||
def delete(_context, _name) | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
spec/fixtures/test_module/lib/puppet/type/test_simple_get_filter.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: 'test_simple_get_filter', | ||
docs: <<-EOS, | ||
This type provides Puppet with the capabilities to manage ... | ||
EOS | ||
features: ['simple_get_filter'], | ||
attributes: { | ||
ensure: { | ||
type: 'Enum[present, absent]', | ||
desc: 'Whether this resource should be present or absent on the target system.', | ||
default: 'present', | ||
}, | ||
name: { | ||
type: 'String', | ||
desc: 'The name of the resource you want to manage.', | ||
behaviour: :namevar, | ||
}, | ||
test_string: { | ||
type: 'String', | ||
desc: 'Used for testing our expected outcomes', | ||
}, | ||
}, | ||
) |
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
Oops, something went wrong.