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

(FM-7691,FM-7696) refactoring definition handling in contexts #150

Merged
merged 16 commits into from
Jan 28, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
(FM-7691) create and pass through context when connecting a transport
DavidS committed Jan 24, 2019
commit 9535fe36c58afdef0d7428a60339a85fceeb09e6
9 changes: 3 additions & 6 deletions lib/puppet/resource_api/transport.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# rubocop:disable Style/Documentation
module Puppet; end
module Puppet::ResourceApi; end
module Puppet::ResourceApi::Transport; end
# rubocop:enable Style/Documentation
require 'puppet/resource_api/puppet_context'

# Remote target transport API
module Puppet::ResourceApi::Transport
@@ -23,7 +19,8 @@ def connect(name, connection_info)
validate(name, connection_info)
require "puppet/transport/#{name}"
class_name = name.split('_').map { |e| e.capitalize }.join
Puppet::Transport.const_get(class_name).new(connection_info)
context = Puppet::ResourceApi::PuppetContext.new(@transports[name])
Puppet::Transport.const_get(class_name).new(context, connection_info)
end
module_function :connect # rubocop:disable Style/AccessModifierDeclarations

8 changes: 7 additions & 1 deletion spec/puppet/resource_api/transport_spec.rb
Original file line number Diff line number Diff line change
@@ -111,6 +111,8 @@
context 'when the transport file does exist' do
context 'with an incorrectly defined transport' do
it 'throws a NameError' do
described_class.register(schema)

expect(described_class).to receive(:validate).with(name, host: 'example.com')
expect(described_class).to receive(:require).with('puppet/transport/test_target')
expect { described_class.connect(name, host: 'example.com') }.to raise_error NameError,
@@ -120,13 +122,17 @@

context 'with a correctly defined transport' do
let(:test_target) { double('Puppet::Transport::TestTarget') } # rubocop:disable RSpec/VerifiedDoubles
let(:context) { instance_double(Puppet::ResourceApi::PuppetContext, 'context') }

it 'loads initiates the class successfully' do
described_class.register(schema)

expect(described_class).to receive(:require).with('puppet/transport/test_target')
expect(described_class).to receive(:validate).with(name, host: 'example.com')
expect(Puppet::ResourceApi::PuppetContext).to receive(:new).with(kind_of(Puppet::ResourceApi::TransportSchemaDef)).and_return(context)

stub_const('Puppet::Transport::TestTarget', test_target)
expect(test_target).to receive(:new).with(host: 'example.com')
expect(test_target).to receive(:new).with(context, host: 'example.com')

described_class.connect(name, host: 'example.com')
end