Skip to content

Commit fa8339c

Browse files
gerasesSergei Gerasenko
authored and
Sergei Gerasenko
committed
Use the read method on the return of open_url to actually get the content.
1 parent 802eb9a commit fa8339c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/puppet/parser/functions/loadjson.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module Puppet::Parser::Functions
4444
url = args[0]
4545
end
4646
begin
47-
contents = OpenURI.open_uri(url, http_options)
47+
contents = OpenURI.open_uri(url, http_options).read
4848
rescue OpenURI::HTTPError => e
4949
res = e.io
5050
warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'")

spec/functions/loadjson_spec.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
allow(File).to receive(:exist?).and_call_original
5656
allow(File).to receive(:exist?).with(filename).and_return(true).once
5757
allow(File).to receive(:read).with(filename).and_return(json).once
58-
allow(File).to receive(:read).with(filename).and_return(json).once
5958
if Puppet::PUPPETVERSION[0].to_i < 8
6059
allow(PSON).to receive(:load).with(json).and_return(data).once
6160
else
@@ -98,7 +97,7 @@
9897
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
9998

10099
it {
101-
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json)
100+
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(StringIO.new(json))
102101
if Puppet::PUPPETVERSION[0].to_i < 8
103102
expect(PSON).to receive(:load).with(json).and_return(data).once
104103
else
@@ -118,7 +117,7 @@
118117
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
119118

120119
it {
121-
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json)
120+
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(StringIO.new(json))
122121
if Puppet::PUPPETVERSION[0].to_i < 8
123122
expect(PSON).to receive(:load).with(json).and_return(data).once
124123
else
@@ -138,7 +137,7 @@
138137
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
139138

140139
it {
141-
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json)
140+
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(StringIO.new(json))
142141
if Puppet::PUPPETVERSION[0].to_i < 8
143142
expect(PSON).to receive(:load).with(json).and_return(data).once
144143
else
@@ -155,7 +154,7 @@
155154
let(:json) { ',;{"key":"value"}' }
156155

157156
it {
158-
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json)
157+
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(StringIO.new(json))
159158
if Puppet::PUPPETVERSION[0].to_i < 8
160159
expect(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
161160
else

0 commit comments

Comments
 (0)