|
49 | 49 | }
|
50 | 50 | end
|
51 | 51 |
|
| 52 | + context 'Interface is set in config' do |
52 | 53 | before do
|
53 | 54 | instance
|
54 | 55 | allow(driver).to receive(:create_server).and_return(server)
|
55 | 56 | allow(driver).to receive(:wait_for_sshd)
|
56 | 57 | end
|
57 | 58 |
|
58 |
| - context 'Interface is set in config' do |
59 |
| - |
60 | 59 | it 'derives hostname from DNS when specified in the .kitchen.yml' do
|
61 | 60 | config[:interface] = 'dns'
|
62 | 61 | driver.create(state)
|
|
83 | 82 | end
|
84 | 83 |
|
85 | 84 | context 'Interface is derived automatically' do
|
| 85 | + before do |
| 86 | + instance |
| 87 | + allow(driver).to receive(:create_server).and_return(server) |
| 88 | + allow(driver).to receive(:wait_for_sshd) |
| 89 | + end |
86 | 90 |
|
87 | 91 | let(:server) do
|
88 | 92 | double(:id => "123",
|
|
122 | 126 | end
|
123 | 127 |
|
124 | 128 | context 'user_data implementation is working' do
|
| 129 | + before do |
| 130 | + instance |
| 131 | + allow(driver).to receive(:create_server).and_return(server) |
| 132 | + allow(driver).to receive(:wait_for_sshd) |
| 133 | + end |
125 | 134 |
|
126 | 135 | it 'user_data is not defined' do
|
127 | 136 | driver.create(state)
|
|
137 | 146 | end
|
138 | 147 |
|
139 | 148 | context 'When #iam_creds returns values' do
|
140 |
| - context 'but they should not be used' do |
141 |
| - before do |
142 |
| - allow(ENV).to receive(:[]).and_return(nil) |
143 |
| - allow(driver).to receive(:iam_creds).and_return(iam_creds) |
144 |
| - allow(Net::HTTP).to receive(:get).with(URI.parse('http://169.254.169.254')).and_return(true) |
145 |
| - end |
| 149 | + let(:config) do |
| 150 | + { |
| 151 | + aws_ssh_key_id: 'larry', |
| 152 | + user_data: nil |
| 153 | + } |
| 154 | + end |
| 155 | + |
| 156 | + before do |
| 157 | + allow(ENV).to receive(:[]).and_return(nil) |
| 158 | + allow(driver).to receive(:iam_creds).and_return(iam_creds) |
| 159 | + instance |
| 160 | + end |
146 | 161 |
|
| 162 | + context 'but they should not be used' do |
147 | 163 | context 'because :aws_access_key_id is set but not via #iam_creds' do
|
| 164 | + let(:aws_access_key_id) { 'secret' } |
| 165 | + before do |
| 166 | + config[:aws_access_key_id] = aws_access_key_id |
| 167 | + end |
| 168 | + |
148 | 169 | it 'does not override :aws_access_key_id' do
|
149 |
| - expect(driver.send(:config)[:aws_access_key_id]).to eq(config[:aws_access_key_id]) |
| 170 | + expect(driver.send(:config)[:aws_access_key_id]).to eq(aws_access_key_id) |
150 | 171 | end
|
151 | 172 |
|
152 | 173 | it 'does not set :aws_session_token via #iam_creds' do
|
|
155 | 176 | end
|
156 | 177 | end
|
157 | 178 |
|
158 |
| - context 'because :aws_access_key_id is set but not via #iam_creds' do |
| 179 | + context 'because :aws_secret_access_key is set but not via #iam_creds' do |
| 180 | + let(:aws_secret_access_key) { 'moarsecret' } |
| 181 | + |
| 182 | + before do |
| 183 | + config[:aws_secret_access_key] = aws_secret_access_key |
| 184 | + end |
| 185 | + |
159 | 186 | it 'does not override :aws_secret_access_key' do
|
160 |
| - expect(driver.send(:config)[:aws_secret_access_key]).to eq(config[:aws_secret_access_key]) |
| 187 | + expect(driver.send(:config)[:aws_secret_access_key]).to eq(aws_secret_access_key) |
161 | 188 | end
|
162 | 189 |
|
163 | 190 | it 'does not set :aws_session_token via #iam_creds' do
|
|
167 | 194 | end
|
168 | 195 |
|
169 | 196 | context 'because :aws_session_token is set but not via #iam_creds' do
|
170 |
| - before { config[:aws_session_token] = 'adifferentsessiontoken' } |
| 197 | + let(:aws_session_token) { 'adifferentsessiontoken' } |
| 198 | + before do |
| 199 | + config[:aws_session_token] = aws_session_token |
| 200 | + end |
171 | 201 | it 'does not override :aws_session_token' do
|
172 | 202 | expect(driver.send(:config)[:aws_session_token]).to eq('adifferentsessiontoken')
|
173 | 203 | end
|
|
182 | 212 | }
|
183 | 213 | end
|
184 | 214 |
|
185 |
| - before do |
186 |
| - allow(ENV).to receive(:[]).and_return(nil) |
187 |
| - allow(driver).to receive(:iam_creds).and_return(iam_creds) |
188 |
| - end |
189 |
| - |
190 | 215 | it 'uses :aws_access_key_id from iam_creds' do
|
191 | 216 | expect(driver.send(:config)[:aws_access_key_id]).to eq(iam_creds[:aws_access_key_id])
|
192 | 217 | end
|
|
204 | 229 | describe '#iam_creds' do
|
205 | 230 | context 'when a metadata service is available' do
|
206 | 231 | before do
|
207 |
| - allow(Net::HTTP).to receive(:get).with(URI.parse('http://169.254.169.254')).and_return(true) |
| 232 | + allow(Net::HTTP).to receive(:get).and_return(true) |
208 | 233 | end
|
209 | 234 |
|
210 | 235 | context 'and #fetch_credentials returns valid iam credentials' do
|
211 | 236 | it '#iam_creds retuns the iam credentials from fetch_credentials' do
|
212 | 237 | allow(driver).to receive(:fetch_credentials).and_return(iam_creds)
|
213 |
| - expect(driver.send(:iam_creds)).to eq(iam_creds) |
| 238 | + expect(driver.iam_creds).to eq(iam_creds) |
214 | 239 | end
|
215 | 240 | end
|
216 | 241 |
|
217 | 242 | context 'when #fetch_credentials fails with NoMethodError' do
|
218 | 243 | it 'returns an empty hash' do
|
219 | 244 | allow(driver).to receive(:fetch_credentials).and_raise(NoMethodError)
|
| 245 | + expect { driver.fetch_credentials }.to raise_error(NoMethodError) |
220 | 246 | expect(driver.iam_creds).to eq({})
|
221 | 247 | end
|
222 | 248 | end
|
223 | 249 |
|
224 | 250 | context 'when #fetch_credentials fails with ::StandardError' do
|
225 | 251 | it 'returns an empty hash' do
|
226 | 252 | allow(driver).to receive(:fetch_credentials).and_raise(::StandardError)
|
| 253 | + expect { driver.fetch_credentials }.to raise_error(::StandardError) |
227 | 254 | expect(driver.iam_creds).to eq({})
|
228 | 255 | end
|
229 | 256 | end
|
230 | 257 |
|
231 | 258 | context 'when #fetch_credentials fails with Errno::EHOSTUNREACH' do
|
232 | 259 | it 'returns an empty hash' do
|
233 | 260 | allow(driver).to receive(:fetch_credentials).and_raise(Errno::EHOSTUNREACH)
|
| 261 | + expect { driver.fetch_credentials }.to raise_error(Errno::EHOSTUNREACH) |
234 | 262 | expect(driver.iam_creds).to eq({})
|
235 | 263 | end
|
236 | 264 | end
|
237 | 265 |
|
238 | 266 | context 'when #fetch_credentials fails with Timeout::Error' do
|
239 | 267 | it 'returns an empty hash' do
|
240 | 268 | allow(driver).to receive(:fetch_credentials).and_raise(Timeout::Error)
|
| 269 | + expect { driver.fetch_credentials }.to raise_error(Timeout::Error) |
241 | 270 | expect(driver.iam_creds).to eq({})
|
242 | 271 | end
|
243 | 272 | end
|
|
253 | 282 | end
|
254 | 283 |
|
255 | 284 | describe '#block_device_mappings' do
|
| 285 | + before do |
| 286 | + instance |
| 287 | + allow(driver).to receive(:create_server).and_return(server) |
| 288 | + allow(driver).to receive(:wait_for_sshd) |
| 289 | + end |
256 | 290 | let(:connection) { double(Fog::Compute) }
|
257 | 291 | let(:image) { double('Image', :root_device_name => 'name') }
|
258 | 292 | before do
|
|
0 commit comments