2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2010-12-22 19:55:47 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var os = require('os');
|
2015-05-25 17:01:42 +02:00
|
|
|
var path = require('path');
|
2010-12-22 19:55:47 +01:00
|
|
|
|
2011-04-14 03:11:21 +02:00
|
|
|
|
2012-06-13 04:05:51 +02:00
|
|
|
process.env.TMPDIR = '/tmpdir';
|
|
|
|
process.env.TMP = '/tmp';
|
|
|
|
process.env.TEMP = '/temp';
|
2015-05-25 17:01:42 +02:00
|
|
|
if (common.isWindows) {
|
2013-12-10 15:52:27 +01:00
|
|
|
assert.equal(os.tmpdir(), '/temp');
|
|
|
|
process.env.TEMP = '';
|
|
|
|
assert.equal(os.tmpdir(), '/tmp');
|
|
|
|
process.env.TMP = '';
|
2016-01-31 06:20:37 +01:00
|
|
|
const expected = (process.env.SystemRoot || process.env.windir) + '\\temp';
|
2013-12-10 15:52:27 +01:00
|
|
|
assert.equal(os.tmpdir(), expected);
|
2015-02-06 23:27:22 +01:00
|
|
|
process.env.TEMP = '\\temp\\';
|
|
|
|
assert.equal(os.tmpdir(), '\\temp');
|
2015-05-11 18:11:01 +02:00
|
|
|
process.env.TEMP = '\\tmpdir/';
|
|
|
|
assert.equal(os.tmpdir(), '\\tmpdir/');
|
|
|
|
process.env.TEMP = '\\';
|
|
|
|
assert.equal(os.tmpdir(), '\\');
|
|
|
|
process.env.TEMP = 'C:\\';
|
|
|
|
assert.equal(os.tmpdir(), 'C:\\');
|
2013-12-10 15:52:27 +01:00
|
|
|
} else {
|
|
|
|
assert.equal(os.tmpdir(), '/tmpdir');
|
|
|
|
process.env.TMPDIR = '';
|
|
|
|
assert.equal(os.tmpdir(), '/tmp');
|
|
|
|
process.env.TMP = '';
|
|
|
|
assert.equal(os.tmpdir(), '/temp');
|
|
|
|
process.env.TEMP = '';
|
|
|
|
assert.equal(os.tmpdir(), '/tmp');
|
2015-02-06 23:27:22 +01:00
|
|
|
process.env.TMPDIR = '/tmpdir/';
|
|
|
|
assert.equal(os.tmpdir(), '/tmpdir');
|
2015-05-11 18:11:01 +02:00
|
|
|
process.env.TMPDIR = '/tmpdir\\';
|
|
|
|
assert.equal(os.tmpdir(), '/tmpdir\\');
|
|
|
|
process.env.TMPDIR = '/';
|
|
|
|
assert.equal(os.tmpdir(), '/');
|
2013-12-10 15:52:27 +01:00
|
|
|
}
|
2012-06-13 04:05:51 +02:00
|
|
|
|
2012-11-08 21:31:45 +01:00
|
|
|
var endianness = os.endianness();
|
|
|
|
console.log('endianness = %s', endianness);
|
|
|
|
assert.ok(/[BL]E/.test(endianness));
|
|
|
|
|
2011-10-05 00:08:18 +02:00
|
|
|
var hostname = os.hostname();
|
|
|
|
console.log('hostname = %s', hostname);
|
2011-03-27 12:14:34 +02:00
|
|
|
assert.ok(hostname.length > 0);
|
|
|
|
|
|
|
|
var uptime = os.uptime();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('uptime = %d', uptime);
|
2011-03-27 12:14:34 +02:00
|
|
|
assert.ok(uptime > 0);
|
|
|
|
|
|
|
|
var cpus = os.cpus();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('cpus = ', cpus);
|
2011-03-27 12:14:34 +02:00
|
|
|
assert.ok(cpus.length > 0);
|
|
|
|
|
|
|
|
var type = os.type();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('type = ', type);
|
2011-03-27 12:14:34 +02:00
|
|
|
assert.ok(type.length > 0);
|
|
|
|
|
|
|
|
var release = os.release();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('release = ', release);
|
2011-03-27 12:14:34 +02:00
|
|
|
assert.ok(release.length > 0);
|
|
|
|
|
2011-04-27 05:02:54 +02:00
|
|
|
var platform = os.platform();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('platform = ', platform);
|
2011-04-27 05:02:54 +02:00
|
|
|
assert.ok(platform.length > 0);
|
|
|
|
|
|
|
|
var arch = os.arch();
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('arch = ', arch);
|
2011-04-27 05:02:54 +02:00
|
|
|
assert.ok(arch.length > 0);
|
|
|
|
|
2011-03-27 12:14:34 +02:00
|
|
|
if (process.platform != 'sunos') {
|
|
|
|
// not implemeneted yet
|
|
|
|
assert.ok(os.loadavg().length > 0);
|
|
|
|
assert.ok(os.freemem() > 0);
|
|
|
|
assert.ok(os.totalmem() > 0);
|
|
|
|
}
|
2011-03-17 00:31:38 +01:00
|
|
|
|
|
|
|
|
2011-11-01 17:23:17 +01:00
|
|
|
var interfaces = os.networkInterfaces();
|
2011-03-17 00:31:38 +01:00
|
|
|
console.error(interfaces);
|
2011-04-27 05:02:54 +02:00
|
|
|
switch (platform) {
|
2011-03-17 00:31:38 +01:00
|
|
|
case 'linux':
|
2016-01-31 06:20:37 +01:00
|
|
|
{
|
|
|
|
const filter = function(e) { return e.address == '127.0.0.1'; };
|
|
|
|
const actual = interfaces.lo.filter(filter);
|
|
|
|
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
|
|
|
|
mac: '00:00:00:00:00:00', family: 'IPv4',
|
|
|
|
internal: true }];
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-15 21:36:05 +01:00
|
|
|
case 'win32':
|
2016-01-31 06:20:37 +01:00
|
|
|
{
|
|
|
|
const filter = function(e) { return e.address == '127.0.0.1'; };
|
|
|
|
const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter);
|
|
|
|
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
|
|
|
|
mac: '00:00:00:00:00:00', family: 'IPv4',
|
|
|
|
internal: true }];
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
break;
|
|
|
|
}
|
2011-03-17 00:31:38 +01:00
|
|
|
}
|
2012-04-12 10:29:15 +02:00
|
|
|
|
|
|
|
var EOL = os.EOL;
|
|
|
|
assert.ok(EOL.length > 0);
|
2015-05-25 17:01:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
var home = os.homedir();
|
|
|
|
|
|
|
|
console.log('homedir = ' + home);
|
|
|
|
assert.ok(typeof home === 'string');
|
|
|
|
assert.ok(home.indexOf(path.sep) !== -1);
|
|
|
|
|
|
|
|
if (common.isWindows && process.env.USERPROFILE) {
|
|
|
|
assert.equal(home, process.env.USERPROFILE);
|
|
|
|
delete process.env.USERPROFILE;
|
|
|
|
assert.ok(os.homedir().indexOf(path.sep) !== -1);
|
|
|
|
process.env.USERPROFILE = home;
|
|
|
|
} else if (!common.isWindows && process.env.HOME) {
|
|
|
|
assert.equal(home, process.env.HOME);
|
|
|
|
delete process.env.HOME;
|
|
|
|
assert.ok(os.homedir().indexOf(path.sep) !== -1);
|
|
|
|
process.env.HOME = home;
|
|
|
|
}
|