Skip to content

Commit

Permalink
Chore: Add test for isFakeRoot (yarnpkg#4435)
Browse files Browse the repository at this point in the history
**Summary**

Follow up to yarnpkg#4431. `isFakeRoot` didn't have any tests and it was broken from the start. yarnpkg#4431 solved it and it was merged to be included in 1.0.2 without tests. This patch adds the missing tests for this function.

**Test plan**

Added new tests, duh :D
  • Loading branch information
martinstuecklschwaiger authored and joaolucasl committed Oct 27, 2017
1 parent 2900106 commit 32b5f5b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion __tests__/util/root-user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
/* @flow */

import {isRootUser} from '../../src/util/root-user.js';
import {isRootUser, isFakeRoot} from '../../src/util/root-user.js';

test('isRootUser', () => {
expect(isRootUser(null)).toBe(false);
expect(isRootUser(1001)).toBe(false);
expect(isRootUser(0)).toBe(true);
});

test('isFakeRoot', () => {
const hasFakerootPreviously = 'FAKEROOTKEY' in process.env;
const oldValue = process.env.FAKEROOTKEY;
delete process.env.FAKEROOTKEY;

expect(isFakeRoot()).toBe(false);

process.env.FAKEROOTKEY = '15574641';
expect(isFakeRoot()).toBe(true);

if (hasFakerootPreviously) {
process.env.FAKEROOTKEY = oldValue;
}
});

0 comments on commit 32b5f5b

Please sign in to comment.