1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { of } from 'rxjs';
3 import { NvmeofGatewayComponent } from './nvmeof-gateway.component';
4 import { NvmeofService } from '../../../shared/api/nvmeof.service';
5 import { HttpClientModule } from '@angular/common/http';
6 import { SharedModule } from '~/app/shared/shared.module';
7 import { ComboBoxModule, GridModule } from 'carbon-components-angular';
8 import { NvmeofTabsComponent } from '../nvmeof-tabs/nvmeof-tabs.component';
9 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
11 const mockServiceDaemons = [
13 daemon_type: 'nvmeof',
14 daemon_id: 'nvmeof.default.ceph-node-01.kdcguk',
15 daemon_name: 'nvmeof.nvmeof.default.ceph-node-01.kdcguk',
16 hostname: 'ceph-node-01',
17 container_id: '6fe5a9ae9c96',
18 container_image_id: '32a3d75b7c146d6c37b04ee3c9ba883ab88a8f7ae8f286de268d0f41ebd86a51',
19 container_image_name: 'quay.io/ceph/nvmeof:1.2.17',
20 container_image_digests: [
21 'quay.io/ceph/nvmeof@sha256:4308d05d3bb2167fc695d755316fec8d12ec3f00eb7639eeeabad38a5c4df0f9'
23 memory_usage: 89443532,
24 cpu_percentage: '98.87%',
27 status_desc: 'running'
30 daemon_type: 'nvmeof',
31 daemon_id: 'nvmeof.default.ceph-node-02.hybprc',
32 daemon_name: 'nvmeof.nvmeof.default.ceph-node-02.hybprc',
33 hostname: 'ceph-node-02',
34 container_id: '2b061130726b',
35 container_image_id: '32a3d75b7c146d6c37b04ee3c9ba883ab88a8f7ae8f286de268d0f41ebd86a51',
36 container_image_name: 'quay.io/ceph/nvmeof:1.2.17',
37 container_image_digests: [
38 'quay.io/ceph/nvmeof@sha256:4308d05d3bb2167fc695d755316fec8d12ec3f00eb7639eeeabad38a5c4df0f9'
40 memory_usage: 89328189,
41 cpu_percentage: '98.89%',
44 status_desc: 'running'
48 const mockGateways = [
50 id: 'client.nvmeof.nvmeof.default.ceph-node-01.kdcguk',
51 hostname: 'ceph-node-01',
52 status_desc: 'running',
56 id: 'client.nvmeof.nvmeof.default.ceph-node-02.hybprc',
57 hostname: 'ceph-node-02',
58 status_desc: 'running',
63 const mockGwGroups = [
66 serviceName: 'nvmeof.rbd.default'
70 serviceName: 'nvmeof.rbd.foo'
74 const mockServices = [
77 service_name: 'nvmeof.rbd.default',
78 service_type: 'nvmeof',
85 service_name: 'nvmeof.rbd.foo',
86 service_type: 'nvmeof',
95 class MockNvmeOfService {
97 return of(mockServices);
101 class MockCephServiceService {
102 getDaemons(_service: string) {
103 return of(mockServiceDaemons);
107 describe('NvmeofGatewayComponent', () => {
108 let component: NvmeofGatewayComponent;
109 let fixture: ComponentFixture<NvmeofGatewayComponent>;
111 beforeEach(async () => {
112 await TestBed.configureTestingModule({
113 declarations: [NvmeofGatewayComponent, NvmeofTabsComponent],
114 imports: [HttpClientModule, SharedModule, ComboBoxModule, GridModule],
116 { provide: NvmeofService, useClass: MockNvmeOfService },
117 { provide: CephServiceService, useClass: MockCephServiceService }
119 }).compileComponents();
121 fixture = TestBed.createComponent(NvmeofGatewayComponent);
122 component = fixture.componentInstance;
123 component.ngOnInit();
124 fixture.detectChanges();
127 it('should create', () => {
128 expect(component).toBeTruthy();
131 it('should load gateway groups correctly', () => {
132 expect(component.gwGroups.length).toBe(2);
133 expect(component.gwGroups).toStrictEqual(mockGwGroups);
136 it('should set service name of gateway groups correctly', () => {
137 expect(component.groupService).toBe(mockServices[0][0].service_name);
140 it('should set gateways correctly', () => {
141 expect(component.gateways.length).toBe(2);
142 expect(component.gateways).toStrictEqual(mockGateways);