diff --git a/lib/sproxyd.js b/lib/sproxyd.js index 67300ea..3e9ea72 100644 --- a/lib/sproxyd.js +++ b/lib/sproxyd.js @@ -81,7 +81,7 @@ class SproxydClient { this.bootstrap = opts.bootstrap === undefined ? [['localhost', '81']] : _parseBootstrapList(opts.bootstrap); this.bootstrap = shuffle(this.bootstrap); - if (options.chordCos) { + if (options.chordCos !== undefined && options.chordCos !== null) { this.cos = options.chordCos; this.path = options.path || '/proxy/chord/'; } else { diff --git a/package.json b/package.json index 5493a54..61849f7 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "engines": { "node": ">=20" }, - "version": "8.2.0", + "version": "8.2.1", "description": "sproxyd client", "main": "index.js", "scripts": { diff --git a/tests/unit/sproxyd.js b/tests/unit/sproxyd.js index 0d9d780..fbe7ec8 100644 --- a/tests/unit/sproxyd.js +++ b/tests/unit/sproxyd.js @@ -374,6 +374,38 @@ const clientImmutableWithFailover = new Sproxy({ }); }); +describe('Sproxyd constructor chordCos', () => { + it('should default to cos 2 when chordCos is absent', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'] }); + assert.strictEqual(c.cos, 0x2); + }); + + it('should default to cos 2 when chordCos is undefined', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'], chordCos: undefined }); + assert.strictEqual(c.cos, 0x2); + }); + + it('should default to cos 2 when chordCos is null', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'], chordCos: null }); + assert.strictEqual(c.cos, 0x2); + }); + + it('should set cos 0 when chordCos is 0 (integer)', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'], chordCos: 0 }); + assert.strictEqual(c.cos, 0); + }); + + it('should set cos "0" when chordCos is "0" (string)', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'], chordCos: '0' }); + assert.strictEqual(c.cos, '0'); + }); + + it('should set cos when chordCos is a non-zero integer', () => { + const c = new Sproxy({ bootstrap: ['127.0.0.1:9000'], chordCos: 3 }); + assert.strictEqual(c.cos, 3); + }); +}); + describe('Sproxyd client', () => { const client = new Sproxy({ bootstrap: ['127.0.0.1:9000'] }); clientAssert(client.bootstrap, client.path);