Skip to content

Commit d6a2bd8

Browse files
committed
Fix optionsParser.js typos and boolean value parsing
1 parent 7f26e48 commit d6a2bd8

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

lib/optionsParser.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ class ConnectionOptions {
6868
const argsProcessor = yargs
6969
.usage('$0 [args]')
7070
.options({
71-
'conn-urls': { describe: 'broker adresses and ports for failover conection e.g. "host1:port,host2:port"]', type: 'string'},
72-
'conn-use-config-file': { default: false, describe: 'use configuration file for connection', type: ['boolean', 'string']},
73-
'conn-reconnect': { default: true, describe: 'client reconnect settings', type: ['boolean', 'string']},
71+
'conn-urls': { describe: 'broker addresses and ports for failover connection e.g. "host1:port,host2:port"]', type: 'string'},
72+
'conn-use-config-file': { default: false, describe: 'use configuration file for connection', type: 'boolean'},
73+
'conn-reconnect': { default: true, describe: 'client reconnect settings', type: 'boolean'},
7474
'conn-reconnect-interval': { describe: 'client reconnect interval (only supported with "custom" reconnect")', type: 'float'},
7575
'conn-reconnect-limit': { describe: 'client reconnect limit (only supported with "custom" reconnect)', type: 'int'},
7676
'conn-reconnect-timeout': { describe: 'client reconnect timeout (only supported with "custom" reconnect)', type: 'int'},
77-
'conn-heartbeat': { deafult: 0, describe: 'heartbeat in second', type: 'uint'},
78-
'conn-ssl': { default: false, describe: 'enable tls connection', type: ['boolean', 'string']},
77+
'conn-heartbeat': { default: 0, describe: 'heartbeat in second', type: 'uint'},
78+
'conn-ssl': { default: false, describe: 'enable tls connection', type: 'boolean'},
7979
'conn-ssl-certificate': { describe: 'path to client certificate (PEM format), enables client authentication', type: 'string'},
8080
'conn-ssl-private-key': { describe: 'path to client private key (PEM format), conn-ssl-certificate must be given', type: 'string'},
8181
'conn-ssl-password': { describe: 'client\'s certificate database password', type: 'string' },
8282
'conn-ssl-trust-store': { describe: 'path to client trust store (PEM format), conn-ssl-certificate must be given', type: 'string' },
8383
'conn-ssl-verify-peer': { default: false, describe: 'verifies server certificate, conn-ssl-certificate and trusted db path needs to be specified (PEM format)', type: 'boolean'},
8484
'conn-ssl-verify-peer-name': { default: false, describe: 'verifies connection url against server hostname', type: 'boolean'},
8585
'conn-max-frame-size': { default: undefined, describe: 'defines max frame size for connection', type: 'uint'},
86-
'conn-web-socket': { alias: 'conn-ws', default: false, describe: 'use websocket as transport layer', type: ['boolean', 'string']},
87-
'conn-web-socket-protocols': { alias: 'conn-ws-protocols', describe: 'protocol for ws connection', type: 'array', deafult: ['binary', 'AMQPWSB10', 'amqp']},
86+
'conn-web-socket': { alias: 'conn-ws', default: false, describe: 'use websocket as transport layer', type: 'boolean'},
87+
'conn-web-socket-protocols': { alias: 'conn-ws-protocols', describe: 'protocol for ws connection', type: 'array', default: ['binary', 'AMQPWSB10', 'amqp']},
8888
'conn-property': { describe: 'Sets connection property map item'},
8989
'broker': { alias: 'b', default: 'localhost:5672', describe: 'address of machine with broker (i.e. admin:admin@broker-address:5672)'},
9090
})
@@ -445,7 +445,7 @@ class ReceiverOptions extends SenderReceiverOptions {
445445
'action': { default: 'acknowledge', describe: 'action on acquired message', choices: ['acknowledge', 'reject', 'release', 'noack']},
446446
'capacity': { default: 0 ,describe: 'set sender capacity', type: 'uint'},
447447
'process-reply-to': { default: false ,describe: 'send message to reply-to address if enabled and message got reply-to address', type: 'boolean'},
448-
'recv-listen': { default: false, describe: 'enable receiver listen (P2P)', type: ['boolean', 'string']},
448+
'recv-listen': { default: false, describe: 'enable receiver listen (P2P)', type: 'boolean'},
449449
'recv-listen-port': { default: 5672, describe: 'define port for local listening', type: ['uint']},
450450
'reactor-auto-settle-off': { default: false, describe: 'disable auto settling', type: 'boolean'},
451451
});

test/optionsParserTest.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Red Hat Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
let expect = require('chai').expect;
19+
let optionsParser = require('../lib/optionsParser');
20+
21+
describe('options parser', () => {
22+
describe('parsing --conn-use-config-file', () => {
23+
let options = new optionsParser.SenderOptions()
24+
it('parse true value', () => {
25+
options.parseConnectionOptions(["--conn-use-config-file", "true"]);
26+
expect(options.useConfigFile).is.true
27+
});
28+
it('parse false value', () => {
29+
options.parseConnectionOptions(["--conn-use-config-file", "false"]);
30+
expect(options.useConfigFile).is.false
31+
});
32+
it('default to true with no value', () => {
33+
options.parseConnectionOptions(["--conn-use-config-file"]);
34+
expect(options.useConfigFile).is.true
35+
});
36+
it('default to false', () => {
37+
options.parseConnectionOptions([]);
38+
expect(options.useConfigFile).is.false
39+
});
40+
});
41+
describe('parsing --conn-reconnect', () => {
42+
let options = new optionsParser.SenderOptions()
43+
it('default to true with no value', () => {
44+
options.parseConnectionOptions(["--conn-ssl"]);
45+
expect(options.reconnect).is.true
46+
});
47+
it('default to true', () => {
48+
options.parseConnectionOptions([]);
49+
expect(options.reconnect).is.true
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)