1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import _ from 'lodash';
5 import { NgxPipeFunctionModule } from 'ngx-pipe-function';
6 import { of } from 'rxjs';
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';
17 describe('ServiceDaemonListComponent', () => {
18 let component: ServiceDaemonListComponent;
19 let fixture: ComponentFixture<ServiceDaemonListComponent>;
24 container_id: '003c10beafc8c27b635bcdfed1ed832e4c1005be89bb1bb05ad4cc6c2b98e41b',
25 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
26 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
29 version: '15.1.0-1174-g16a11f7',
31 status_desc: 'running',
32 last_refresh: '2020-02-25T04:33:26.465699'
36 container_id: 'baeec41a01374b3ed41016d542d19aef4a70d69c27274f271e26381a0cc58e7a',
37 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
38 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
41 version: '15.1.0-1174-g16a11f7',
43 status_desc: 'running',
44 last_refresh: '2020-02-25T04:33:26.465822'
48 container_id: '8483de277e365bea4365cee9e1f26606be85c471e4da5d51f57e4b85a42c616e',
49 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
50 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
53 version: '15.1.0-1174-g16a11f7',
55 status_desc: 'running',
56 last_refresh: '2020-02-25T04:33:26.465886'
60 container_id: '6ca0574f47e300a6979eaf4e7c283a8c4325c2235ae60358482fc4cd58844a21',
61 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
62 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
65 version: '15.1.0-1174-g16a11f7',
67 status_desc: 'running',
68 last_refresh: '2020-02-25T04:33:26.465886'
72 const getDaemonsByHostname = (hostname?: string) => {
73 return hostname ? _.filter(daemons, { hostname: hostname }) : daemons;
76 const getDaemonsByServiceName = (serviceName?: string) => {
77 return serviceName ? _.filter(daemons, { daemon_type: serviceName }) : daemons;
81 imports: [HttpClientTestingModule, CephModule, CoreModule, NgxPipeFunctionModule, SharedModule]
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))
92 spyOn(cephServiceService, 'getDaemons').and.callFake(() =>
93 of(getDaemonsByServiceName(component.serviceName))
95 fixture.detectChanges();
98 it('should create', () => {
99 expect(component).toBeTruthy();
102 it('should list daemons by host', () => {
103 component.hostname = 'mon0';
104 component.getDaemons(new CdTableFetchDataContext(() => undefined));
105 expect(component.daemons.length).toBe(1);
108 it('should list daemons by service', () => {
109 component.serviceName = 'osd';
110 component.getDaemons(new CdTableFetchDataContext(() => undefined));
111 expect(component.daemons.length).toBe(3);
114 it('should not display doc panel if orchestrator is available', () => {
115 expect(component.showDocPanel).toBeFalsy();