summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2010-08-29 21:39:07 +0100
committerRichard Wall <richard@largo>2010-08-29 21:39:07 +0100
commitca0884b96c26fb08353e982263e096fa9777fb10 (patch)
treebc0f3e9f8fe68dcdf74ff6d30367d5813b726d4d
parent3c28be95136220398ff8b5b808742c8028876950 (diff)
Add tests for the parts of RRDFile that we use.
-rw-r--r--jarmon/jarmon.test.js117
1 files changed, 115 insertions, 2 deletions
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
@@ -46,6 +46,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",
setUp: function() {
@@ -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');