|
131 | 131 | subject.post_catalog(certname, environment: 'production', facts: facts, checksum_type: %w[sha256 sha384]) |
132 | 132 | end |
133 | 133 |
|
| 134 | + it 'does not accept msgpack by default' do |
| 135 | + stub_request(:post, uri) |
| 136 | + .with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, text/pson'}) |
| 137 | + .to_return(**catalog_response) |
| 138 | + |
| 139 | + allow(Puppet.features).to receive(:msgpack?).and_return(false) |
| 140 | + |
| 141 | + subject.post_catalog(certname, environment: environment, facts: facts) |
| 142 | + end |
| 143 | + |
| 144 | + it 'accepts msgpack & rich_json_msgpack if the gem is present' do |
| 145 | + stub_request(:post, uri) |
| 146 | + .with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, application/vnd.puppet.rich+msgpack, application/x-msgpack, text/pson'}) |
| 147 | + .to_return(**catalog_response) |
| 148 | + |
| 149 | + allow(Puppet.features).to receive(:msgpack?).and_return(true) |
| 150 | + |
| 151 | + subject.post_catalog(certname, environment: environment, facts: facts) |
| 152 | + end |
| 153 | + |
134 | 154 | it 'returns a deserialized catalog' do |
135 | 155 | stub_request(:post, uri) |
136 | 156 | .to_return(**catalog_response) |
|
140 | 160 | expect(cat.name).to eq(certname) |
141 | 161 | end |
142 | 162 |
|
| 163 | + it 'deserializes the catalog from msgpack', if: Puppet.features.msgpack? do |
| 164 | + body = catalog.to_msgpack |
| 165 | + formatter = Puppet::Network::FormatHandler.format(:msgpack) |
| 166 | + catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }} |
| 167 | + |
| 168 | + stub_request(:post, uri) |
| 169 | + .to_return(**catalog_response) |
| 170 | + |
| 171 | + _, cat = subject.post_catalog(certname, environment: 'production', facts: facts) |
| 172 | + expect(cat).to be_a(Puppet::Resource::Catalog) |
| 173 | + expect(cat.name).to eq(certname) |
| 174 | + end |
| 175 | + |
| 176 | + it 'deserializes the catalog from rich msgpack', if: Puppet.features.msgpack? do |
| 177 | + body = Puppet.override(rich_data: true) do |
| 178 | + catalog.to_msgpack |
| 179 | + end |
| 180 | + |
| 181 | + formatter = Puppet::Network::FormatHandler.format(:rich_data_msgpack) |
| 182 | + catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }} |
| 183 | + |
| 184 | + stub_request(:post, uri) |
| 185 | + .to_return(**catalog_response) |
| 186 | + |
| 187 | + _, cat = subject.post_catalog(certname, environment: 'production', facts: facts) |
| 188 | + expect(cat).to be_a(Puppet::Resource::Catalog) |
| 189 | + expect(cat.name).to eq(certname) |
| 190 | + end |
| 191 | + |
143 | 192 | it 'returns the request response' do |
144 | 193 | stub_request(:post, uri) |
145 | 194 | .to_return(**catalog_response) |
|
0 commit comments