Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions packages/vertica-nodejs/lib/connection-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ class ConnectionParameters {
}

try {
this.client_os = os.platform()
this.client_os = `${os.type()} ${os.release()} ${os.arch()}`
} catch (e) {
this.client_os = ""
try {
this.client_os = os.platform()
} catch (e2) {
this.client_os = "unknown"
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('vertica-nodejs handling auditing connection properties', function() {
assert.equal(res.rows[0].client_pid, process.pid)
assert.equal(res.rows[0].client_type, "Node.js Driver")
assert.equal(res.rows[0].client_version, vertica.version)
assert.equal(res.rows[0].client_os, os.platform())
assert.equal(res.rows[0].client_os, `${os.type()} ${os.release()} ${os.arch()}`)
assert.equal(res.rows[0].client_os_user_name, os.userInfo().username)
assert.equal(res.rows[0].client_os_hostname, os.hostname())
client.end()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'
const helper = require('../test-helper')
const assert = require('assert')
const os = require('os')
const ConnectionParameters = require('../../../lib/connection-parameters')

const suite = new helper.Suite()

suite.test('client_os provides detailed OS string', function () {
const subject = new ConnectionParameters()
const expected = `${os.type()} ${os.release()} ${os.arch()}`
assert.equal(subject.client_os, expected)
})

suite.test('client_os falls back to os.platform() when detailed retrieval fails', function () {
const originalType = os.type
const originalRelease = os.release
const originalArch = os.arch
try {
os.type = function () { throw new Error('type fail') }
os.release = function () { throw new Error('release fail') }
os.arch = function () { throw new Error('arch fail') }

const subject = new ConnectionParameters()
assert.equal(subject.client_os, os.platform())
} finally {
os.type = originalType
os.release = originalRelease
os.arch = originalArch
}
})

suite.test('client_os uses "unknown" when both detailed and platform retrieval fail', function () {
const originalType = os.type
const originalRelease = os.release
const originalArch = os.arch
const originalPlatform = os.platform
try {
os.type = function () { throw new Error('type fail') }
os.release = function () { throw new Error('release fail') }
os.arch = function () { throw new Error('arch fail') }
os.platform = function () { throw new Error('platform fail') }

const subject = new ConnectionParameters()
assert.equal(subject.client_os, 'unknown')
} finally {
os.type = originalType
os.release = originalRelease
os.arch = originalArch
os.platform = originalPlatform
}
})
Loading