|
| 1 | +'use strict' |
| 2 | +const helper = require('../test-helper') |
| 3 | +const assert = require('assert') |
| 4 | +const os = require('os') |
| 5 | +const ConnectionParameters = require('../../../lib/connection-parameters') |
| 6 | + |
| 7 | +const suite = new helper.Suite() |
| 8 | + |
| 9 | +suite.test('client_os provides detailed OS string', function () { |
| 10 | + const subject = new ConnectionParameters() |
| 11 | + const expected = `${os.type()} ${os.release()} ${os.arch()}` |
| 12 | + assert.equal(subject.client_os, expected) |
| 13 | +}) |
| 14 | + |
| 15 | +suite.test('client_os falls back to os.platform() when detailed retrieval fails', function () { |
| 16 | + const originalType = os.type |
| 17 | + const originalRelease = os.release |
| 18 | + const originalArch = os.arch |
| 19 | + try { |
| 20 | + os.type = function () { throw new Error('type fail') } |
| 21 | + os.release = function () { throw new Error('release fail') } |
| 22 | + os.arch = function () { throw new Error('arch fail') } |
| 23 | + |
| 24 | + const subject = new ConnectionParameters() |
| 25 | + assert.equal(subject.client_os, os.platform()) |
| 26 | + } finally { |
| 27 | + os.type = originalType |
| 28 | + os.release = originalRelease |
| 29 | + os.arch = originalArch |
| 30 | + } |
| 31 | +}) |
| 32 | + |
| 33 | +suite.test('client_os uses "unknown" when both detailed and platform retrieval fail', function () { |
| 34 | + const originalType = os.type |
| 35 | + const originalRelease = os.release |
| 36 | + const originalArch = os.arch |
| 37 | + const originalPlatform = os.platform |
| 38 | + try { |
| 39 | + os.type = function () { throw new Error('type fail') } |
| 40 | + os.release = function () { throw new Error('release fail') } |
| 41 | + os.arch = function () { throw new Error('arch fail') } |
| 42 | + os.platform = function () { throw new Error('platform fail') } |
| 43 | + |
| 44 | + const subject = new ConnectionParameters() |
| 45 | + assert.equal(subject.client_os, 'unknown') |
| 46 | + } finally { |
| 47 | + os.type = originalType |
| 48 | + os.release = originalRelease |
| 49 | + os.arch = originalArch |
| 50 | + os.platform = originalPlatform |
| 51 | + } |
| 52 | +}) |
0 commit comments