From 78a5f3379fd3f0e3eeae680166022846925cf660 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 13 Sep 2017 23:16:34 +0200 Subject: [PATCH] Chore: Add test for isFakeRoot (#4435) **Summary** Follow up to #4431. `isFakeRoot` didn't have any tests and it was broken from the start. #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 --- __tests__/util/root-user.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/__tests__/util/root-user.js b/__tests__/util/root-user.js index 4e214261bc..e06a4d2140 100644 --- a/__tests__/util/root-user.js +++ b/__tests__/util/root-user.js @@ -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; + } +});