@@ -4,50 +4,51 @@ module VCAP::CloudController
44 RSpec . describe Config do
55 let ( :test_config_hash ) {
66 {
7- packages : {
8- fog_connection : { } ,
9- fog_aws_storage_options : {
10- encryption : 'AES256'
11- } ,
12- app_package_directory_key : 'app_key' ,
7+ packages : {
8+ fog_connection : { } ,
9+ fog_aws_storage_options : {
10+ encryption : 'AES256'
1311 } ,
14- droplets : {
15- fog_connection : { } ,
16- droplet_directory_key : 'droplet_key' ,
12+ app_package_directory_key : 'app_key' ,
13+ } ,
14+ droplets : {
15+ fog_connection : { } ,
16+ droplet_directory_key : 'droplet_key' ,
17+ } ,
18+ buildpacks : {
19+ fog_connection : { } ,
20+ buildpack_directory_key : 'bp_key' ,
21+ } ,
22+ resource_pool : {
23+ minimum_size : 9001 ,
24+ maximum_size : 0 ,
25+ fog_connection : { } ,
26+ resource_directory_key : 'resource_key' ,
27+ } ,
28+ bulk_api : { } ,
29+ external_domain : 'host' ,
30+ tls_port : 1234 ,
31+ staging : {
32+ auth : {
33+ user : 'user' ,
34+ password : 'password' ,
1735 } ,
18- buildpacks : {
19- fog_connection : { } ,
20- buildpack_directory_key : 'bp_key' ,
21- } ,
22- resource_pool : {
23- minimum_size : 9001 ,
24- maximum_size : 0 ,
25- fog_connection : { } ,
26- resource_directory_key : 'resource_key' ,
27- } ,
28- bulk_api : { } ,
29- external_domain : 'host' ,
30- tls_port : 1234 ,
31- staging : {
32- auth : {
33- user : 'user' ,
34- password : 'password' ,
35- } ,
36- } ,
37- bits_service : { enabled : false } ,
38- reserved_private_domains : File . join ( Paths ::FIXTURES , 'config/reserved_private_domains.dat' ) ,
39- diego : { } ,
40- stacks_file : 'path/to/stacks/file' ,
41- db_encryption_key : '123-456' ,
42- install_buildpacks : [
43- {
44- name : 'some-buildpack' ,
45- }
46- ]
36+ } ,
37+ bits_service : { enabled : false } ,
38+ reserved_private_domains : File . join ( Paths ::FIXTURES , 'config/reserved_private_domains.dat' ) ,
39+ diego : { } ,
40+ stacks_file : 'path/to/stacks/file' ,
41+ db_encryption_key : '123-456' ,
42+ install_buildpacks : [
43+ {
44+ name : 'some-buildpack' ,
45+ }
46+ ]
4747 }
4848 }
49+ subject ( :config_instance ) { Config . new ( test_config_hash ) }
4950
50- describe '# load_from_file' do
51+ describe '. load_from_file' do
5152 it 'raises if the file does not exist' do
5253 expect {
5354 Config . load_from_file ( 'nonexistent.yml' , context : :worker )
@@ -234,7 +235,6 @@ module VCAP::CloudController
234235
235236 describe '#configure_components' do
236237 let ( :dependency_locator ) { CloudController ::DependencyLocator . instance }
237-
238238 let ( :test_config_hash ) {
239239 {
240240 packages : {
@@ -275,10 +275,6 @@ module VCAP::CloudController
275275 }
276276 }
277277
278- let ( :config_instance ) do
279- Config . new ( test_config_hash )
280- end
281-
282278 before do
283279 allow ( Stack ) . to receive ( :configure )
284280 end
@@ -339,13 +335,13 @@ module VCAP::CloudController
339335 context 'when database encryption keys are used' do
340336 let ( :keys ) do
341337 {
342- keys : {
343- current : 'abc-123' ,
344- previous : 'def-456' ,
345- old : 'ghi-789'
346- } ,
347- current_key_label : 'current' ,
348- pbkdf2_hmac_iterations : 100_020
338+ keys : {
339+ current : 'abc-123' ,
340+ previous : 'def-456' ,
341+ old : 'ghi-789'
342+ } ,
343+ current_key_label : 'current' ,
344+ pbkdf2_hmac_iterations : 100_020
349345 }
350346 end
351347
@@ -395,10 +391,6 @@ module VCAP::CloudController
395391 end
396392
397393 describe '#get' do
398- let ( :config_instance ) do
399- Config . new ( test_config_hash )
400- end
401-
402394 it 'returns the value at the given key' do
403395 expect ( config_instance . get ( :external_domain ) ) . to eq 'host'
404396 end
@@ -409,12 +401,12 @@ module VCAP::CloudController
409401
410402 it 'returns a hash for nested properties' do
411403 expect ( config_instance . get ( :packages ) ) . to eq ( {
412- fog_connection : { } ,
413- fog_aws_storage_options : {
414- encryption : 'AES256'
415- } ,
416- app_package_directory_key : 'app_key' ,
417- } )
404+ fog_connection : { } ,
405+ fog_aws_storage_options : {
406+ encryption : 'AES256'
407+ } ,
408+ app_package_directory_key : 'app_key' ,
409+ } )
418410 expect ( config_instance . get ( :packages , :fog_aws_storage_options ) ) . to eq ( encryption : 'AES256' )
419411 end
420412
@@ -450,14 +442,90 @@ module VCAP::CloudController
450442 end
451443
452444 describe '#set' do
453- let ( :config_instance ) do
454- Config . new ( test_config_hash )
455- end
456-
457445 it 'saves the value at the key in the config' do
458446 config_instance . set ( :external_host , 'foobar.example.com' )
459447 expect ( config_instance . get ( :external_host ) ) . to eq 'foobar.example.com'
460448 end
461449 end
450+
451+ describe '#kubernetes_service_account_token' do
452+ subject ( :config_instance ) { Config . new ( test_config_hash . merge ( k8s_config_hash ) ) }
453+
454+ let ( :k8s_config_hash ) do
455+ {
456+ kubernetes : {
457+ service_account : { token_file : service_account_token_file . path } ,
458+ host_url : 'http://k8s.example.com' ,
459+ }
460+ }
461+ end
462+
463+ let ( :expected_service_account_token ) { 'service-account-token' }
464+ let ( :service_account_token_file ) do
465+ Tempfile . new ( 'service_account_token' ) . tap do |file |
466+ file . write ( expected_service_account_token )
467+ file . close
468+ end
469+ end
470+
471+ it 'returns the contents' do
472+ expect ( config_instance . kubernetes_service_account_token ) . to ( eq ( expected_service_account_token ) )
473+ end
474+
475+ context 'when no kubernetes api is configured' do
476+ let ( :k8s_config_hash ) do
477+ {
478+ kubernetes : {
479+ service_account : { token_file : service_account_token_file . path } ,
480+ host_url : '' ,
481+ }
482+ }
483+ end
484+
485+ it 'raises' do
486+ expect { config_instance . kubernetes_service_account_token } . to ( raise_error ( Config ::KubernetesApiNotConfigured ) )
487+ end
488+ end
489+ end
490+
491+ describe '#kubernetes_ca_cert' do
492+ subject ( :config_instance ) { Config . new ( test_config_hash . merge ( k8s_config_hash ) ) }
493+
494+ let ( :k8s_config_hash ) do
495+ {
496+ kubernetes : {
497+ ca_file : ca_file . path ,
498+ host_url : 'http://k8s.example.com' ,
499+ }
500+ }
501+ end
502+
503+ let ( :expected_ca_cert ) { 'some-ca' }
504+ let ( :ca_file ) do
505+ Tempfile . new ( 'ca_file' ) . tap do |file |
506+ file . write ( expected_ca_cert )
507+ file . close
508+ end
509+ end
510+
511+ it 'returns the contents' do
512+ expect ( config_instance . kubernetes_ca_cert ) . to ( eq ( expected_ca_cert ) )
513+ end
514+
515+ context 'when no kubernetes api is configured' do
516+ let ( :k8s_config_hash ) do
517+ {
518+ kubernetes : {
519+ ca_file : ca_file . path ,
520+ host_url : '' ,
521+ }
522+ }
523+ end
524+
525+ it 'raises' do
526+ expect { config_instance . kubernetes_ca_cert } . to ( raise_error ( Config ::KubernetesApiNotConfigured ) )
527+ end
528+ end
529+ end
462530 end
463531end
0 commit comments