more work on influxdb 0.9 query editor and query builder, can now handle regex conditions, tag operator and tag value quotes changes automatically depending if the tag value is a regex or not, #1525

This commit is contained in:
Torkel Ödegaard
2015-06-26 10:38:39 +02:00
parent dd8d6bc705
commit 3f167d7fd1
4 changed files with 56 additions and 12 deletions

View File

@@ -27,10 +27,15 @@ define([
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE hostname=\'server1\' AND $timeFilter'
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE hostname = \'server1\' AND $timeFilter'
+ ' GROUP BY time($interval) ORDER BY asc');
});
it('should switch regex operator with tag value is regex', function() {
var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: [{key: 'app', value: '/e.*/'}]});
var query = builder.build();
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE app =~ /e.*/ AND $timeFilter GROUP BY time($interval) ORDER BY asc');
});
});
describe('series with multiple tags only', function() {
@@ -42,7 +47,7 @@ define([
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE hostname=\'server1\' AND app=\'email\' AND ' +
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE hostname = \'server1\' AND app = \'email\' AND ' +
'$timeFilter GROUP BY time($interval) ORDER BY asc');
});
});
@@ -78,7 +83,7 @@ define([
it('should have where condition in tag keys query with tags', function() {
var builder = new InfluxQueryBuilder({ measurement: '', tags: [{key: 'host', value: 'se1'}] });
var query = builder.buildExploreQuery('TAG_KEYS');
expect(query).to.be("SHOW TAG KEYS WHERE host='se1'");
expect(query).to.be("SHOW TAG KEYS WHERE host = 'se1'");
});
it('should have no conditions in measurement query for query with no tags', function() {
@@ -90,7 +95,7 @@ define([
it('should have where condition in measurement query for query with tags', function() {
var builder = new InfluxQueryBuilder({measurement: '', tags: [{key: 'app', value: 'email'}]});
var query = builder.buildExploreQuery('MEASUREMENTS');
expect(query).to.be("SHOW MEASUREMENTS WHERE app='email'");
expect(query).to.be("SHOW MEASUREMENTS WHERE app = 'email'");
});
it('should have where tag name IN filter in tag values query for query with one tag', function() {
@@ -102,7 +107,13 @@ define([
it('should have measurement tag condition and tag name IN filter in tag values query', function() {
var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: [{key: 'app', value: 'email'}, {key: 'host', value: 'server1'}]});
var query = builder.buildExploreQuery('TAG_VALUES', 'app');
expect(query).to.be('SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE host=\'server1\'');
expect(query).to.be('SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE host = \'server1\'');
});
it('should switch to regex operator in tag condition', function() {
var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: [{key: 'host', value: '/server.*/'}]});
var query = builder.buildExploreQuery('TAG_VALUES', 'app');
expect(query).to.be('SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE host =~ /server.*/');
});
});

View File

@@ -65,6 +65,18 @@ define([
});
});
describe('when last tag value segment is updated to regex', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
ctx.scope.tagSegmentUpdated({value: '/server.*/', type: 'value'}, 2);
});
it('should update operator', function() {
expect(ctx.scope.tagSegments[1].value).to.be('=~');
});
});
describe('when second tag key is added', function() {
beforeEach(function() {
ctx.scope.init();