文件操作 - datasource.test.ts
返回文件管理
返回主菜单
删除本文件
文件: /usr/share/grafana/public/app/plugins/datasource/grafana/specs/datasource.test.ts
编辑文件内容
import { DataSourceInstanceSettings, dateTime } from '@grafana/data'; import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__ import { GrafanaDatasource } from '../datasource'; jest.mock('@grafana/runtime', () => ({ ...((jest.requireActual('@grafana/runtime') as unknown) as object), getBackendSrv: () => backendSrv, })); jest.mock('app/features/templating/template_srv', () => ({ replace: (val: string) => { return val.replace('$var2', 'replaced__delimiter__replaced2').replace('$var', 'replaced'); }, })); describe('grafana data source', () => { const getMock = jest.spyOn(backendSrv, 'get'); beforeEach(() => { jest.clearAllMocks(); }); describe('when executing an annotations query', () => { let calledBackendSrvParams: any; let ds: GrafanaDatasource; beforeEach(() => { getMock.mockImplementation((url: string, options: any) => { calledBackendSrvParams = options; return Promise.resolve([]); }); ds = new GrafanaDatasource({} as DataSourceInstanceSettings); }); describe('with tags that have template variables', () => { const options = setupAnnotationQueryOptions({ tags: ['tag1:$var'] }); beforeEach(() => { return ds.annotationQuery(options); }); it('should interpolate template variables in tags in query options', () => { expect(calledBackendSrvParams.tags[0]).toBe('tag1:replaced'); }); }); describe('with tags that have multi value template variables', () => { const options = setupAnnotationQueryOptions({ tags: ['$var2'] }); beforeEach(() => { return ds.annotationQuery(options); }); it('should interpolate template variables in tags in query options', () => { expect(calledBackendSrvParams.tags[0]).toBe('replaced'); expect(calledBackendSrvParams.tags[1]).toBe('replaced2'); }); }); describe('with type dashboard', () => { const options = setupAnnotationQueryOptions( { type: 'dashboard', tags: ['tag1'], }, { id: 1 } ); beforeEach(() => { return ds.annotationQuery(options); }); it('should remove tags from query options', () => { expect(calledBackendSrvParams.tags).toBe(undefined); }); }); }); }); function setupAnnotationQueryOptions(annotation: { tags: string[]; type?: string }, dashboard?: { id: number }) { return { annotation, dashboard, range: { from: dateTime(1432288354), to: dateTime(1432288401), }, rangeRaw: { from: 'now-24h', to: 'now' }, }; }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件