|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | require 'base64' |
16 | | -require 'spec_helper' |
17 | 16 | require 'config/matchers' |
18 | 17 | require 'fixtures/config/kube_config_hash' |
19 | 18 | require 'helpers/file_fixtures' |
| 19 | +require 'spec_helper' |
20 | 20 |
|
21 | 21 | require 'kubernetes/config/kube_config' |
| 22 | +require 'kubernetes/loader' |
22 | 23 |
|
23 | 24 |
|
24 | 25 | describe Kubernetes::KubeConfig do |
|
247 | 248 | expect(kube_config.send(:create_temp_file_with_base64content, content)).to eq(expected_path) |
248 | 249 | end |
249 | 250 | end |
| 251 | + |
| 252 | + context 'load from defaults' do |
| 253 | + before(:each) do |
| 254 | + # Clear out everything before each run. |
| 255 | + ENV['HOME'] = nil |
| 256 | + ENV['KUBECONFIG'] = nil |
| 257 | + ENV['KUBERNETES_SERVICE_HOST'] = nil |
| 258 | + ENV['KUBERNETES_SERVICE_PORT'] = nil |
| 259 | + |
| 260 | + # Suppress warnings |
| 261 | + warn_level = $VERBOSE |
| 262 | + $VERBOSE = nil |
| 263 | + Kubernetes::InClusterConfig::SERVICE_TOKEN_FILENAME = '/non/existent/file/token' |
| 264 | + Kubernetes::InClusterConfig::SERVICE_CA_CERT_FILENAME = '/non/existent/file/ca.crt' |
| 265 | + $VERBOSE = warn_level |
| 266 | + end |
| 267 | + |
| 268 | + it 'should load from KUBECONFIG' do |
| 269 | + ENV['KUBECONFIG'] = Kubernetes::Testing::file_fixture('config/config_2').to_s |
| 270 | + ENV['HOME'] = Kubernetes::Testing::file_fixture('config').to_s |
| 271 | + config = Kubernetes::Configuration::default_config |
| 272 | + |
| 273 | + expect(config.host).to eq('other:8080') |
| 274 | + end |
| 275 | + |
| 276 | + it 'should load from HOME' do |
| 277 | + ENV['HOME'] = Kubernetes::Testing::file_fixture('config').to_s |
| 278 | + config = Kubernetes::Configuration::default_config |
| 279 | + |
| 280 | + expect(config.host).to eq('firstconfig:8080') |
| 281 | + end |
| 282 | + |
| 283 | + it 'should load from cluster' do |
| 284 | + ENV['KUBERNETES_SERVICE_HOST'] = 'kubernetes' |
| 285 | + ENV['KUBERNETES_SERVICE_PORT'] = '8888' |
| 286 | + |
| 287 | + # Suppress warnings |
| 288 | + warn_level = $VERBOSE |
| 289 | + $VERBOSE = nil |
| 290 | + |
| 291 | + # Override constants for token and cert locations |
| 292 | + Kubernetes::InClusterConfig::SERVICE_TOKEN_FILENAME = Kubernetes::Testing::file_fixture('config/config').to_s |
| 293 | + Kubernetes::InClusterConfig::SERVICE_CA_CERT_FILENAME = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s |
| 294 | + $VERBOSE = warn_level |
| 295 | + |
| 296 | + config = Kubernetes::Configuration::default_config |
| 297 | + |
| 298 | + expect(config.host).to eq('kubernetes:8888') |
| 299 | + end |
| 300 | + |
| 301 | + it 'should default to localhost' do |
| 302 | + config = Kubernetes::Configuration::default_config |
| 303 | + |
| 304 | + expect(config.host).to eq('localhost:8080') |
| 305 | + end |
| 306 | + end |
250 | 307 | end |
251 | 308 | end |
0 commit comments