This commit is contained in:
Mitsuhiro Tanda 2018-08-28 01:58:53 +09:00
parent 2926725bab
commit 3031c2e6fc

View File

@ -581,7 +581,7 @@ describe('PrometheusDatasource', () => {
describe('When performing annotationQuery', () => { describe('When performing annotationQuery', () => {
let results; let results;
const options = { const options: any = {
annotation: { annotation: {
expr: 'ALERTS{alertstate="firing"}', expr: 'ALERTS{alertstate="firing"}',
tagKeys: 'job', tagKeys: 'job',
@ -594,7 +594,6 @@ describe('PrometheusDatasource', () => {
}, },
}; };
beforeEach(async () => {
const response = { const response = {
status: 'success', status: 'success',
data: { data: {
@ -616,13 +615,17 @@ describe('PrometheusDatasource', () => {
}, },
}; };
describe('not use useValueForTime', () => {
beforeEach(async () => {
options.annotation.useValueForTime = false;
backendSrv.datasourceRequest = jest.fn(() => Promise.resolve(response)); backendSrv.datasourceRequest = jest.fn(() => Promise.resolve(response));
ctx.ds = new PrometheusDatasource(instanceSettings, q, backendSrv as any, templateSrv, timeSrv); ctx.ds = new PrometheusDatasource(instanceSettings, q, <any>backendSrv, templateSrv, timeSrv);
await ctx.ds.annotationQuery(options).then(data => { await ctx.ds.annotationQuery(options).then(function (data) {
results = data; results = data;
}); });
}); });
it('should return annotation list', () => { it('should return annotation list', () => {
expect(results.length).toBe(1); expect(results.length).toBe(1);
expect(results[0].tags).toContain('testjob'); expect(results[0].tags).toContain('testjob');
@ -630,43 +633,21 @@ describe('PrometheusDatasource', () => {
expect(results[0].text).toBe('testinstance'); expect(results[0].text).toBe('testinstance');
expect(results[0].time).toBe(123 * 1000); expect(results[0].time).toBe(123 * 1000);
}); });
});
it('should return annotation list with seriesValueAsTiemstamp', () => { describe('use useValueForTime', () => {
const options = { beforeEach(async () => {
annotation: { options.annotation.useValueForTime = true;
expr: 'timestamp_seconds', backendSrv.datasourceRequest = jest.fn(() => Promise.resolve(response));
tagKeys: 'job', ctx.ds = new PrometheusDatasource(instanceSettings, q, <any>backendSrv, templateSrv, timeSrv);
titleFormat: '{{job}}',
textFormat: '{{instance}}', await ctx.ds.annotationQuery(options).then(function (data) {
useValueForTime: true, results = data;
}, });
range: { });
from: new Date('2014-04-10T05:20:10Z'),
to: new Date('2014-05-20T03:10:22Z'), it('should return annotation list', () => {
}, expect(results[0].time).toEqual(1);
};
ctx.backendSrvMock.datasourceRequest.mockReturnValue(
Promise.resolve({
status: 'success',
data: {
resultType: 'matrix',
result: [
{
metric: {
__name__: 'timestamp_milliseconds',
instance: 'testinstance',
job: 'testjob',
},
values: [[1443454528, '1500000000000']],
},
],
},
})
);
ctx.ds = new PrometheusDatasource(instanceSettings, q, ctx.backendSrvMock, ctx.templateSrvMock, ctx.timeSrvMock);
ctx.ds.annotationQuery(options).then(function (results) {
expect(results[0].time).toEqual(1500000000000);
ctx.backendSrvMock.datasourceRequest.mockReset();
}); });
}); });
}); });