1
import { sampleApiResponse } from './__testdata__/testdata';
2
import { groupTargets, Target, ScrapePools, getColor } from './target';
4
describe('groupTargets', () => {
5
const targets: Target[] = sampleApiResponse.data.activeTargets as Target[];
6
const targetGroups: ScrapePools = groupTargets(targets);
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);
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);
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]);
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' },
37
testCases.forEach(({ color, status }) => {
38
it(`returns ${color} for ${status} status`, () => {
39
expect(getColor(status)).toEqual(color);