elasticsearch-indexPattern-specs.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define([
  2. 'moment',
  3. 'app/plugins/datasource/elasticsearch/indexPattern'
  4. ], function(moment, IndexPattern) {
  5. 'use strict';
  6. describe('IndexPattern', function() {
  7. describe('when getting index for today', function() {
  8. it('should return correct index name', function() {
  9. var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  10. var expected = 'asd-' + moment().format('YYYY.MM.DD');
  11. expect(pattern.getIndexForToday()).to.be(expected);
  12. });
  13. });
  14. describe('when getting index list for time range', function() {
  15. describe('no interval', function() {
  16. it('should return correct index', function() {
  17. var pattern = new IndexPattern('my-metrics');
  18. var from = new Date(2015, 4, 30, 1, 2, 3);
  19. var to = new Date(2015, 5, 1, 12, 5 , 6);
  20. expect(pattern.getIndexList(from, to)).to.eql('my-metrics');
  21. });
  22. });
  23. describe('daily', function() {
  24. it('should return correct index list', function() {
  25. var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  26. var from = new Date(1432940523000);
  27. var to = new Date(1433153106000);
  28. var expected = [
  29. 'asd-2015.05.29',
  30. 'asd-2015.05.30',
  31. 'asd-2015.05.31',
  32. 'asd-2015.06.01',
  33. ];
  34. expect(pattern.getIndexList(from, to)).to.eql(expected);
  35. });
  36. });
  37. });
  38. });
  39. });