Skip to content

Commit

Permalink
(FM-7691) Load the schema before trying to validate connection_info
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jan 23, 2019
1 parent 9d549c0 commit 383028a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/puppet/resource_api/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def connect(name, connection_info)

def self.validate(name, connection_info)
@transports ||= {}
require "puppet/transport/schema/#{name}" unless @transports.key? name
transport_schema = @transports[name]
raise Puppet::DevError, 'Transport for `%{target}` not registered' % { target: name } if transport_schema.nil?

Expand Down
17 changes: 10 additions & 7 deletions spec/puppet/resource_api/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,22 @@

describe '#self.validate' do
context 'when the transport being validated has not be registered' do
it { expect { described_class.validate('wibble', {}) }.to raise_error Puppet::DevError, %r{Transport for `wibble` not registered} }
it { expect { described_class.validate('wibble', {}) }.to raise_error LoadError, %r{cannot load such file -- puppet/transport/schema/wibble} }
end

context 'when the transport being validated has been registered' do
let(:schema) { { name: 'validate', desc: 'a minimal connection', connection_info: {} } }
let(:schema_def) { instance_double('Puppet::ResourceApi::TransportSchemaDef', 'schema_def') }

it 'validates the connection_info' do
allow(Puppet::ResourceApi::TransportSchemaDef).to receive(:new).with(schema).and_return(schema_def)

it 'continues to validate the connection_info' do
# rubocop:disable RSpec/AnyInstance
expect_any_instance_of(Puppet::ResourceApi::TransportSchemaDef).to receive(:check_schema).with({})
expect_any_instance_of(Puppet::ResourceApi::TransportSchemaDef).to receive(:validate).with({})
# rubocop:enable RSpec/AnyInstance
described_class.register(schema)
described_class.validate('validate', {})

expect(schema_def).to receive(:check_schema).with('connection_info').and_return(nil)
expect(schema_def).to receive(:validate).with('connection_info').and_return(nil)

described_class.validate('validate', 'connection_info')
end
end
end
Expand Down

0 comments on commit 383028a

Please sign in to comment.