Skip to content

Commit d7a01db

Browse files
committed
(FM-7691) Load the schema before trying to validate connection_info
1 parent 53c6a86 commit d7a01db

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/puppet/resource_api/transport.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def connect(name, connection_info)
3333

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

spec/puppet/resource_api/transport_spec.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,22 @@
129129

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

135135
context 'when the transport being validated has been registered' do
136136
let(:schema) { { name: 'validate', desc: 'a minimal connection', connection_info: {} } }
137+
let(:schema_def) { instance_double('Puppet::ResourceApi::TransportSchemaDef', 'schema_def') }
138+
139+
it 'validates the connection_info' do
140+
allow(Puppet::ResourceApi::TransportSchemaDef).to receive(:new).with(schema).and_return(schema_def)
137141

138-
it 'continues to validate the connection_info' do
139-
# rubocop:disable RSpec/AnyInstance
140-
expect_any_instance_of(Puppet::ResourceApi::TransportSchemaDef).to receive(:check_schema).with({})
141-
expect_any_instance_of(Puppet::ResourceApi::TransportSchemaDef).to receive(:validate).with({})
142-
# rubocop:enable RSpec/AnyInstance
143142
described_class.register(schema)
144-
described_class.validate('validate', {})
143+
144+
expect(schema_def).to receive(:check_schema).with('connection_info').and_return(nil)
145+
expect(schema_def).to receive(:validate).with('connection_info').and_return(nil)
146+
147+
described_class.validate('validate', 'connection_info')
145148
end
146149
end
147150
end

0 commit comments

Comments
 (0)