Skip to content

Commit 2d9f717

Browse files
committed
Fix unit tests
1 parent 514bea3 commit 2d9f717

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

src/config_test.ts

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,15 @@ describe('KubeConfig', () => {
461461
process.env.HOMEPATH = originalEnvVars.HOMEPATH;
462462
});
463463

464-
it('should return null if no home is present', () => {
464+
it('should return null if no home-ish env vars are set', () => {
465465
const dir = findHomeDir();
466466
expect(dir).to.equal(null);
467467
});
468468

469469
describe('look for an existing .kube/config', () => {
470470
let allDirs;
471471
let homeDrive;
472-
before(() => {
472+
beforeEach(() => {
473473
allDirs = {};
474474
process.env.HOME = 'home';
475475
process.env.HOMEDRIVE = 'drive';
@@ -481,7 +481,7 @@ describe('KubeConfig', () => {
481481
allDirs[process.env.USERPROFILE] = {};
482482
});
483483
it('should load from HOME if present', () => {
484-
const dir = process.env.HOME;
484+
const dir = process.env.HOME as string;
485485
allDirs[dir]['.kube'] = { config: 'data' };
486486
mockfs(allDirs);
487487

@@ -491,10 +491,10 @@ describe('KubeConfig', () => {
491491
expect(home).to.equal(dir);
492492
});
493493
it('should favor HOME when present', () => {
494-
const dir = process.env.HOME;
494+
const dir = process.env.HOME as string;
495495
allDirs[dir]['.kube'] = { config: 'data' };
496496
allDirs[homeDrive]['.kube'] = { config: 'data' };
497-
allDirs[process.env.USERPROFILE]['.kube'] = { config: 'data' };
497+
allDirs[process.env.USERPROFILE as string]['.kube'] = { config: 'data' };
498498
mockfs(allDirs);
499499

500500
const home = findHomeDir();
@@ -506,7 +506,7 @@ describe('KubeConfig', () => {
506506
it('should load from HOMEDRIVE/HOMEPATH if present', () => {
507507
const dir = homeDrive;
508508
allDirs[dir]['.kube'] = { config: 'data' };
509-
mockfs(arg);
509+
mockfs(allDirs);
510510

511511
const home = findHomeDir();
512512

@@ -517,8 +517,8 @@ describe('KubeConfig', () => {
517517
it('should favor HOMEDRIVE/HOMEPATH over USERPROFILE', () => {
518518
const dir = homeDrive;
519519
allDirs[dir]['.kube'] = { config: 'data' };
520-
allDirs[process.env.USERPROFILE]['.kube'] = { config: 'data' };
521-
mockfs(arg);
520+
allDirs[process.env.USERPROFILE as string]['.kube'] = { config: 'data' };
521+
mockfs(allDirs);
522522

523523
const home = findHomeDir();
524524

@@ -527,9 +527,9 @@ describe('KubeConfig', () => {
527527
});
528528

529529
it('should load from USERPROFILE if present', () => {
530-
const dir = process.env.USERPROFILE;
530+
const dir = process.env.USERPROFILE as string;
531531
allDirs[dir]['.kube'] = { config: 'data' };
532-
mockfs(arg);
532+
mockfs(allDirs);
533533

534534
const home = findHomeDir();
535535

@@ -538,11 +538,11 @@ describe('KubeConfig', () => {
538538
});
539539
});
540540

541-
// Just test for existence,but this will include the writability order
541+
// Just test for existence,but this will include the writeability order
542542
describe('look for an existing directory', () => {
543543
let allDirs;
544544
let homeDrive;
545-
before(() => {
545+
beforeEach(() => {
546546
allDirs = {};
547547
process.env.HOME = 'home';
548548
process.env.HOMEDRIVE = 'drive';
@@ -551,52 +551,44 @@ describe('KubeConfig', () => {
551551
homeDrive = join(process.env.HOMEDRIVE, process.env.HOMEPATH);
552552
});
553553
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
554+
allDirs[process.env.HOME as string] = 'data';
555+
allDirs[homeDrive] = 'data';
556+
allDirs[process.env.USERPROFILE as string] = 'data';
557+
const dir = process.env.HOME;
560558
mockfs(allDirs);
561559

562560
const home = findHomeDir();
563561

564562
mockfs.restore();
565563
expect(home).to.equal(dir);
566564
});
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
565+
it('should load from USERPROFILE if present', () => {
566+
allDirs[homeDrive] = 'data';
567+
allDirs[process.env.USERPROFILE as string] = 'data';
573568
mockfs(allDirs);
574569

575570
const home = findHomeDir();
576571

577572
mockfs.restore();
578-
expect(home).to.equal(homeDrive);
573+
expect(home).to.equal(process.env.USERPROFILE);
579574
});
580-
it('should load from USERPROFILE if present', () => {
581-
allDirs = {
582-
[process.env.USERPROFILE]: 'data'
583-
}
584-
const dir = process.env.USERPROFILE;
575+
it('should load from homeDrive if present', () => {
576+
allDirs[homeDrive] = 'data';
585577
mockfs(allDirs);
586578

587579
const home = findHomeDir();
588580

589581
mockfs.restore();
590-
expect(home).to.equal(dir);
582+
expect(home).to.equal(homeDrive);
591583
});
592-
});
593-
it('should return null if nothing is present', () => {
594-
mockfs({});
584+
it('should return HOME when no home-ish directories are present', () => {
585+
mockfs({});
595586

596-
const home = findHomeDir();
587+
const home = findHomeDir();
597588

598-
mockfs.restore();
599-
expect(home).to.equal(null);
589+
mockfs.restore();
590+
expect(home).to.equal(process.env.HOME);
591+
});
600592
});
601593
});
602594

0 commit comments

Comments
 (0)