@@ -466,34 +466,137 @@ describe('KubeConfig', () => {
466
466
expect ( dir ) . to . equal ( null ) ;
467
467
} ) ;
468
468
469
- it ( 'should load from HOMEDRIVE/HOMEPATH if present' , ( ) => {
470
- process . env . HOMEDRIVE = 'foo' ;
471
- process . env . HOMEPATH = 'bar' ;
472
- const dir = join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ;
473
- const arg = { } ;
474
- arg [ dir ] = { config : 'data' } ;
475
- mockfs ( arg ) ;
469
+ describe ( 'look for an existing .kube/config' , ( ) => {
470
+ let allDirs ;
471
+ let homeDrive ;
472
+ before ( ( ) => {
473
+ allDirs = { } ;
474
+ process . env . HOME = 'home' ;
475
+ process . env . HOMEDRIVE = 'drive' ;
476
+ process . env . HOMEPATH = 'a-path' ;
477
+ process . env . USERPROFILE = 'a-userprofile' ;
478
+ homeDrive = join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ;
479
+ allDirs [ process . env . HOME ] = { } ;
480
+ allDirs [ homeDrive ] = { } ;
481
+ allDirs [ process . env . USERPROFILE ] = { } ;
482
+ } ) ;
483
+ it ( 'should load from HOME if present' , ( ) => {
484
+ const dir = process . env . HOME ;
485
+ allDirs [ dir ] [ '.kube' ] = { config : 'data' } ;
486
+ mockfs ( allDirs ) ;
476
487
477
- const home = findHomeDir ( ) ;
488
+ const home = findHomeDir ( ) ;
478
489
479
- mockfs . restore ( ) ;
480
- expect ( home ) . to . equal ( dir ) ;
490
+ mockfs . restore ( ) ;
491
+ expect ( home ) . to . equal ( dir ) ;
492
+ } ) ;
493
+ it ( 'should favor HOME when present' , ( ) => {
494
+ const dir = process . env . HOME ;
495
+ allDirs [ dir ] [ '.kube' ] = { config : 'data' } ;
496
+ allDirs [ homeDrive ] [ '.kube' ] = { config : 'data' } ;
497
+ allDirs [ process . env . USERPROFILE ] [ '.kube' ] = { config : 'data' } ;
498
+ mockfs ( allDirs ) ;
499
+
500
+ const home = findHomeDir ( ) ;
501
+
502
+ mockfs . restore ( ) ;
503
+ expect ( home ) . to . equal ( dir ) ;
504
+ } ) ;
505
+
506
+ it ( 'should load from HOMEDRIVE/HOMEPATH if present' , ( ) => {
507
+ const dir = homeDrive ;
508
+ allDirs [ dir ] [ '.kube' ] = { config : 'data' } ;
509
+ mockfs ( arg ) ;
510
+
511
+ const home = findHomeDir ( ) ;
512
+
513
+ mockfs . restore ( ) ;
514
+ expect ( home ) . to . equal ( dir ) ;
515
+ } ) ;
516
+
517
+ it ( 'should favor HOMEDRIVE/HOMEPATH over USERPROFILE' , ( ) => {
518
+ const dir = homeDrive ;
519
+ allDirs [ dir ] [ '.kube' ] = { config : 'data' } ;
520
+ allDirs [ process . env . USERPROFILE ] [ '.kube' ] = { config : 'data' } ;
521
+ mockfs ( arg ) ;
522
+
523
+ const home = findHomeDir ( ) ;
524
+
525
+ mockfs . restore ( ) ;
526
+ expect ( home ) . to . equal ( dir ) ;
527
+ } ) ;
528
+
529
+ it ( 'should load from USERPROFILE if present' , ( ) => {
530
+ const dir = process . env . USERPROFILE ;
531
+ allDirs [ dir ] [ '.kube' ] = { config : 'data' } ;
532
+ mockfs ( arg ) ;
533
+
534
+ const home = findHomeDir ( ) ;
535
+
536
+ mockfs . restore ( ) ;
537
+ expect ( home ) . to . equal ( dir ) ;
538
+ } ) ;
481
539
} ) ;
482
540
483
- it ( 'should load from USERPROFILE if present' , ( ) => {
484
- const dir = 'someplace' ;
541
+ // Just test for existence,but this will include the writability order
542
+ describe ( 'look for an existing directory' , ( ) => {
543
+ let allDirs ;
544
+ let homeDrive ;
545
+ before ( ( ) => {
546
+ allDirs = { } ;
547
+ process . env . HOME = 'home' ;
548
+ process . env . HOMEDRIVE = 'drive' ;
549
+ process . env . HOMEPATH = 'a-path' ;
550
+ process . env . USERPROFILE = 'a-userprofile' ;
551
+ homeDrive = join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ;
552
+ } ) ;
553
+ it ( 'should load from HOME if present' , ( ) => {
554
+ allDirs = {
555
+ [ process . env . HOME ] : 'data' ,
556
+ [ homeDrive ] : 'data' ,
557
+ [ process . env . USERPROFILE ] : 'data'
558
+ }
559
+ const dir = process . env . HOME
560
+ mockfs ( allDirs ) ;
561
+
562
+ const home = findHomeDir ( ) ;
485
563
486
- process . env . HOMEDRIVE = 'foo' ;
487
- process . env . HOMEPATH = 'bar' ;
488
- process . env . USERPROFILE = dir ;
489
- const arg = { } ;
490
- arg [ dir ] = { config : 'data' } ;
491
- mockfs ( arg ) ;
564
+ mockfs . restore ( ) ;
565
+ expect ( home ) . to . equal ( dir ) ;
566
+ } ) ;
567
+ it ( 'should load from homeDrive if present' , ( ) => {
568
+ allDirs = {
569
+ [ homeDrive ] : 'data' ,
570
+ [ process . env . USERPROFILE ] : 'data'
571
+ }
572
+ const dir = process . env . HOME
573
+ mockfs ( allDirs ) ;
574
+
575
+ const home = findHomeDir ( ) ;
576
+
577
+ mockfs . restore ( ) ;
578
+ expect ( home ) . to . equal ( homeDrive ) ;
579
+ } ) ;
580
+ it ( 'should load from USERPROFILE if present' , ( ) => {
581
+ allDirs = {
582
+ [ process . env . USERPROFILE ] : 'data'
583
+ }
584
+ const dir = process . env . USERPROFILE ;
585
+ mockfs ( allDirs ) ;
586
+
587
+ const home = findHomeDir ( ) ;
588
+
589
+ mockfs . restore ( ) ;
590
+ expect ( home ) . to . equal ( dir ) ;
591
+ } ) ;
592
+ } ) ;
593
+ it ( 'should return null if nothing is present' , ( ) => {
594
+ mockfs ( { } ) ;
492
595
493
596
const home = findHomeDir ( ) ;
494
597
495
598
mockfs . restore ( ) ;
496
- expect ( home ) . to . equal ( dir ) ;
599
+ expect ( home ) . to . equal ( null ) ;
497
600
} ) ;
498
601
} ) ;
499
602
0 commit comments