From 4afe231bc8371560cc87f6865d74f052691ea582 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Tue, 24 Aug 2010 00:02:30 +0100 Subject: use new paths and smarten up the test results --- jarmon/jarmon.test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 jarmon/jarmon.test.js (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js new file mode 100644 index 0000000..b6ee035 --- /dev/null +++ b/jarmon/jarmon.test.js @@ -0,0 +1,40 @@ +/* Copyright (c) 2010 Richard Wall + * See LICENSE for details. + * + * Unit tests for Jarmon + **/ + +YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { + Y.Test.Runner.add(new Y.Test.Case({ + name: "jarmon.downloadBinary", + + setUp : function () { + }, + + tearDown : function () { + }, + + test_urlNotFound: function () { + var d = new jarmon.downloadBinary('non-existent-file.html'); + d.addBoth( + function(self, ret) { + self.resume(function() { + Y.Assert.isInstanceOf(Error, ret); + Y.Assert.areEqual(404, ret.message); + }); + }, this); + + this.wait(); + }, + })); + + //initialize the console + var yconsole = new Y.Console({ + newestOnTop: false, + width:'600px' + }); + yconsole.render('#log'); + + //run all tests + Y.Test.Runner.run(); +}); -- cgit v1.2.3 From a741b9e561512e258fe4a589ac074c548eb37e3a Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Wed, 25 Aug 2010 21:06:07 +0100 Subject: Add a test for successful binary download --- jarmon/jarmon.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index b6ee035..4a5c273 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -15,6 +15,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { }, test_urlNotFound: function () { + /** + * When url cannot be found, the deferred should errback with status + * 404. + **/ var d = new jarmon.downloadBinary('non-existent-file.html'); d.addBoth( function(self, ret) { @@ -26,6 +30,24 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.wait(); }, + + test_urlFound: function () { + /** + * When url is found, the deferred should callback with an instance + * of javascriptrrd.BinaryFile + **/ + var d = new jarmon.downloadBinary('testfile.bin'); + d.addBoth( + function(self, ret) { + self.resume(function() { + Y.Assert.isInstanceOf(BinaryFile, ret); + Y.Assert.areEqual(String.fromCharCode(0), ret.getRawData()); + }); + }, this); + + this.wait(); + }, + })); //initialize the console -- cgit v1.2.3 From 64f965d74374f3a15342bf6e807ac50513a69f68 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Wed, 25 Aug 2010 22:20:41 +0100 Subject: Add a test for query timerange --- jarmon/jarmon.test.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 4a5c273..86243b4 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -8,12 +8,6 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { Y.Test.Runner.add(new Y.Test.Case({ name: "jarmon.downloadBinary", - setUp : function () { - }, - - tearDown : function () { - }, - test_urlNotFound: function () { /** * When url cannot be found, the deferred should errback with status @@ -46,10 +40,32 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { }, this); this.wait(); - }, + } })); + + Y.Test.Runner.add(new Y.Test.Case({ + name: "jarmon.RrdQuery", + + test_getDataTimeRangeOverlapError: function () { + /** + * The starttime must be less than the endtime + **/ + var rq = new jarmon.RrdQuery({}, ''); + var error = null; + try { + rq.getData(1, 0); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); + } + + })); + + + //initialize the console var yconsole = new Y.Console({ newestOnTop: false, -- cgit v1.2.3 From 333dfba10d99e5a2eec391c2481156329e2949dc Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sat, 28 Aug 2010 22:34:26 +0100 Subject: the start of a builder of simple, testable rrd files --- jarmon/jarmon.test.js | 53 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 86243b4..229b9a8 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -48,19 +48,54 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { Y.Test.Runner.add(new Y.Test.Case({ name: "jarmon.RrdQuery", + setUp: function() { + this.d = new jarmon.downloadBinary('simple.rrd') + .addCallback( + function(self, binary) { + try { + return new RRDFile(binary); + } catch(e) { + console.log(e); + } + }, this) + .addErrback( + function(ret) { + console.log(ret); + }); + }, + test_getDataTimeRangeOverlapError: function () { /** * The starttime must be less than the endtime **/ - var rq = new jarmon.RrdQuery({}, ''); - var error = null; - try { - rq.getData(1, 0); - } catch(e) { - error = e; - } - Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); - } + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rq = new jarmon.RrdQuery(self.rrd, ''); + var error = null; + try { + rq.getData(1, 0); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); + }); + }, this); + this.wait(); + }, + + test_getDataSimple: function () { + /** + * The starttime must be less than the endtime + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + Y.Assert.areEqual(1, rrd.getLastUpdate()); + }); + }, this); + this.wait(); + }, })); -- cgit v1.2.3 From 3c28be95136220398ff8b5b808742c8028876950 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 29 Aug 2010 19:24:25 +0100 Subject: A first rrdquery test --- jarmon/jarmon.test.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 229b9a8..7a2d6ec 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -49,7 +49,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { name: "jarmon.RrdQuery", setUp: function() { - this.d = new jarmon.downloadBinary('simple.rrd') + this.d = new jarmon.downloadBinary('build/test.rrd') .addCallback( function(self, binary) { try { @@ -86,12 +86,20 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { test_getDataSimple: function () { /** - * The starttime must be less than the endtime + * The generated rrd file should have values 0-9 at 1s intervals + * starting at 1980-01-01 00:00:00 **/ this.d.addCallback( function(self, rrd) { self.resume(function() { - Y.Assert.areEqual(1, rrd.getLastUpdate()); + var firstUpdate = new Date('1 jan 1980 00:00:00').getTime(); + var lastUpdate = firstUpdate + 10*1000; + Y.Assert.areEqual( + lastUpdate/1000, rrd.getLastUpdate()); + var q = new jarmon.RrdQuery(rrd, ''); + var data = q.getData(firstUpdate, lastUpdate); + Y.Assert.areEqual( + 0, data.data[0][1]); }); }, this); this.wait(); -- cgit v1.2.3 From ca0884b96c26fb08353e982263e096fa9777fb10 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 29 Aug 2010 21:39:07 +0100 Subject: Add tests for the parts of RRDFile that we use. --- jarmon/jarmon.test.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 7a2d6ec..3d96d5a 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -45,6 +45,110 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { })); + Y.Test.Runner.add(new Y.Test.Case({ + name: "javascriptrrd.RRDFile", + + setUp: function() { + this.d = new jarmon.downloadBinary('build/test.rrd') + .addCallback( + function(self, binary) { + try { + return new RRDFile(binary); + } catch(e) { + console.log(e); + } + }, this) + .addErrback( + function(ret) { + console.log(ret); + }); + }, + + test_getLastUpdate: function () { + /** + * The generated rrd file should have a lastupdate date of + * 1980-01-01 00:00:10 + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var lastUpdate = new Date('1 jan 1980 00:00:10').getTime(); + Y.Assert.areEqual( + lastUpdate/1000, rrd.getLastUpdate()); + }); + }, this); + this.wait(); + }, + + test_getDSIndex: function () { + /** + * The generated rrd file should have a single DS whose name is + * 'speed'. A RangeError is thrown if the requested index or dsName + * doesnt exist. + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + Y.Assert.areEqual('speed', rrd.getDS(0).getName()); + Y.Assert.areEqual(0, rrd.getDS('speed').getIdx()); + var error = null; + try { + rrd.getDS(1); + } catch(e) { + error = e; + } + Y.assert(error instanceof RangeError); + }); + }, this); + this.wait(); + }, + + test_getNrRRAs: function () { + /** + * The generated rrd file should have a single RRA + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + Y.Assert.areEqual(1, rrd.getNrRRAs()); + }); + }, this); + this.wait(); + }, + + test_getRRA: function () { + /** + * The generated rrd file should have a single RRA using AVERAGE + * consolidation, step=1, rows=10 and values 0-9 + * rra.getEl throws a RangeError if asked for row which doesn't + * exist. + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rra = rrd.getRRA(0); + Y.Assert.areEqual('AVERAGE', rra.getCFName()); + Y.Assert.areEqual(1, rra.getStep()); + Y.Assert.areEqual(10, rra.getNrRows()); + for(var i=0; i<10; i++) { + Y.Assert.areEqual(i, rra.getEl(i, 0)); + } + var error = null + try { + rra.getEl(10, 0); + } catch(e) { + error = e; + } + Y.assert(error instanceof RangeError); + }); + }, this); + this.wait(); + }, + + + + })); + Y.Test.Runner.add(new Y.Test.Case({ name: "jarmon.RrdQuery", @@ -92,14 +196,22 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.addCallback( function(self, rrd) { self.resume(function() { + var rra = rrd.getRRA(0) + console.log(rra.getEl(0, 0)); + + var firstUpdate = new Date('1 jan 1980 00:00:00').getTime(); var lastUpdate = firstUpdate + 10*1000; Y.Assert.areEqual( lastUpdate/1000, rrd.getLastUpdate()); + + + /* var q = new jarmon.RrdQuery(rrd, ''); var data = q.getData(firstUpdate, lastUpdate); Y.Assert.areEqual( - 0, data.data[0][1]); + firstUpdate+1000, data.data[0][0]); + */ }); }, this); this.wait(); @@ -112,7 +224,8 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { //initialize the console var yconsole = new Y.Console({ newestOnTop: false, - width:'600px' + width:'600px', + height: '400px' }); yconsole.render('#log'); -- cgit v1.2.3 From 877f4724204f0d68f44116ef21b8425813c8285d Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 29 Aug 2010 23:16:18 +0100 Subject: a filing test for RrdQuery getData --- jarmon/jarmon.test.js | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 3d96d5a..6360685 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -52,11 +52,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d = new jarmon.downloadBinary('build/test.rrd') .addCallback( function(self, binary) { - try { - return new RRDFile(binary); - } catch(e) { - console.log(e); - } + return new RRDFile(binary); }, this) .addErrback( function(ret) { @@ -143,10 +139,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { }); }, this); this.wait(); - }, - - - + } })); Y.Test.Runner.add(new Y.Test.Case({ @@ -156,11 +149,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d = new jarmon.downloadBinary('build/test.rrd') .addCallback( function(self, binary) { - try { - return new RRDFile(binary); - } catch(e) { - console.log(e); - } + return new RRDFile(binary); }, this) .addErrback( function(ret) { @@ -188,34 +177,31 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.wait(); }, - test_getDataSimple: function () { + test_getData: function () { /** * The generated rrd file should have values 0-9 at 1s intervals - * starting at 1980-01-01 00:00:00 + * starting at 1980-01-01 00:00:01 + * Result should include a data points with times > starttime and + * <= endTime **/ this.d.addCallback( function(self, rrd) { self.resume(function() { - var rra = rrd.getRRA(0) - console.log(rra.getEl(0, 0)); - - - var firstUpdate = new Date('1 jan 1980 00:00:00').getTime(); - var lastUpdate = firstUpdate + 10*1000; - Y.Assert.areEqual( - lastUpdate/1000, rrd.getLastUpdate()); + var startTime = new Date('1 jan 1980 00:00:00').getTime(); + var endTime = new Date('1 jan 1980 00:00:10').getTime(); - - /* var q = new jarmon.RrdQuery(rrd, ''); - var data = q.getData(firstUpdate, lastUpdate); + var data = q.getData(startTime, endTime); + Y.Assert.areEqual( + 10, data.data.length); Y.Assert.areEqual( - firstUpdate+1000, data.data[0][0]); - */ + startTime+1000, data.data[0][0]); + Y.Assert.areEqual( + endTime, data.data[9][0]); }); }, this); this.wait(); - }, + } })); -- cgit v1.2.3 From 4b7ed618664c5404c390f8e6ef8c106189eaf44c Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 30 Aug 2010 13:16:19 +0100 Subject: more realistic rrd step sizes and data --- jarmon/jarmon.test.js | 53 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 6360685..09fec1a 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -44,6 +44,12 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { })); + var RRD_STEP = 10; + var RRD_DSNAME = 'speed'; + var RRD_DSINDEX = 0; + var RRD_RRAROWS = 6; + var RRD_STARTTIME = new Date('1 jan 1980 00:00:00').getTime(); + var RRD_ENDTIME = new Date('1 jan 1980 00:01:01').getTime(); Y.Test.Runner.add(new Y.Test.Case({ name: "javascriptrrd.RRDFile", @@ -63,14 +69,13 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { test_getLastUpdate: function () { /** * The generated rrd file should have a lastupdate date of - * 1980-01-01 00:00:10 + * 1980-01-01 00:50:01 **/ this.d.addCallback( function(self, rrd) { self.resume(function() { - var lastUpdate = new Date('1 jan 1980 00:00:10').getTime(); Y.Assert.areEqual( - lastUpdate/1000, rrd.getLastUpdate()); + RRD_ENDTIME/1000, rrd.getLastUpdate()); }); }, this); this.wait(); @@ -85,11 +90,12 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.addCallback( function(self, rrd) { self.resume(function() { - Y.Assert.areEqual('speed', rrd.getDS(0).getName()); - Y.Assert.areEqual(0, rrd.getDS('speed').getIdx()); + Y.Assert.areEqual(RRD_DSNAME, rrd.getDS(0).getName()); + Y.Assert.areEqual( + RRD_DSINDEX, rrd.getDS('speed').getIdx()); var error = null; try { - rrd.getDS(1); + rrd.getDS(RRD_DSINDEX+1); } catch(e) { error = e; } @@ -115,7 +121,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { test_getRRA: function () { /** * The generated rrd file should have a single RRA using AVERAGE - * consolidation, step=1, rows=10 and values 0-9 + * consolidation, step=10, rows=6 and values 0-5 * rra.getEl throws a RangeError if asked for row which doesn't * exist. **/ @@ -124,10 +130,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { self.resume(function() { var rra = rrd.getRRA(0); Y.Assert.areEqual('AVERAGE', rra.getCFName()); - Y.Assert.areEqual(1, rra.getStep()); - Y.Assert.areEqual(10, rra.getNrRows()); - for(var i=0; i<10; i++) { - Y.Assert.areEqual(i, rra.getEl(i, 0)); + Y.Assert.areEqual(RRD_STEP, rra.getStep()); + Y.Assert.areEqual(RRD_RRAROWS, rra.getNrRows()); + for(var i=0; i starttime and * <= endTime **/ this.d.addCallback( function(self, rrd) { self.resume(function() { - var startTime = new Date('1 jan 1980 00:00:00').getTime(); - var endTime = new Date('1 jan 1980 00:00:10').getTime(); - - var q = new jarmon.RrdQuery(rrd, ''); - var data = q.getData(startTime, endTime); - Y.Assert.areEqual( - 10, data.data.length); - Y.Assert.areEqual( - startTime+1000, data.data[0][0]); - Y.Assert.areEqual( - endTime, data.data[9][0]); + var rq = new jarmon.RrdQuery(rrd, ''); + var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME); + console.log(data.data); + Y.Assert.areEqual(RRD_RRAROWS, data.data.length); + Y.Assert.areEqual(2, data.data[2][1]); + Y.Assert.areEqual(RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]); + //Y.Assert.areEqual( + // RRD_ENDTIME, data.data[RRD_RRAROWS-1][0]); }); }, this); this.wait(); - } + }, })); -- cgit v1.2.3 From 337882182bd0ab3e7a147159245a8d1331fbfbf0 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 30 Aug 2010 15:22:25 +0100 Subject: Add another RRA to demonstrate that jarmon is currently selecting the wrong RRA --- jarmon/jarmon.test.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 09fec1a..0aca865 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -47,9 +47,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { var RRD_STEP = 10; var RRD_DSNAME = 'speed'; var RRD_DSINDEX = 0; - var RRD_RRAROWS = 6; + var RRD_RRACOUNT = 2; + var RRD_RRAROWS = 12; var RRD_STARTTIME = new Date('1 jan 1980 00:00:00').getTime(); - var RRD_ENDTIME = new Date('1 jan 1980 00:01:01').getTime(); + var RRD_ENDTIME = new Date('1 jan 1980 00:02:01').getTime(); Y.Test.Runner.add(new Y.Test.Case({ name: "javascriptrrd.RRDFile", @@ -112,7 +113,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.addCallback( function(self, rrd) { self.resume(function() { - Y.Assert.areEqual(1, rrd.getNrRRAs()); + Y.Assert.areEqual(RRD_RRACOUNT, rrd.getNrRRAs()); }); }, this); this.wait(); @@ -137,7 +138,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { } var error = null try { - rra.getEl(10, 0); + rra.getEl(RRD_RRAROWS+1, 0); } catch(e) { error = e; } @@ -195,10 +196,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME); - console.log(data.data); Y.Assert.areEqual(RRD_RRAROWS, data.data.length); Y.Assert.areEqual(2, data.data[2][1]); - Y.Assert.areEqual(RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]); + Y.Assert.areEqual( + RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]); //Y.Assert.areEqual( // RRD_ENDTIME, data.data[RRD_RRAROWS-1][0]); }); -- cgit v1.2.3 From 047d284b792ce7ac2b8e47e8067b142c5f081ee7 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 30 Aug 2010 22:02:51 +0100 Subject: hopefully more consistent behaviour - more like rrdtool fetch --- jarmon/jarmon.test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 0aca865..7bffb1b 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -50,7 +50,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { var RRD_RRACOUNT = 2; var RRD_RRAROWS = 12; var RRD_STARTTIME = new Date('1 jan 1980 00:00:00').getTime(); - var RRD_ENDTIME = new Date('1 jan 1980 00:02:01').getTime(); + var RRD_ENDTIME = new Date('1 jan 1980 00:02:00').getTime(); Y.Test.Runner.add(new Y.Test.Case({ name: "javascriptrrd.RRDFile", @@ -76,7 +76,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { function(self, rrd) { self.resume(function() { Y.Assert.areEqual( - RRD_ENDTIME/1000, rrd.getLastUpdate()); + RRD_ENDTIME/1000+1, rrd.getLastUpdate()); }); }, this); this.wait(); @@ -196,12 +196,13 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME); - Y.Assert.areEqual(RRD_RRAROWS, data.data.length); + Y.Assert.areEqual(RRD_RRAROWS+1, data.data.length); Y.Assert.areEqual(2, data.data[2][1]); Y.Assert.areEqual( RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]); - //Y.Assert.areEqual( - // RRD_ENDTIME, data.data[RRD_RRAROWS-1][0]); + Y.Assert.areEqual( + RRD_ENDTIME + RRD_STEP*1000, + data.data[data.data.length-1][0]); }); }, this); this.wait(); -- cgit v1.2.3 From ddfdbf0e40aa2a9ac7f48520829dc6b30ff3c02b Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Thu, 2 Sep 2010 23:52:25 +0100 Subject: Add test for unknown consolidation function error --- jarmon/jarmon.test.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 7bffb1b..9e8eaca 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -171,19 +171,42 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.addCallback( function(self, rrd) { self.resume(function() { - var rq = new jarmon.RrdQuery(self.rrd, ''); + var rq = new jarmon.RrdQuery(rrd, ''); var error = null; try { rq.getData(1, 0); } catch(e) { error = e; } - Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); + Y.Assert.isInstanceOf(RangeError, error); }); }, this); this.wait(); }, + + test_getDataUnknownCfError: function () { + /** + * Error is raised if the rrd file doesn't contain an RRA with the + * requested consolidation function (CF) + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rq = new jarmon.RrdQuery(rrd, ''); + var error = null; + try { + rq.getData(RRD_STARTTIME, RRD_ENDTIME, 0, 'FOO'); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(TypeError, error); + }); + }, this); + this.wait(); + }, + + test_getData: function () { /** * The generated rrd file should have values 0-9 at 300s intervals -- cgit v1.2.3 From e9b1a0b4728d9e74ae3c6dccbf037e07f36f5fd4 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 3 Oct 2010 20:57:16 +0100 Subject: More complete tests for getData and associated simplification of the getData code. --- jarmon/jarmon.test.js | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 9e8eaca..0ff1840 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -218,19 +218,61 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { function(self, rrd) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); - var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME); - Y.Assert.areEqual(RRD_RRAROWS+1, data.data.length); - Y.Assert.areEqual(2, data.data[2][1]); + + // We request data starting 1 STEP +1s after the RRD file + // first val and ending 1 STEP -1s before the RRD last val + // ie one step within the RRD file, but 1s away from the + // step boundary to test the quantisation of the + // requested time range. + var data = rq.getData( + RRD_STARTTIME + (RRD_STEP+1) * 1000, + RRD_ENDTIME - (RRD_STEP-1) * 1000); + + // so we expect two less rows than the total rows in the + // file. + Y.Assert.areEqual(RRD_RRAROWS-2, data.data.length); + + // The value of the first returned row should be the + // second value in the RRD file (starts at value 0) + Y.Assert.areEqual(1, data.data[0][1]); + + // The value of the last returned row should be the + // 10 value in the RRD file (starts at value 0) + Y.Assert.areEqual(10, data.data[data.data.length-1][1]); + + // The timestamp of the first returned row should be + // exactly one step after the start of the RRD file Y.Assert.areEqual( RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]); + + // RRD_ENDTIME is on a step boundary and is therfore + // actually the start time of a new row + // So when we ask for endTime = RRD_ENDTIME-STEP-1 we + // actually get data up to the 2nd to last RRD row. Y.Assert.areEqual( - RRD_ENDTIME + RRD_STEP*1000, + RRD_ENDTIME-RRD_STEP*1000*2, data.data[data.data.length-1][0]); }); }, this); this.wait(); }, + test_getDataUnknownValues: function () { + /** + * If the requested time range is outside the range of the RRD file + * we should not get any values back + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rq = new jarmon.RrdQuery(rrd, ''); + var data = rq.getData(RRD_ENDTIME, RRD_ENDTIME+1000); + Y.Assert.areEqual(0, data.data.length); + }); + }, this); + this.wait(); + } + })); @@ -242,7 +284,5 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { height: '400px' }); yconsole.render('#log'); - - //run all tests Y.Test.Runner.run(); }); -- cgit v1.2.3 From 9c71054a0e3f6e0bb5b524ada9b9c73ca90c2913 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 4 Oct 2010 00:27:06 +0100 Subject: A test case for the Chart class --- jarmon/jarmon.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 0ff1840..9ae7531 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -276,6 +276,41 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { })); + Y.Test.Runner.add(new Y.Test.Case({ + name: "jarmon.Chart", + + XsetUp: function() { + this.d = new jarmon.downloadBinary('build/test.rrd') + .addCallback( + function(self, binary) { + return new RRDFile(binary); + }, this) + .addErrback( + function(ret) { + console.log(ret); + }); + }, + + test_draw: function () { + /** + * + **/ + var $tpl = $('
').appendTo($('body')); + var c = new jarmon.Chart($tpl, {xaxis: {mode: "time"}}); + //jarmon.Chart.BASE_OPTIONS + //c.options.xaxis.tzoffset = 0; + c.addData('speed', new jarmon.RrdQueryRemote('build/test.rrd', 'm/s'), true); + var d = c.setTimeRange(RRD_STARTTIME, RRD_ENDTIME); + d.addCallback( + function(self) { + self.resume(function() { + Y.Assert.areEqual(1, 1); + }); + }, this); + this.wait(); + }, + })); + //initialize the console var yconsole = new Y.Console({ -- cgit v1.2.3 From 834649eb48062724a1f66c0c7473fb93f743bf74 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Tue, 5 Oct 2010 00:06:12 +0100 Subject: use jarmon BASE OPTIONS for increased coverage --- jarmon/jarmon.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 9ae7531..bab708d 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -53,7 +53,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { var RRD_ENDTIME = new Date('1 jan 1980 00:02:00').getTime(); Y.Test.Runner.add(new Y.Test.Case({ - name: "javascriptrrd.RRDFile", + name: "jarmon.RRDFile", setUp: function() { this.d = new jarmon.downloadBinary('build/test.rrd') @@ -296,9 +296,9 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * **/ var $tpl = $('
').appendTo($('body')); - var c = new jarmon.Chart($tpl, {xaxis: {mode: "time"}}); - //jarmon.Chart.BASE_OPTIONS - //c.options.xaxis.tzoffset = 0; + var c = new jarmon.Chart($tpl, jarmon.Chart.BASE_OPTIONS); + // + c.options.xaxis.tzoffset = 0; c.addData('speed', new jarmon.RrdQueryRemote('build/test.rrd', 'm/s'), true); var d = c.setTimeRange(RRD_STARTTIME, RRD_ENDTIME); d.addCallback( -- cgit v1.2.3 From 7bcfbd72d1ded68fdd55a49a0b90e226eb8ceed1 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 28 Nov 2010 14:50:38 +0000 Subject: The beginnings of a test for jarmon.Chart --- jarmon/jarmon.test.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index bab708d..c838023 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -279,21 +279,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { Y.Test.Runner.add(new Y.Test.Case({ name: "jarmon.Chart", - XsetUp: function() { - this.d = new jarmon.downloadBinary('build/test.rrd') - .addCallback( - function(self, binary) { - return new RRDFile(binary); - }, this) - .addErrback( - function(ret) { - console.log(ret); - }); - }, - test_draw: function () { /** - * + * Test that a rendered chart has the correct dimensions, legend, + * axis, labels etc **/ var $tpl = $('
').appendTo($('body')); var c = new jarmon.Chart($tpl, jarmon.Chart.BASE_OPTIONS); @@ -304,7 +293,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { d.addCallback( function(self) { self.resume(function() { - Y.Assert.areEqual(1, 1); + // TODO: write useful tests }); }, this); this.wait(); -- cgit v1.2.3