當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript datasource_srv.DatasourceSrv類代碼示例

本文整理匯總了TypeScript中app/features/plugins/datasource_srv.DatasourceSrv的典型用法代碼示例。如果您正苦於以下問題:TypeScript DatasourceSrv類的具體用法?TypeScript DatasourceSrv怎麽用?TypeScript DatasourceSrv使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DatasourceSrv類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('datasource_srv', function() {
  let _datasourceSrv = new DatasourceSrv({}, {}, {}, {});
  let metricSources;

  describe('when loading metric sources', () => {
    let unsortedDatasources = {
      mmm: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      '--Grafana--': {
        type: 'grafana',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
      },
      '--Mixed--': {
        type: 'test-db',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
      },
      ZZZ: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      aaa: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      BBB: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
    };
    beforeEach(() => {
      config.datasources = unsortedDatasources;
      metricSources = _datasourceSrv.getMetricSources({ skipVariables: true });
    });

    it('should return a list of sources sorted case insensitively with builtin sources last', () => {
      expect(metricSources[0].name).toBe('aaa');
      expect(metricSources[1].name).toBe('BBB');
      expect(metricSources[2].name).toBe('mmm');
      expect(metricSources[3].name).toBe('ZZZ');
      expect(metricSources[4].name).toBe('--Grafana--');
      expect(metricSources[5].name).toBe('--Mixed--');
    });

    beforeEach(() => {
      config.defaultDatasource = 'BBB';
    });

    it('should set default data source', () => {
      expect(metricSources[2].name).toBe('default');
      expect(metricSources[2].sort).toBe('BBB');
    });
  });
});
開發者ID:knoguchi,項目名稱:grafana,代碼行數:55,代碼來源:datasource_srv.jest.ts

示例2: describe

describe('datasource_srv', function() {
  let _datasourceSrv = new DatasourceSrv({}, {}, {}, templateSrv);

  describe('when loading explore sources', () => {
    beforeEach(() => {
      config.datasources = {
        explore1: {
          name: 'explore1',
          meta: { explore: true, metrics: true },
        },
        explore2: {
          name: 'explore2',
          meta: { explore: true, metrics: false },
        },
        nonExplore: {
          name: 'nonExplore',
          meta: { explore: false, metrics: true },
        },
      };
    });

    it('should return list of explore sources', () => {
      const exploreSources = _datasourceSrv.getExploreSources();
      expect(exploreSources.length).toBe(2);
      expect(exploreSources[0].name).toBe('explore1');
      expect(exploreSources[1].name).toBe('explore2');
    });
  });

  describe('when loading metric sources', () => {
    let metricSources;
    let unsortedDatasources = {
      mmm: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      '--Grafana--': {
        type: 'grafana',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
      },
      '--Mixed--': {
        type: 'test-db',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
      },
      ZZZ: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      aaa: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      BBB: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
    };
    beforeEach(() => {
      config.datasources = unsortedDatasources;
      metricSources = _datasourceSrv.getMetricSources({});
      config.defaultDatasource = 'BBB';
    });

    it('should return a list of sources sorted case insensitively with builtin sources last', () => {
      expect(metricSources[1].name).toBe('aaa');
      expect(metricSources[2].name).toBe('BBB');
      expect(metricSources[3].name).toBe('mmm');
      expect(metricSources[4].name).toBe('ZZZ');
      expect(metricSources[5].name).toBe('--Grafana--');
      expect(metricSources[6].name).toBe('--Mixed--');
    });

    it('should set default data source', () => {
      expect(metricSources[3].name).toBe('default');
      expect(metricSources[3].sort).toBe('BBB');
    });

    it('should set default inject the variable datasources', () => {
      expect(metricSources[0].name).toBe('$datasource');
      expect(metricSources[0].sort).toBe('$datasource');
    });
  });
});
開發者ID:cboggs,項目名稱:grafana,代碼行數:83,代碼來源:datasource_srv.jest.ts

示例3: describe

describe('datasource_srv', () => {
  const _datasourceSrv = new DatasourceSrv({}, {}, {}, templateSrv);

  describe('when loading external datasources', () => {
    beforeEach(() => {
      config.datasources = {
        buildInDs: {
          id: 1,
          type: 'b',
          name: 'buildIn',
          meta: { builtIn: true } as DataSourcePluginMeta,
          jsonData: {},
        },
        nonBuildIn: {
          id: 2,
          type: 'e',
          name: 'external1',
          meta: { builtIn: false } as DataSourcePluginMeta,
          jsonData: {},
        },
        nonExplore: {
          id: 3,
          type: 'e2',
          name: 'external2',
          meta: {} as PluginMeta,
          jsonData: {},
        },
      };
    });

    it('should return list of explore sources', () => {
      const externalSources = _datasourceSrv.getExternal();
      expect(externalSources.length).toBe(2);
      expect(externalSources[0].name).toBe('external1');
      expect(externalSources[1].name).toBe('external2');
    });
  });

  describe('when loading metric sources', () => {
    let metricSources;
    const unsortedDatasources = {
      mmm: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      '--Grafana--': {
        type: 'grafana',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
      },
      '--Mixed--': {
        type: 'test-db',
        meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
      },
      ZZZ: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      aaa: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
      BBB: {
        type: 'test-db',
        meta: { metrics: { m: 1 } },
      },
    };
    beforeEach(() => {
      config.datasources = unsortedDatasources as any;
      metricSources = _datasourceSrv.getMetricSources({});
      config.defaultDatasource = 'BBB';
    });

    it('should return a list of sources sorted case insensitively with builtin sources last', () => {
      expect(metricSources[1].name).toBe('aaa');
      expect(metricSources[2].name).toBe('BBB');
      expect(metricSources[3].name).toBe('mmm');
      expect(metricSources[4].name).toBe('ZZZ');
      expect(metricSources[5].name).toBe('--Grafana--');
      expect(metricSources[6].name).toBe('--Mixed--');
    });

    it('should set default data source', () => {
      expect(metricSources[3].name).toBe('default');
      expect(metricSources[3].sort).toBe('BBB');
    });

    it('should set default inject the variable datasources', () => {
      expect(metricSources[0].name).toBe('$datasource');
      expect(metricSources[0].sort).toBe('$datasource');
    });
  });
});
開發者ID:grafana,項目名稱:grafana,代碼行數:92,代碼來源:datasource_srv.test.ts

示例4: beforeEach

 beforeEach(() => {
   config.datasources = unsortedDatasources;
   metricSources = _datasourceSrv.getMetricSources({});
   config.defaultDatasource = 'BBB';
 });
開發者ID:cboggs,項目名稱:grafana,代碼行數:5,代碼來源:datasource_srv.jest.ts

示例5: it

 it('should return list of explore sources', () => {
   const exploreSources = _datasourceSrv.getExploreSources();
   expect(exploreSources.length).toBe(2);
   expect(exploreSources[0].name).toBe('explore1');
   expect(exploreSources[1].name).toBe('explore2');
 });
開發者ID:cboggs,項目名稱:grafana,代碼行數:6,代碼來源:datasource_srv.jest.ts

示例6: beforeEach

 beforeEach(() => {
   config.datasources = unsortedDatasources;
   metricSources = _datasourceSrv.getMetricSources({ skipVariables: true });
 });
開發者ID:knoguchi,項目名稱:grafana,代碼行數:4,代碼來源:datasource_srv.jest.ts


注:本文中的app/features/plugins/datasource_srv.DatasourceSrv類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。