diff options
author | Richard Wall <richard@largo> | 2010-10-03 20:57:16 +0100 |
---|---|---|
committer | Richard Wall <richard@largo> | 2010-10-03 20:57:16 +0100 |
commit | e9b1a0b4728d9e74ae3c6dccbf037e07f36f5fd4 (patch) | |
tree | 9750d6fc0a459fc51258e35693940c084b8c810c /jarmon/jarmon.test.js | |
parent | ddfdbf0e40aa2a9ac7f48520829dc6b30ff3c02b (diff) |
More complete tests for getData and associated simplification of the getData code.
Diffstat (limited to 'jarmon/jarmon.test.js')
-rw-r--r-- | jarmon/jarmon.test.js | 52 |
1 files changed, 46 insertions, 6 deletions
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(); }); |