]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts
42c06228d867f273549147603ebfad525e0e2943
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / service-daemon-list / service-daemon-list.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import _ from 'lodash';
5 import { NgxPipeFunctionModule } from 'ngx-pipe-function';
6 import { of } from 'rxjs';
7
8 import { CephModule } from '~/app/ceph/ceph.module';
9 import { CoreModule } from '~/app/core/core.module';
10 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
11 import { HostService } from '~/app/shared/api/host.service';
12 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
13 import { SharedModule } from '~/app/shared/shared.module';
14 import { configureTestBed } from '~/testing/unit-test-helper';
15 import { ServiceDaemonListComponent } from './service-daemon-list.component';
16
17 describe('ServiceDaemonListComponent', () => {
18 let component: ServiceDaemonListComponent;
19 let fixture: ComponentFixture<ServiceDaemonListComponent>;
20
21 const daemons = [
22 {
23 hostname: 'osd0',
24 container_id: '003c10beafc8c27b635bcdfed1ed832e4c1005be89bb1bb05ad4cc6c2b98e41b',
25 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
26 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
27 daemon_id: '3',
28 daemon_type: 'osd',
29 version: '15.1.0-1174-g16a11f7',
30 status: 1,
31 status_desc: 'running',
32 last_refresh: '2020-02-25T04:33:26.465699'
33 },
34 {
35 hostname: 'osd0',
36 container_id: 'baeec41a01374b3ed41016d542d19aef4a70d69c27274f271e26381a0cc58e7a',
37 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
38 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
39 daemon_id: '4',
40 daemon_type: 'osd',
41 version: '15.1.0-1174-g16a11f7',
42 status: 1,
43 status_desc: 'running',
44 last_refresh: '2020-02-25T04:33:26.465822'
45 },
46 {
47 hostname: 'osd0',
48 container_id: '8483de277e365bea4365cee9e1f26606be85c471e4da5d51f57e4b85a42c616e',
49 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
50 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
51 daemon_id: '5',
52 daemon_type: 'osd',
53 version: '15.1.0-1174-g16a11f7',
54 status: 1,
55 status_desc: 'running',
56 last_refresh: '2020-02-25T04:33:26.465886'
57 },
58 {
59 hostname: 'mon0',
60 container_id: '6ca0574f47e300a6979eaf4e7c283a8c4325c2235ae60358482fc4cd58844a21',
61 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
62 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
63 daemon_id: 'a',
64 daemon_type: 'mon',
65 version: '15.1.0-1174-g16a11f7',
66 status: 1,
67 status_desc: 'running',
68 last_refresh: '2020-02-25T04:33:26.465886'
69 }
70 ];
71
72 const getDaemonsByHostname = (hostname?: string) => {
73 return hostname ? _.filter(daemons, { hostname: hostname }) : daemons;
74 };
75
76 const getDaemonsByServiceName = (serviceName?: string) => {
77 return serviceName ? _.filter(daemons, { daemon_type: serviceName }) : daemons;
78 };
79
80 configureTestBed({
81 imports: [HttpClientTestingModule, CephModule, CoreModule, NgxPipeFunctionModule, SharedModule]
82 });
83
84 beforeEach(() => {
85 fixture = TestBed.createComponent(ServiceDaemonListComponent);
86 component = fixture.componentInstance;
87 const hostService = TestBed.inject(HostService);
88 const cephServiceService = TestBed.inject(CephServiceService);
89 spyOn(hostService, 'getDaemons').and.callFake(() =>
90 of(getDaemonsByHostname(component.hostname))
91 );
92 spyOn(cephServiceService, 'getDaemons').and.callFake(() =>
93 of(getDaemonsByServiceName(component.serviceName))
94 );
95 fixture.detectChanges();
96 });
97
98 it('should create', () => {
99 expect(component).toBeTruthy();
100 });
101
102 it('should list daemons by host', () => {
103 component.hostname = 'mon0';
104 component.getDaemons(new CdTableFetchDataContext(() => undefined));
105 expect(component.daemons.length).toBe(1);
106 });
107
108 it('should list daemons by service', () => {
109 component.serviceName = 'osd';
110 component.getDaemons(new CdTableFetchDataContext(() => undefined));
111 expect(component.daemons.length).toBe(3);
112 });
113
114 it('should not display doc panel if orchestrator is available', () => {
115 expect(component.showDocPanel).toBeFalsy();
116 });
117 });