1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import * as _ from 'lodash';
5 import { of } from 'rxjs';
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';
16 describe('ServiceDaemonListComponent', () => {
17 let component: ServiceDaemonListComponent;
18 let fixture: ComponentFixture<ServiceDaemonListComponent>;
23 container_id: '003c10beafc8c27b635bcdfed1ed832e4c1005be89bb1bb05ad4cc6c2b98e41b',
24 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
25 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
28 version: '15.1.0-1174-g16a11f7',
30 status_desc: 'running',
31 last_refresh: '2020-02-25T04:33:26.465699'
35 container_id: 'baeec41a01374b3ed41016d542d19aef4a70d69c27274f271e26381a0cc58e7a',
36 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
37 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
40 version: '15.1.0-1174-g16a11f7',
42 status_desc: 'running',
43 last_refresh: '2020-02-25T04:33:26.465822'
47 container_id: '8483de277e365bea4365cee9e1f26606be85c471e4da5d51f57e4b85a42c616e',
48 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
49 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
52 version: '15.1.0-1174-g16a11f7',
54 status_desc: 'running',
55 last_refresh: '2020-02-25T04:33:26.465886'
59 container_id: '6ca0574f47e300a6979eaf4e7c283a8c4325c2235ae60358482fc4cd58844a21',
60 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
61 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
64 version: '15.1.0-1174-g16a11f7',
66 status_desc: 'running',
67 last_refresh: '2020-02-25T04:33:26.465886'
71 const getDaemonsByHostname = (hostname?: string) => {
72 return hostname ? _.filter(daemons, { hostname: hostname }) : daemons;
75 const getDaemonsByServiceName = (serviceName?: string) => {
76 return serviceName ? _.filter(daemons, { daemon_type: serviceName }) : daemons;
80 imports: [HttpClientTestingModule, CephModule, CoreModule, SharedModule],
82 providers: [i18nProviders]
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))
93 spyOn(cephServiceService, 'getDaemons').and.callFake(() =>
94 of(getDaemonsByServiceName(component.serviceName))
96 fixture.detectChanges();
99 it('should create', () => {
100 expect(component).toBeTruthy();
103 it('should list daemons by host', () => {
104 component.hostname = 'mon0';
105 component.getDaemons(new CdTableFetchDataContext(() => {}));
106 expect(component.daemons.length).toBe(1);
109 it('should list daemons by service', () => {
110 component.serviceName = 'osd';
111 component.getDaemons(new CdTableFetchDataContext(() => {}));
112 expect(component.daemons.length).toBe(3);