prometheus

Форк
0
42 строки · 1.5 Кб
1
import { sampleApiResponse } from './__testdata__/testdata';
2
import { groupTargets, Target, ScrapePools, getColor } from './target';
3

4
describe('groupTargets', () => {
5
  const targets: Target[] = sampleApiResponse.data.activeTargets as Target[];
6
  const targetGroups: ScrapePools = groupTargets(targets);
7

8
  it('groups a list of targets by scrape job', () => {
9
    ['blackbox', 'prometheus/test', 'node_exporter'].forEach((scrapePool) => {
10
      expect(Object.keys(targetGroups)).toContain(scrapePool);
11
    });
12
    Object.keys(targetGroups).forEach((scrapePool: string): void => {
13
      const ts: Target[] = targetGroups[scrapePool].targets;
14
      ts.forEach((t: Target) => {
15
        expect(t.scrapePool).toEqual(scrapePool);
16
      });
17
    });
18
  });
19

20
  it('adds upCount during aggregation', () => {
21
    const testCases: { [key: string]: number } = { blackbox: 3, 'prometheus/test': 1, node_exporter: 1 };
22
    Object.keys(testCases).forEach((scrapePool: string): void => {
23
      expect(targetGroups[scrapePool].upCount).toEqual(testCases[scrapePool]);
24
    });
25
  });
26
});
27

28
describe('getColor', () => {
29
  const testCases: { color: string; status: string }[] = [
30
    { color: 'danger', status: 'down' },
31
    { color: 'danger', status: 'DOWN' },
32
    { color: 'warning', status: 'unknown' },
33
    { color: 'warning', status: 'foo' },
34
    { color: 'success', status: 'up' },
35
    { color: 'success', status: 'Up' },
36
  ];
37
  testCases.forEach(({ color, status }) => {
38
    it(`returns ${color} for ${status} status`, () => {
39
      expect(getColor(status)).toEqual(color);
40
    });
41
  });
42
});
43

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.