Skip to content

Commit 2218800

Browse files
authored
Enhance client_os reporting for vertica-nodejs (#159)
Report detailed client_os with robust fallback and tests
1 parent b10298b commit 2218800

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

packages/vertica-nodejs/lib/connection-parameters.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ class ConnectionParameters {
144144
}
145145

146146
try {
147-
this.client_os = os.platform()
147+
this.client_os = `${os.type()} ${os.release()} ${os.arch()}`
148148
} catch (e) {
149-
this.client_os = ""
149+
try {
150+
this.client_os = os.platform()
151+
} catch (e2) {
152+
this.client_os = "unknown"
153+
}
150154
}
151155

152156
try {

packages/vertica-nodejs/mochatest/integration/client/vertica-connection-params-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('vertica-nodejs handling auditing connection properties', function() {
114114
assert.equal(res.rows[0].client_pid, process.pid)
115115
assert.equal(res.rows[0].client_type, "Node.js Driver")
116116
assert.equal(res.rows[0].client_version, vertica.version)
117-
assert.equal(res.rows[0].client_os, os.platform())
117+
assert.equal(res.rows[0].client_os, `${os.type()} ${os.release()} ${os.arch()}`)
118118
assert.equal(res.rows[0].client_os_user_name, os.userInfo().username)
119119
assert.equal(res.rows[0].client_os_hostname, os.hostname())
120120
client.end()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)