Skip to content

Commit

Permalink
add unit
Browse files Browse the repository at this point in the history
  • Loading branch information
yincongcyincong committed Jun 24, 2024
1 parent 984c9a2 commit 215b4d6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('PrometheusDatasource', () => {
});
});

it('should add filters to expression', () => {
it('AdhocFilters should not add filters', () => {
getAdhocFiltersMock.mockReturnValue([
{
key: 'k1',
Expand All @@ -219,7 +219,8 @@ describe('PrometheusDatasource', () => {
}
]);
replaceMock.mockImplementation((str, params) => {
return str.replace('$topk', '5');
const topk = params['topk'] as ScopedVar;
return str.replace('$topk', topk.value);
});
const caseTarget: PromQuery = { expr: 'topk_max($topk, vmalert_iteration_duration_seconds_sum)', refId: 'A' };
const result = ds.createQuery(caseTarget, { interval: '15s', scopedVars: { 'topk': { text: 'topk', value: '5' } } as ScopedVars} as DataQueryRequest<PromQuery>, 0, 0);
Expand Down Expand Up @@ -506,7 +507,7 @@ describe('PrometheusDatasource', () => {
expect(result).toMatchObject({ expr: 'test{job="bar", k1="v1", k2!="v2"}' });
});

it('should add filters to expression', () => {
it('AdhocFilters should not add filters', () => {
getAdhocFiltersMock.mockReturnValue([
{
key: 'k1',
Expand All @@ -515,14 +516,14 @@ describe('PrometheusDatasource', () => {
}
]);
replaceMock.mockImplementation((str, params) => {
return str?.replace('$topk', '5');
const topk = params['topk'] as ScopedVar;
return str?.replace('$topk', topk.value);
});
const query: PromQuery = {
expr: 'topk_max($topk, vmalert_iteration_duration_seconds_sum)',
refId: 'A'
};
const result = ds.applyTemplateVariables(query, { 'topk': { text: 'topk', value: '5' } } as ScopedVars);
console.log(result);
expect(result).toMatchObject({ expr: 'topk_max(5, vmalert_iteration_duration_seconds_sum{k1="v1"})'});
});
});
Expand Down

0 comments on commit 215b4d6

Please sign in to comment.