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