-
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 #36 from DavidS/pdk-822-namevar-handling
(PDK-822) Implement proper namevar handling
- Loading branch information
Showing
9 changed files
with
162 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'test_module::titles' do | ||
it { is_expected.to compile } | ||
end |
30 changes: 30 additions & 0 deletions
30
spec/fixtures/test_module/lib/puppet/provider/title_provider/title_provider.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,30 @@ | ||
require 'puppet/resource_api' | ||
require 'puppet/resource_api/simple_provider' | ||
|
||
# Implementation for the title_provider type using the Resource API. | ||
class Puppet::Provider::TitleProvider::TitleProvider < Puppet::ResourceApi::SimpleProvider | ||
def get(_context) | ||
[ | ||
{ | ||
name: 'foo', | ||
ensure: :present, | ||
}, | ||
{ | ||
name: 'bar', | ||
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 |
21 changes: 21 additions & 0 deletions
21
spec/fixtures/test_module/lib/puppet/type/title_provider.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,21 @@ | ||
require 'puppet/resource_api' | ||
|
||
Puppet::ResourceApi.register_type( | ||
name: 'title_provider', | ||
docs: <<-EOS, | ||
This type provides Puppet with the capabilities to manage ... | ||
EOS | ||
features: [], | ||
attributes: { | ||
ensure: { | ||
type: 'Enum[present, absent]', | ||
desc: 'Whether this resource should be present or absent on the target system.', | ||
default: 'present', | ||
}, | ||
namevar: { | ||
type: 'String', | ||
desc: 'The name of the resource you want to manage.', | ||
behaviour: :namevar, | ||
}, | ||
}, | ||
) |
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,13 @@ | ||
# test_module::titles | ||
# | ||
# A description of what this class does | ||
# | ||
# @summary A short summary of the purpose of this class | ||
# | ||
# @example | ||
# include test_module::titles | ||
class test_module::titles { | ||
title_provider { 'some title': | ||
namevar => 'some id' | ||
} | ||
} |
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,11 @@ | ||
require 'spec_helper' | ||
|
||
describe 'test_module::titles' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) { os_facts } | ||
|
||
it { is_expected.to compile } | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
spec/fixtures/test_module/spec/unit/puppet/provider/title_provider/title_provider_spec.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,50 @@ | ||
require 'spec_helper' | ||
|
||
# TODO: needs some cleanup/helper to avoid this misery | ||
module Puppet::Provider::TitleProvider; end | ||
require 'puppet/provider/title_provider/title_provider' | ||
|
||
RSpec.describe Puppet::Provider::TitleProvider::TitleProvider do | ||
subject(:provider) { described_class.new } | ||
|
||
let(:context) { instance_double('Puppet::ResourceApi::BaseContext', 'context') } | ||
|
||
describe '#get' do | ||
it 'processes resources' do | ||
expect(provider.get(context)).to eq [ | ||
{ | ||
name: 'foo', | ||
ensure: :present, | ||
}, | ||
{ | ||
name: 'bar', | ||
ensure: :present, | ||
}, | ||
] | ||
end | ||
end | ||
|
||
describe 'create(context, name, should)' do | ||
it 'creates the resource' do | ||
expect(context).to receive(:notice).with(%r{\ACreating 'a'}) | ||
|
||
provider.create(context, 'a', name: 'a', ensure: 'present') | ||
end | ||
end | ||
|
||
describe 'update(context, name, should)' do | ||
it 'updates the resource' do | ||
expect(context).to receive(:notice).with(%r{\AUpdating 'foo'}) | ||
|
||
provider.update(context, 'foo', name: 'foo', ensure: 'present') | ||
end | ||
end | ||
|
||
describe 'delete(context, name, should)' do | ||
it 'deletes the resource' do | ||
expect(context).to receive(:notice).with(%r{\ADeleting 'foo'}) | ||
|
||
provider.delete(context, 'foo') | ||
end | ||
end | ||
end |
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