github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/targets/target.test.ts (about)

     1  /* eslint-disable camelcase */
     2  
     3  import { sampleApiResponse } from './__testdata__/testdata';
     4  import { groupTargets, Target, ScrapePools, getColor } from './target';
     5  
     6  describe('groupTargets', () => {
     7    const targets: Target[] = sampleApiResponse.data.activeTargets as unknown as Target[];
     8    const targetGroups: ScrapePools = groupTargets(targets);
     9  
    10    it('groups a list of targets by scrape job', () => {
    11      ['blackbox', 'prometheus/test', 'node_exporter'].forEach((scrapePool) => {
    12        expect(Object.keys(targetGroups)).toContain(scrapePool);
    13      });
    14      Object.keys(targetGroups).forEach((scrapePool: string): void => {
    15        const ts: Target[] = targetGroups[scrapePool].targets;
    16        ts.forEach((t: Target) => {
    17          expect(t.scrapePool).toEqual(scrapePool);
    18        });
    19      });
    20    });
    21  
    22    it('adds upCount during aggregation', () => {
    23      const testCases: { [key: string]: number } = { blackbox: 3, 'prometheus/test': 1, node_exporter: 1 };
    24      Object.keys(testCases).forEach((scrapePool: string): void => {
    25        expect(targetGroups[scrapePool].upCount).toEqual(testCases[scrapePool]);
    26      });
    27    });
    28  });
    29  
    30  describe('getColor', () => {
    31    const testCases: { color: string; status: string }[] = [
    32      { color: 'danger', status: 'down' },
    33      { color: 'danger', status: 'DOWN' },
    34      { color: 'warning', status: 'unknown' },
    35      { color: 'warning', status: 'foo' },
    36      { color: 'success', status: 'up' },
    37      { color: 'success', status: 'Up' },
    38    ];
    39    testCases.forEach(({ color, status }) => {
    40      it(`returns ${color} for ${status} status`, () => {
    41        expect(getColor(status)).toEqual(color);
    42      });
    43    });
    44  });