prometheus

Форк
0
/
EndpointLink.test.tsx 
61 строка · 3.4 Кб
1
import React from 'react';
2
import { shallow, mount } from 'enzyme';
3
import { Badge } from 'reactstrap';
4
import EndpointLink from './EndpointLink';
5

6
describe('EndpointLink', () => {
7
  it('renders a simple anchor if the endpoint has no query params', () => {
8
    const endpoint = 'http://100.104.208.71:15090/stats/prometheus';
9
    const globalURL = 'http://100.104.208.71:15090/stats/prometheus';
10
    const endpointLink = shallow(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
11
    const anchor = endpointLink.find('a');
12
    expect(anchor.prop('href')).toEqual(globalURL);
13
    expect(anchor.children().text()).toEqual(endpoint);
14
    expect(endpointLink.find('br')).toHaveLength(0);
15
  });
16

17
  it('renders an anchor targeting endpoint but with query param labels if the endpoint has query params', () => {
18
    const endpoint = 'http://100.99.128.71:9115/probe?module=http_2xx&target=http://some-service';
19
    const globalURL = 'http://100.99.128.71:9115/probe?module=http_2xx&target=http://some-service';
20
    const endpointLink = shallow(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
21
    const anchor = endpointLink.find('a');
22
    const badges = endpointLink.find(Badge);
23
    expect(anchor.prop('href')).toEqual(globalURL);
24
    expect(anchor.children().text()).toEqual('http://100.99.128.71:9115/probe');
25
    expect(endpointLink.find('br')).toHaveLength(1);
26
    expect(badges).toHaveLength(2);
27
    const moduleLabel = badges.filterWhere((badge) => badge.children().text() === 'module="http_2xx"');
28
    expect(moduleLabel.length).toEqual(1);
29
    const targetLabel = badges.filterWhere((badge) => badge.children().text() === 'target="http://some-service"');
30
    expect(targetLabel.length).toEqual(1);
31
  });
32
  // In cases of IPv6 addresses with a Zone ID, URL may not be parseable.
33
  // See https://github.com/prometheus/prometheus/issues/9760
34
  it('renders an anchor for IPv6 link with zone ID including labels for query params', () => {
35
    const endpoint =
36
      'http://[fe80::f1ee:adeb:371d:983%eth1]:9100/stats/prometheus?module=http_2xx&target=http://some-service';
37
    const globalURL =
38
      'http://[fe80::f1ee:adeb:371d:983%eth1]:9100/stats/prometheus?module=http_2xx&target=http://some-service';
39
    const endpointLink = shallow(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
40
    const anchor = endpointLink.find('a');
41
    const badges = endpointLink.find(Badge);
42
    expect(anchor.prop('href')).toEqual(globalURL);
43
    expect(anchor.children().text()).toEqual('http://[fe80::f1ee:adeb:371d:983%eth1]:9100/stats/prometheus');
44
    expect(endpointLink.find('br')).toHaveLength(1);
45
    expect(badges).toHaveLength(2);
46
    const moduleLabel = badges.filterWhere((badge) => badge.children().text() === 'module="http_2xx"');
47
    expect(moduleLabel.length).toEqual(1);
48
    const targetLabel = badges.filterWhere((badge) => badge.children().text() === 'target="http://some-service"');
49
    expect(targetLabel.length).toEqual(1);
50
  });
51

52
  it('handles params with multiple values correctly', () => {
53
    const consoleSpy = jest.spyOn(console, 'warn');
54
    const endpoint = `http://example.com/federate?match[]={__name__="name1"}&match[]={__name__="name2"}&match[]={__name__="name3"}`;
55
    const globalURL = 'http://example.com/federate';
56
    const endpointLink = mount(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
57
    const badges = endpointLink.find(Badge);
58
    expect(badges).toHaveLength(3);
59
    expect(consoleSpy).not.toHaveBeenCalled();
60
  });
61
});
62

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

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

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

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