Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add chart tests #44

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ gulp.task('test-coverage', ['instrument'], function() {
.pipe(istanbul.enforceThresholds({
thresholds: {
global: {
statements: 95,
branches: 70,
statements: 96,
branches: 81,
functions: 100,
lines: 95
lines: 96
}
}
}));
Expand Down
13 changes: 4 additions & 9 deletions test/app/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ let path = require('path');
describe('app tests', function() {
let juttleEngineTester;

before((done) => {
before(() => {
juttleEngineTester = new JuttleEngineTester();
juttleEngineTester.start(done);
return juttleEngineTester.start();
});

after((done) => {
juttleEngineTester.stop({
dumpContainerLogs: process.env['DEBUG']
})
.then(() => {
done();
});
after(() => {
return juttleEngineTester.stop();
});

it('shows errors for a program that produces an error', () => {
Expand Down
112 changes: 112 additions & 0 deletions test/app/barchart.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use strict';

let JuttleEngineTester = require('./lib/juttle-engine-tester');
let path = require('path');
let expect = require('chai').expect;

describe('barchart', function() {
let juttleEngineTester;

before(() => {
juttleEngineTester = new JuttleEngineTester();
return juttleEngineTester.start();
});

after(() => {
return juttleEngineTester.stop();
});

it('can render a simple barchart', () => {
var title = 'Average CPU % per host for last 10 minutes';
return juttleEngineTester.run({
path: path.join(__dirname, 'juttle', 'simple_barchart.juttle')
})
.then(() => {
return juttleEngineTester.waitForViewTitle(title);
})
.then(() => {
return juttleEngineTester.getBarsOnViewWithTitle(title)
})
.then((bars) => {
expect(bars.length).to.be.equal(10);
})
.then(() => {
return juttleEngineTester.waitForYAxisTitleOnViewWithTitle(title, 'CPU %');
})
.then(() => {
return juttleEngineTester.waitForXAxisTitleOnViewWithTitle(title, 'hostname');
})
.then(() => {
return juttleEngineTester.waitForXAxisLabelOnViewWithTitle(title, [
'sea.3','nyc.5','sea.9','nyc.2','sea.6',
'sea.0','sjc.7','nyc.8','sjc.4','sjc.1'
])
});
});

it('can render a simple barchart with "horizontal" orientation', () => {
var title = 'Average CPU % per host for last 10 minutes';
return juttleEngineTester.run({
path: path.join(__dirname, 'juttle', 'horizontal_barchart.juttle')
})
.then(() => {
return juttleEngineTester.waitForViewTitle(title);
})
.then(() => {
return juttleEngineTester.getBarsOnViewWithTitle(title)
})
.then((bars) => {
expect(bars.length).to.be.equal(10);
})
.then(() => {
return juttleEngineTester.waitForXAxisTitleOnViewWithTitle(title, 'CPU %');
})
.then(() => {
return juttleEngineTester.waitForYAxisTitleOnViewWithTitle(title, 'hostname');
})
.then(() => {
return juttleEngineTester.waitForYAxisLabelOnViewWithTitle(title, [
'sjc.1', 'sjc.4', 'nyc.8', 'sjc.7', 'sea.0',
'sea.6', 'nyc.2', 'sea.9', 'nyc.5', 'sea.3'
])
});
});

it('can render a barchart with negative and positive values', () => {
var title = 'Target average response time comparison';
return juttleEngineTester.run({
path: path.join(__dirname, 'juttle', 'up_and_down_barchart.juttle')
})
.then(() => {
return juttleEngineTester.waitForViewTitle(title);
})
.then(() => {
return juttleEngineTester.waitForXAxisLabelOnViewWithTitle(title, [
'sea.0', 'sjc.1', 'nyc.2', 'sea.3'
]);
})
.then(() => {
return juttleEngineTester.getBarsOnViewWithTitle(title)
})
.then((bars) => {
expect(bars.length).to.be.equal(4);

var barColors = [];
return Promise.each(bars, function(bar) {
return juttleEngineTester.getComputedStyleValue(bar, 'fill')
.then((value) => {
barColors.push(value);
});
})
.then(() => {
expect(barColors).to.deep.equal([
'rgb(0, 128, 0)',
'rgb(0, 128, 0)',
'rgb(0, 128, 0)',
'rgb(128, 0, 0)'
]);
});
});
});

});
25 changes: 25 additions & 0 deletions test/app/juttle/events_on_timechart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
read stochastic -source 'cdn' -from :2014-01-01: -to :2014-02-01: -nhosts 3 -source_type 'metric' name='cpu'
| view timechart -o {
id: 'CPU',
title: '% CPU usage per host' ,
keyField: 'host',
yScales: {
primary: {
label: '% CPU busy',
tickFormat: '%'
}
},
xScale: {
label: 'hostname',
}
};

emit -from :2014-01-01: -to :2014-02-01: -every :15 days:
| put type = 'git', text = 'release ${time}', label = 'git tag'
| view events
-on 'CPU'
-typeField 'type'
-timeField 'time'
-messageField 'text'
-nameField 'label';

23 changes: 23 additions & 0 deletions test/app/juttle/horizontal_barchart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
read stochastic -source 'cdn' -nhosts 10 -from :10 minutes before 2014-01-01: -to :2014-01-01: -source_type 'metrics' name = 'cpu'
| filter name = 'cpu'
| reduce value = avg(value) by host
| sort value -desc
| view barchart -o {
categoryField: 'host',
valueField: 'value',
title: 'Average CPU % per host for last 10 minutes',
yScales: {
primary: {
label: 'CPU %',
tickFormat: '%'
}
},
xScale: {
label: 'hostname',
},
tooltip: {
valueFormat: '%'
},
orientation: 'horizontal'
}

17 changes: 17 additions & 0 deletions test/app/juttle/overlayed_timechart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
read stochastic -source 'cdn' -from :3 days before 2014-01-01: -to :2014-01-01: -nhosts 3 -source_type 'metric' name='cpu'
| view timechart
-o {
title: '% CPU usage per host' ,
keyField: 'host',
duration: :1 day:,
overlayTime: true,
yScales: {
primary: {
label: '% CPU busy',
tickFormat: '%'
}
},
xScale: {
label: 'hostname',
}
}
22 changes: 22 additions & 0 deletions test/app/juttle/simple_barchart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
read stochastic -source 'cdn' -nhosts 10 -from :10 minutes before 2014-01-01: -to :2014-01-01: -source_type 'metrics' name = 'cpu'
| filter name = 'cpu'
| reduce value = avg(value) by host
| sort value -desc
| view barchart -o {
categoryField: 'host',
valueField: 'value',
title: 'Average CPU % per host for last 10 minutes',
yScales: {
primary: {
label: 'CPU %',
tickFormat: '%'
}
},
xScale: {
label: 'hostname',
},
tooltip: {
valueFormat: '%'
}
}

15 changes: 15 additions & 0 deletions test/app/juttle/simple_timechart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
read stochastic -source 'cdn' -from :10 minutes before 2014-01-01: -to :2014-01-01: -nhosts 3 -source_type 'metric' name='cpu'
| view timechart
-o {
title: '% CPU usage per host' ,
keyField: 'host',
yScales: {
primary: {
label: '% CPU busy',
tickFormat: '%'
}
},
xScale: {
label: 'hostname',
}
}
19 changes: 19 additions & 0 deletions test/app/juttle/up_and_down_barchart.juttle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
read stochastic
-source 'cdn'
-nhosts 4
-from :10 minutes before 2014-01-01:
-to :2014-01-01:
-source_type 'metrics'
-daily 1.8
name = 'response_ms'
| filter name = 'response_ms'
| reduce value = avg(value) by host
| put value = 100 - value // target average response_ms is 100ms
| view barchart -o {
categoryField: 'host',
valueField: 'value',
title: 'Target average response time comparison',
color: '#008000',
negativeColor: '#800000'
}

Loading