Commit a263257
Fix loading JSON from URL
Starting with Puppet 8, stdlib use the JSON class instead of the PSON
class that was used before to load JSON content downloaded from an URL.
The PSON class allowed to pass an IO object and #read its content for
parsing, but the JSON class mandates passing a String.
The loadjson() functions, when passed an URL, download the document with
OpenURI.open_uri (which return a StringIO object) and try to parse it.
On Puppet 7, this works because PSON accept IO objects, but with Puppet
8 an exception is raised:
```
Error: Evaluation Error: Error while evaluating a Function Call, no implicit conversion of StringIO into String
```
As the test suite inadequately mocked OpenURI.open_uri to return a
String, this was not catch.
Fix this by adjusting the return value in the test suite to match the
actual behavior of OpenURI and calling #read on the IO object returned
by OpenURI.open_uri.
While here, add an acceptance tests to check loadjson when using an URL.1 parent 3f792ff commit a263257
3 files changed
Lines changed: 26 additions & 5 deletions
File tree
- lib/puppet/parser/functions
- spec
- acceptance
- functions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
| 122 | + | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
| |||
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
141 | | - | |
| 143 | + | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
158 | | - | |
| 161 | + | |
| 162 | + | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
| |||
0 commit comments