]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
1c8bf5485661be2f608681e302c51d61978e73b5
[ceph-ci.git] /
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';
10
11 const mockServiceDaemons = [
12   {
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'
22     ],
23     memory_usage: 89443532,
24     cpu_percentage: '98.87%',
25     version: '1.2.17',
26     status: 1,
27     status_desc: 'running'
28   },
29   {
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'
39     ],
40     memory_usage: 89328189,
41     cpu_percentage: '98.89%',
42     version: '1.2.17',
43     status: 1,
44     status_desc: 'running'
45   }
46 ];
47
48 const mockGateways = [
49   {
50     id: 'client.nvmeof.nvmeof.default.ceph-node-01.kdcguk',
51     hostname: 'ceph-node-01',
52     status_desc: 'running',
53     status: 1
54   },
55   {
56     id: 'client.nvmeof.nvmeof.default.ceph-node-02.hybprc',
57     hostname: 'ceph-node-02',
58     status_desc: 'running',
59     status: 1
60   }
61 ];
62
63 const mockGwGroups = [
64   {
65     content: 'default',
66     serviceName: 'nvmeof.rbd.default'
67   },
68   {
69     content: 'foo',
70     serviceName: 'nvmeof.rbd.foo'
71   }
72 ];
73
74 const mockServices = [
75   [
76     {
77       service_name: 'nvmeof.rbd.default',
78       service_type: 'nvmeof',
79       unmanaged: false,
80       spec: {
81         group: 'default'
82       }
83     },
84     {
85       service_name: 'nvmeof.rbd.foo',
86       service_type: 'nvmeof',
87       unmanaged: false,
88       spec: {
89         group: 'foo'
90       }
91     }
92   ],
93   2
94 ];
95 class MockNvmeOfService {
96   listGatewayGroups() {
97     return of(mockServices);
98   }
99 }
100
101 class MockCephServiceService {
102   getDaemons(_service: string) {
103     return of(mockServiceDaemons);
104   }
105 }
106
107 describe('NvmeofGatewayComponent', () => {
108   let component: NvmeofGatewayComponent;
109   let fixture: ComponentFixture<NvmeofGatewayComponent>;
110
111   beforeEach(async () => {
112     await TestBed.configureTestingModule({
113       declarations: [NvmeofGatewayComponent, NvmeofTabsComponent],
114       imports: [HttpClientModule, SharedModule, ComboBoxModule, GridModule],
115       providers: [
116         { provide: NvmeofService, useClass: MockNvmeOfService },
117         { provide: CephServiceService, useClass: MockCephServiceService }
118       ]
119     }).compileComponents();
120
121     fixture = TestBed.createComponent(NvmeofGatewayComponent);
122     component = fixture.componentInstance;
123     component.ngOnInit();
124     fixture.detectChanges();
125   });
126
127   it('should create', () => {
128     expect(component).toBeTruthy();
129   });
130
131   it('should load gateway groups correctly', () => {
132     expect(component.gwGroups.length).toBe(2);
133     expect(component.gwGroups).toStrictEqual(mockGwGroups);
134   });
135
136   it('should set service name of gateway groups correctly', () => {
137     expect(component.groupService).toBe(mockServices[0][0].service_name);
138   });
139
140   it('should set gateways correctly', () => {
141     expect(component.gateways.length).toBe(2);
142     expect(component.gateways).toStrictEqual(mockGateways);
143   });
144 });