mirror of https://github.com/grafana/grafana
parent
b24c539206
commit
14cb2b0143
@ -0,0 +1,28 @@ |
||||
define([ |
||||
'lodash', |
||||
'moment', |
||||
], |
||||
function (_, moment) { |
||||
'use strict'; |
||||
|
||||
function IndexPattern(pattern, interval) { |
||||
this.pattern = pattern; |
||||
this.interval = interval; |
||||
}; |
||||
|
||||
IndexPattern.prototype.getIndexForToday = function() { |
||||
if (this.interval) { |
||||
return moment().format(this.pattern); |
||||
} else { |
||||
return this.pattern; |
||||
} |
||||
}; |
||||
|
||||
|
||||
IndexPattern.prototype.getIndexList = function(from, to) { |
||||
|
||||
}; |
||||
|
||||
|
||||
return IndexPattern; |
||||
}) |
@ -0,0 +1,35 @@ |
||||
define([ |
||||
'moment', |
||||
'plugins/datasource/elasticsearch/indexPattern' |
||||
], function(moment, IndexPattern) { |
||||
'use strict'; |
||||
|
||||
describe('IndexPattern', function() { |
||||
|
||||
describe('when getting index for today', function() { |
||||
it('should return correct index name', function() { |
||||
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'daily'); |
||||
var expected = 'asd-' + moment().format('YYYY.MM.DD'); |
||||
|
||||
expect(pattern.getIndexForToday()).to.be(expected); |
||||
}); |
||||
}); |
||||
|
||||
describe('when getting index list for time range', function() { |
||||
|
||||
describe('daily', function() { |
||||
|
||||
it('should return correct index list', function() { |
||||
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'daily'); |
||||
var from = new Date(2015, 4, 29); |
||||
var to = new Date(2015, 5, 1); |
||||
|
||||
expect(pattern.getIndexList(from, to)).to.be(['asd', 'asd2']); |
||||
}); |
||||
}) |
||||
|
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
Loading…
Reference in new issue