]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
23fe095088956cbfd4b7ce24df8adcb0dd4a87b1
[ceph-ci.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 } 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   });
82
83   beforeEach(() => {
84     fixture = TestBed.createComponent(ServiceDaemonListComponent);
85     component = fixture.componentInstance;
86     const hostService = TestBed.inject(HostService);
87     const cephServiceService = TestBed.inject(CephServiceService);
88     spyOn(hostService, 'getDaemons').and.callFake(() =>
89       of(getDaemonsByHostname(component.hostname))
90     );
91     spyOn(cephServiceService, 'getDaemons').and.callFake(() =>
92       of(getDaemonsByServiceName(component.serviceName))
93     );
94     fixture.detectChanges();
95   });
96
97   it('should create', () => {
98     expect(component).toBeTruthy();
99   });
100
101   it('should list daemons by host', () => {
102     component.hostname = 'mon0';
103     component.getDaemons(new CdTableFetchDataContext(() => undefined));
104     expect(component.daemons.length).toBe(1);
105   });
106
107   it('should list daemons by service', () => {
108     component.serviceName = 'osd';
109     component.getDaemons(new CdTableFetchDataContext(() => undefined));
110     expect(component.daemons.length).toBe(3);
111   });
112 });