|
44 | 44 | desc: 'the user to connect as', |
45 | 45 | }, |
46 | 46 | password: { |
47 | | - type: 'Sensitive[String]', |
| 47 | + type: 'String', |
| 48 | + sensitive: true, |
48 | 49 | desc: 'the password to make the connection', |
49 | 50 | }, |
50 | 51 | }, |
|
76 | 77 | ) |
77 | 78 | } |
78 | 79 | end |
| 80 | + |
| 81 | + context 'when connecting to a transport' do |
| 82 | + let(:name) { 'test_target' } |
| 83 | + let(:connection_info) do |
| 84 | + { |
| 85 | + name: 'test_target', |
| 86 | + desc: 'a basic transport', |
| 87 | + connection_info: { |
| 88 | + host: { |
| 89 | + type: 'String', |
| 90 | + desc: 'the host ip address or hostname', |
| 91 | + }, |
| 92 | + }, |
| 93 | + } |
| 94 | + end |
| 95 | + |
| 96 | + context 'when the transport file does not exist' do |
| 97 | + it 'throws a DevError' do |
| 98 | + expect(described_class).to receive(:validate).with(name, connection_info) |
| 99 | + expect { described_class.connect(name, connection_info) }.to raise_error Puppet::DevError, |
| 100 | + %r{Cannot load transport for `test_target`} |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + context 'when the transport file does exist' do |
| 105 | + context 'with and incorrectly defined transport' do |
| 106 | + it 'throws a DevError' do |
| 107 | + expect(described_class).to receive(:validate).with(name, connection_info) |
| 108 | + expect(described_class).to receive(:require).with('puppet/transport/test_target') |
| 109 | + expect { described_class.connect(name, connection_info) }.to raise_error Puppet::DevError, |
| 110 | + %r{uninitialized constant Puppet::Transport} |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context 'with a correctly defined transport' do |
| 115 | + let(:test_target) { double('Puppet::Transport::TestTarget') } # rubocop:disable RSpec/VerifiedDoubles |
| 116 | + |
| 117 | + it 'loads initiates the class successfully' do |
| 118 | + expect(described_class).to receive(:require).with('puppet/transport/test_target') |
| 119 | + expect(described_class).to receive(:validate).with(name, connection_info) |
| 120 | + |
| 121 | + stub_const('Puppet::Transport::TestTarget', test_target) |
| 122 | + expect(test_target).to receive(:new).with(connection_info) |
| 123 | + |
| 124 | + described_class.connect(name, connection_info) |
| 125 | + end |
| 126 | + end |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + describe '#self.validate' do |
| 131 | + 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} } |
| 133 | + end |
| 134 | + |
| 135 | + context 'when the transport being validated has been registered' do |
| 136 | + let(:schema) { { name: 'validate', desc: 'a minimal connection', connection_info: {} } } |
| 137 | + |
| 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 |
| 143 | + described_class.register(schema) |
| 144 | + described_class.validate('validate', {}) |
| 145 | + end |
| 146 | + end |
| 147 | + end |
79 | 148 | end |
0 commit comments