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.js | 23 +++++++++++++++++++++++ jarmon/jarmon.test.js | 30 +++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 44c4dad..6296fc5 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -27,6 +27,7 @@ if(typeof jarmon == 'undefined') { var jarmon = {}; } + jarmon.downloadBinary = function(url) { /** * Download a binary file asynchronously using the jQuery.ajax function @@ -126,6 +127,20 @@ jarmon.localTimeFormatter = function (v, axis) { }; +jarmon.TimeRangeError = function(message) { + /** + * Raised when an invalid timerange is encountered. + * + * @class jarmon.TimeRangeError + * @constructor + * @param message {String} A description of the error reason + **/ + this.name = "TimeRangeError"; + this.message = (message || ""); +} +jarmon.TimeRangeError.prototype = Error.prototype; + + /** * A wrapper around an instance of javascriptrrd.RRDFile which provides a * convenient way to query the RRDFile based on time range, RRD data source (DS) @@ -156,6 +171,14 @@ jarmon.RrdQuery.prototype.getData = function(startTime, endTime, dsId, cfName) { * @return {Object} A Flot compatible data series * eg label: '', data: [], unit: '' **/ + + if (startTime >= endTime) { + throw new jarmon.TimeRangeError( + ['starttime must be less than endtime. ', + 'starttime: ', starttime, + 'endtime: ', endtime].join('')); + } + var startTimestamp = startTime/1000; var lastUpdated = this.rrd.getLastUpdate(); 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.1-4-g5e80