Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for isFakeRoot #4435

Merged
merged 2 commits into from
Sep 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion __tests__/util/root-user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/* @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', () => {
delete process.env.FAKEROOTKEY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should explicitly set this to '' or something since deleting would just restore it to the default value if the system running this. So if the tests were run with fakreoot then deleting that env variable would just reset it to the system value.

Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out, and delete process.env.FAKEROOTKEY removes the key from the object.
Running the tests with fakeroot actually works.

Copy link
Member

@BYK BYK Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I've tested locally to see the same result. That said be advised that deleting it like this actually removes any existing value without any way for restoring it so your test is actually affecting the global state permanently.

Are you sure you want to do that?


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

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

delete process.env.FAKEROOTKEY;
});