Skip to content

Commit

Permalink
feat: make ping method public
Browse files Browse the repository at this point in the history
  • Loading branch information
hduprat-qare authored and kylefarris committed Oct 18, 2024
1 parent 6ef4213 commit 45d5801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class NodeClam {
if (this.settings.debugMode)
console.log(`${this.debugLabel}: Initially testing socket/tcp connection to clamscan server.`);
try {
const client = await this._ping();
const client = await this.ping();
client.end();
if (this.settings.debugMode)
console.log(`${this.debugLabel}: Established connection to clamscan server!`);
Expand Down Expand Up @@ -684,11 +684,10 @@ class NodeClam {
* Quick check to see if the remote/local socket is working. Callback/Resolve
* response is an instance to a ClamAV socket client.
*
* @private
* @param {Function} [cb] - What to do after the ping
* @returns {Promise<object>} A copy of the Socket/TCP client
*/
_ping(cb) {
ping(cb) {
let hasCb = false;

// Verify second param, if supplied, is a function
Expand All @@ -704,7 +703,7 @@ class NodeClam {
// eslint-disable-next-line consistent-return
return new Promise(async (resolve, reject) => {
try {
client = await this._initSocket('_ping');
client = await this._initSocket('ping');

if (this.settings.debugMode)
console.log(`${this.debugLabel}: Established connection to clamscan server!`);
Expand Down
16 changes: 8 additions & 8 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,21 @@ describe('_initSocket', () => {
});
});

describe('_ping', () => {
describe('ping', () => {
let clamscan;
beforeEach(async () => {
clamscan = await resetClam();
});

it('should exist', () => {
should.exist(clamscan._ping);
should.exist(clamscan.ping);
});
it('should be a function', () => {
clamscan._ping.should.be.a('function');
clamscan.ping.should.be.a('function');
});

it('should respond with a socket client (Promise API)', async () => {
const client = await clamscan._ping();
const client = await clamscan.ping();
expect(client).to.be.an('object');
expect(client.readyState).to.eql('open');
expect(client.writable).to.eql(true);
Expand All @@ -438,7 +438,7 @@ describe('_ping', () => {
});

it('should respond with a socket client (Callback API)', (done) => {
clamscan._ping((err, client) => {
clamscan.ping((err, client) => {
check(done, () => {
expect(err).to.not.be.instanceof(Error);
expect(client).to.be.an('object');
Expand Down Expand Up @@ -1744,7 +1744,7 @@ if (process.env.CI) {
tls: true,
},
});
(await clamscan._ping()).end();
(await clamscan.ping()).end();
});

it('Connects to clamd server via a TLS proxy on 127.0.0.1', async () => {
Expand All @@ -1756,7 +1756,7 @@ if (process.env.CI) {
tls: true,
},
});
(await clamscan._ping()).end();
(await clamscan.ping()).end();
});

it('Connects to clamd server via a TLS proxy on ::1', async () => {
Expand All @@ -1768,7 +1768,7 @@ if (process.env.CI) {
tls: true,
},
});
(await clamscan._ping()).end();
(await clamscan.ping()).end();
});

// it('Connects to clamd server via a TLS proxy on implicit localhost', async () => {
Expand Down

0 comments on commit 45d5801

Please sign in to comment.