|
12 | 12 | let(:token_path) { '/latest/api/token' } |
13 | 13 | let(:identity_document_path) { '/latest/dynamic/instance-identity/document' } |
14 | 14 | let(:hostname_path) { '/latest/meta-data/hostname' } |
15 | | - |
| 15 | + |
16 | 16 | let(:mock_token) { 'mock-token-123456' } |
17 | 17 | let(:mock_identity_document) do |
18 | 18 | { |
|
53 | 53 | stub_request(:put, "http://#{ec2_metadata_host}#{token_path}") |
54 | 54 | .with(headers: { 'X-aws-ec2-metadata-token-ttl-seconds' => '60' }) |
55 | 55 | .to_return(status: 200, body: mock_token) |
56 | | - |
| 56 | + |
57 | 57 | # Stub identity document request |
58 | 58 | stub_request(:get, "http://#{ec2_metadata_host}#{identity_document_path}") |
59 | 59 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
60 | 60 | .to_return(status: 200, body: mock_identity_document.to_json) |
61 | | - |
| 61 | + |
62 | 62 | # Stub hostname request |
63 | 63 | stub_request(:get, "http://#{ec2_metadata_host}#{hostname_path}") |
64 | 64 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
|
116 | 116 | stub_request(:put, "http://#{ec2_metadata_host}#{token_path}") |
117 | 117 | .with(headers: { 'X-aws-ec2-metadata-token-ttl-seconds' => '60' }) |
118 | 118 | .to_return(status: 200, body: mock_token) |
119 | | - |
| 119 | + |
120 | 120 | # Identity document request fails |
121 | 121 | stub_request(:get, "http://#{ec2_metadata_host}#{identity_document_path}") |
122 | 122 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
|
135 | 135 | stub_request(:put, "http://#{ec2_metadata_host}#{token_path}") |
136 | 136 | .with(headers: { 'X-aws-ec2-metadata-token-ttl-seconds' => '60' }) |
137 | 137 | .to_return(status: 200, body: mock_token) |
138 | | - |
| 138 | + |
139 | 139 | # Identity document is invalid JSON |
140 | 140 | stub_request(:get, "http://#{ec2_metadata_host}#{identity_document_path}") |
141 | 141 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
|
154 | 154 | stub_request(:put, "http://#{ec2_metadata_host}#{token_path}") |
155 | 155 | .with(headers: { 'X-aws-ec2-metadata-token-ttl-seconds' => '60' }) |
156 | 156 | .to_return(status: 200, body: mock_token) |
157 | | - |
| 157 | + |
158 | 158 | # Successful identity document request |
159 | 159 | stub_request(:get, "http://#{ec2_metadata_host}#{identity_document_path}") |
160 | 160 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
161 | 161 | .to_return(status: 200, body: mock_identity_document.to_json) |
162 | | - |
| 162 | + |
163 | 163 | # Hostname request times out |
164 | 164 | stub_request(:get, "http://#{ec2_metadata_host}#{hostname_path}") |
165 | 165 | .with(headers: { 'X-aws-ec2-metadata-token' => mock_token }) |
|
174 | 174 | 'cloud.region' => 'mock-west-2', |
175 | 175 | 'cloud.availability_zone' => 'mock-west-2a', |
176 | 176 | 'host.id' => 'i-1234ab56cd7e89f01', |
177 | | - 'host.type' => 't2.micro-mock', |
| 177 | + 'host.type' => 't2.micro-mock' |
178 | 178 | # host.name is missing because the request failed |
179 | 179 | } |
180 | 180 | end |
|
0 commit comments