Skip to content

Commit

Permalink
(FM-7691) pass a context to transport.facts
Browse files Browse the repository at this point in the history
This uses the initial `list` implementation from the previous commit to access the schema
to create a context to pass around.
  • Loading branch information
DavidS committed Jan 25, 2019
1 parent 0a04d4e commit bfe387d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/puppet/resource_api/transport/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def initialize(name, url_or_config)
end

@transport = Puppet::ResourceApi::Transport.connect(name, config)
@schema = Puppet::ResourceApi::Transport.list[name]
end

def facts
context = Puppet::ResourceApi::PuppetContext.new(@schema)
# @transport.facts + custom_facts # look into custom facts work by TP
@transport.facts(nil)
@transport.facts(context)
end

def respond_to_missing?(name, _include_private)
Expand Down
5 changes: 4 additions & 1 deletion spec/puppet/resource_api/transport/wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
describe '#facts' do
context 'when called' do
let(:instance) { described_class.new('wibble', {}) }
let(:context) { instance_double(Puppet::ResourceApi::PuppetContext, 'context') }
let(:facts) { { 'foo' => 'bar' } }
let(:transport) { instance_double(Puppet::Transport::TestDevice, 'transport') }

it 'will return the facts provided by the transport' do
allow(Puppet::ResourceApi::Transport).to receive(:connect).and_return(transport)
allow(transport).to receive(:facts).with(nil).and_return(facts)
allow(Puppet::ResourceApi::Transport).to receive(:list).and_return(schema: :dummy)
allow(Puppet::ResourceApi::PuppetContext).to receive(:new).and_return(context)
allow(transport).to receive(:facts).with(context).and_return(facts)

expect(instance.facts).to eq(facts)
end
Expand Down

0 comments on commit bfe387d

Please sign in to comment.