@@ -322,6 +322,81 @@ describe('KubeConfig', () => {
322322 } ) ;
323323 } ) ;
324324
325+ describe ( 'findHome' , ( ) => {
326+ it ( 'should load from HOME if present' , ( ) => {
327+ const currentHome = process . env . HOME ;
328+ const expectedHome = 'foobar' ;
329+ process . env . HOME = expectedHome ;
330+ const dir = join ( process . env . HOME , '.kube' ) ;
331+ const arg = { } ;
332+ arg [ dir ] = { config : 'data' } ;
333+ mockfs ( arg ) ;
334+
335+ const home = KubeConfig . findHomeDir ( ) ;
336+
337+ mockfs . restore ( ) ;
338+ process . env . HOME = currentHome ;
339+
340+ expect ( home ) . to . equal ( expectedHome ) ;
341+ } ) ;
342+ } ) ;
343+
344+ describe ( 'win32HomeDirTests' , ( ) => {
345+ let originalPlatform : string ;
346+
347+ before ( ( ) => {
348+ originalPlatform = process . platform ;
349+ Object . defineProperty ( process , 'platform' , {
350+ value : 'win32' ,
351+ } ) ;
352+ } ) ;
353+
354+ after ( ( ) => {
355+ Object . defineProperty ( process , 'platform' , {
356+ value : originalPlatform ,
357+ } ) ;
358+ } ) ;
359+
360+ it ( 'should load from HOMEDRIVE/HOMEPATH if present' , ( ) => {
361+ const currentHome = process . env . HOME ;
362+
363+ delete process . env . HOME ;
364+ process . env . HOMEDRIVE = 'foo' ;
365+ process . env . HOMEPATH = 'bar' ;
366+ const dir = join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ;
367+ const arg = { } ;
368+ arg [ dir ] = { config : 'data' } ;
369+ mockfs ( arg ) ;
370+
371+ const home = KubeConfig . findHomeDir ( ) ;
372+
373+ mockfs . restore ( ) ;
374+ process . env . HOME = currentHome ;
375+
376+ expect ( home ) . to . equal ( dir ) ;
377+ } ) ;
378+
379+ it ( 'should load from USERPROFILE if present' , ( ) => {
380+ const currentHome = process . env . HOME ;
381+ const dir = 'someplace' ;
382+
383+ delete process . env . HOME ;
384+ process . env . HOMEDRIVE = 'foo' ;
385+ process . env . HOMEPATH = 'bar' ;
386+ process . env . USERPROFILE = dir ;
387+ const arg = { } ;
388+ arg [ dir ] = { config : 'data' } ;
389+ mockfs ( arg ) ;
390+
391+ const home = KubeConfig . findHomeDir ( ) ;
392+
393+ mockfs . restore ( ) ;
394+ process . env . HOME = currentHome ;
395+
396+ expect ( home ) . to . equal ( dir ) ;
397+ } ) ;
398+ } ) ;
399+
325400 describe ( 'loadContextConfigObjects' , ( ) => {
326401 it ( 'should fail if name is missing from context' , ( ) => {
327402 expect ( ( ) => {
@@ -581,7 +656,7 @@ describe('KubeConfig', () => {
581656 const data = readFileSync ( kcFileName ) ;
582657 const dir = join ( process . env . HOME , '.kube' ) ;
583658 const arg = { } ;
584- arg [ dir ] = { config : data } ;
659+ arg [ dir ] = { config : data } ;
585660 mockfs ( arg ) ;
586661
587662 const kc = new KubeConfig ( ) ;
0 commit comments