From f2a751455b305f98e5255a684af8fa412b490891 Mon Sep 17 00:00:00 2001 From: Bernd Niehues Date: Mon, 2 Sep 2019 15:58:47 +0200 Subject: [PATCH 1/5] [FEATURE] Add test for coap option Add test cases for coap options. --- test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test.js b/test.js index 0758e3e..32bebf3 100644 --- a/test.js +++ b/test.js @@ -270,4 +270,38 @@ describe('coap', function () { res.end() }) }) + + it('should support coap option as string', function (done) { + call('-O 2048,HelloWorld', 'coap://localhost') + + server.once('request', function (req, res) { + res.end('') + try { + expect(req._packet.options.length).to.eql(1) + expect(req._packet.options[0].name).to.eql('2048') + expect(req._packet.options[0].value.toString()).to.eql('HelloWorld') + done() + } catch (err) { + done(err) + } + }) + }) + + it('should support multiple coap options as string', function (done) { + call('-O 2048,HelloWorld', '-O 2050,FooBarBaz', 'coap://localhost') + + server.once('request', function (req, res) { + res.end('') + try { + expect(req._packet.options.length).to.eql(2) + expect(req._packet.options[0].name).to.eql('2048') + expect(req._packet.options[0].value.toString()).to.eql('HelloWorld') + expect(req._packet.options[1].name).to.eql('2050') + expect(req._packet.options[1].value.toString()).to.eql('FooBarBaz') + done() + } catch (err) { + done(err) + } + }) + }) }) From 8acec5c634f4e0834f5f7cab61f4583985a95ccb Mon Sep 17 00:00:00 2001 From: Bernd Niehues Date: Mon, 2 Sep 2019 16:20:48 +0200 Subject: [PATCH 2/5] [FEATURE] Use real examples for coap options The coap-option collector now uses real examples in case of failed requests. Add example to option description as well. Resolves: #40 --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 450c2e5..c10c80c 100755 --- a/index.js +++ b/index.js @@ -18,8 +18,8 @@ function collectOptions (val, memo) { } else { console.log('Error: Option \'%s\' is invalid.', val) console.log('Please provide options in this way:') - console.log('-O [Key]" + coapOptionSeperator + "[Value]') - console.log('OR --coap-option [Key]' + coapOptionSeperator + '[Value]') + console.log('-O 2048,HelloWorld') + console.log('OR --coap-option 2048,HelloWorld') process.exit(-1) } return memo @@ -35,7 +35,7 @@ program .option('-c, --non-confirmable', 'non-confirmable', 'boolean', false) .option('-t, --timeout ', 'The maximum send time in seconds') .option('-T, --show-timing', 'Print request time, handy for simple performance tests', 'boolean', false) - .option('-O, --coap-option