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');
|
|
|
|
|
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';
|
2013-12-10 15:52:27 +01:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
assert.equal(os.tmpdir(), '/temp');
|
|
|
|
process.env.TEMP = '';
|
|
|
|
assert.equal(os.tmpdir(), '/tmp');
|
|
|
|
process.env.TMP = '';
|
|
|
|
var expected = (process.env.SystemRoot || process.env.windir) + '\\temp';
|
|
|
|
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':
|
2011-06-17 22:40:29 +02:00
|
|
|
var filter = function(e) { return e.address == '127.0.0.1'; };
|
|
|
|
var actual = interfaces.lo.filter(filter);
|
2013-02-10 23:19:43 +01:00
|
|
|
var expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
|
2013-08-01 22:53:19 +02:00
|
|
|
mac: '00:00:00:00:00:00', family: 'IPv4',
|
|
|
|
internal: true }];
|
2011-06-17 22:40:29 +02:00
|
|
|
assert.deepEqual(actual, expected);
|
2011-03-17 00:31:38 +01:00
|
|
|
break;
|
2011-12-15 21:36:05 +01:00
|
|
|
case 'win32':
|
|
|
|
var filter = function(e) { return e.address == '127.0.0.1'; };
|
|
|
|
var actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter);
|
2013-12-10 20:32:29 +01:00
|
|
|
var expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
|
2013-08-01 22:53:19 +02:00
|
|
|
mac: '00:00:00:00:00:00', family: 'IPv4',
|
|
|
|
internal: true }];
|
2011-12-15 21:36:05 +01:00
|
|
|
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);
|