Skip to content

Commit bd3a21e

Browse files
committed
(FM-7700) Add a list operation returning registered transports
1 parent 8aaedab commit bd3a21e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/puppet/resource_api/transport.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ def register(schema)
1818
end
1919
module_function :register # rubocop:disable Style/AccessModifierDeclarations
2020

21+
# retrieve a Hash of transport schemas, keyed by their name.
22+
def list
23+
if @transports
24+
Marshal.load(Marshal.dump(@transports))
25+
else
26+
{}
27+
end
28+
end
29+
module_function :list # rubocop:disable Style/AccessModifierDeclarations
30+
2131
def connect(name, connection_info)
2232
validate(name, connection_info)
2333
require "puppet/transport/#{name}"

spec/puppet/resource_api/transport_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@
8888
end
8989
end
9090

91+
describe '#list' do
92+
subject { described_class.list }
93+
94+
context 'with no transports registered' do
95+
it { is_expected.to eq({}) }
96+
end
97+
98+
context 'with a transport registered' do
99+
let(:schema) do
100+
{
101+
name: 'test_target',
102+
desc: 'a basic transport',
103+
connection_info: {
104+
host: {
105+
type: 'String',
106+
desc: 'the host ip address or hostname',
107+
},
108+
},
109+
}
110+
end
111+
112+
before(:each) do
113+
described_class.register(schema)
114+
end
115+
116+
it { expect(described_class.list['test_target'].definition).to eq schema }
117+
it 'returns a new object' do
118+
expect(described_class.list['test_target'].definition.object_id).not_to eq schema.object_id
119+
end
120+
end
121+
end
122+
91123
describe '#connect(name, connection_info)', agent_test: true do
92124
let(:name) { 'test_target' }
93125
let(:schema) do

0 commit comments

Comments
 (0)