-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
47 lines (34 loc) · 1.36 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable unicorn/prefer-module, ava/no-skip-test */
import fs from 'node:fs';
import path from 'node:path';
import test from 'ava';
import sinon from 'sinon';
const require = {};
// TODO: Enable tests again when ESM supports loader hooks.
test.skip('inside a Docker container (.dockerenv test)', t => {
delete require.cache[path.join(__dirname, 'index.js')];
const isDocker = require('.');
fs.statSync = sinon.stub(fs, 'statSync');
fs.statSync.withArgs('/.dockerenv').returns({});
t.true(isDocker());
fs.statSync.restore();
});
test.skip('inside a Docker container (cgroup test)', t => {
delete require.cache[path.join(__dirname, 'index.js')];
const isDocker = require('.');
fs.statSync = sinon.stub(fs, 'statSync');
fs.statSync.withArgs('/.dockerenv').throws('ENOENT, no such file or directory \'/.dockerinit\'');
fs.readFileSync = sinon.stub(fs, 'readFileSync');
fs.readFileSync.withArgs('/proc/self/cgroup', 'utf8').returns('xxx docker yyyy');
t.true(isDocker());
fs.readFileSync.restore();
fs.statSync.restore();
});
test.skip('not inside a Docker container', t => {
delete require.cache[path.join(__dirname, 'index.js')];
const isDocker = require('.');
fs.statSync = sinon.stub(fs, 'statSync');
fs.statSync.withArgs('/.dockerenv').throws('ENOENT, no such file or directory \'/.dockerinit\'');
t.false(isDocker());
fs.statSync.restore();
});