diff options
author | Achint Kaur <achintkaur@li-8aebdecc-36ad-11b2-a85c-b4a398c03cde.ibm.com> | 2024-10-18 14:11:38 +0200 |
---|---|---|
committer | Achint Kaur <achintkaur@li-8aebdecc-36ad-11b2-a85c-b4a398c03cde.ibm.com> | 2024-10-25 07:49:26 +0200 |
commit | f1135273f3300a2bf1181859614530a5f034da61 (patch) | |
tree | eeb4767ef3a6f374d74873376da36be22ed07838 /src/pybind/mgr/dashboard/frontend | |
parent | Merge pull request #59782 from aclamk/wip-aclamk-fix-67596-allocmap (diff) | |
download | ceph-f1135273f3300a2bf1181859614530a5f034da61.tar.xz ceph-f1135273f3300a2bf1181859614530a5f034da61.zip |
Add API tests for nvmeof service.ts file
Fixes: https://tracker.ceph.com/issues/68551
Signed-off-by: Achint Kaur <ackaur@redhat.com>
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend')
-rwxr-xr-x[-rw-r--r--] | src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts | 185 |
1 files changed, 143 insertions, 42 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts index a5c84e60b6f..92eee852d88 100644..100755 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts @@ -2,13 +2,15 @@ import { TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { configureTestBed } from '~/testing/unit-test-helper'; import { NvmeofService } from '../../shared/api/nvmeof.service'; +import { throwError } from 'rxjs'; describe('NvmeofService', () => { let service: NvmeofService; let httpTesting: HttpTestingController; const mockGroupName = 'default'; const mockNQN = 'nqn.2001-07.com.ceph:1721041732363'; - + const UI_API_PATH = 'ui-api/nvmeof'; + const API_PATH = 'api/nvmeof'; configureTestBed({ providers: [NvmeofService], imports: [HttpClientTestingModule] @@ -27,56 +29,155 @@ describe('NvmeofService', () => { expect(service).toBeTruthy(); }); - // gateways - it('should call listGatewayGroups', () => { - service.listGatewayGroups().subscribe(); - const req = httpTesting.expectOne('api/nvmeof/gateway/group'); - expect(req.request.method).toBe('GET'); - }); + describe('test gateway APIs', () => { + it('should call listGatewayGroups', () => { + service.listGatewayGroups().subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/gateway/group`); + expect(req.request.method).toBe('GET'); + }); - it('should call listGateways', () => { - service.listGateways().subscribe(); - const req = httpTesting.expectOne('api/nvmeof/gateway'); - expect(req.request.method).toBe('GET'); + it('should call listGateways', () => { + service.listGateways().subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/gateway`); + expect(req.request.method).toBe('GET'); + }); }); - // subsystems - it('should call listSubsystems', () => { - service.listSubsystems(mockGroupName).subscribe(); - const req = httpTesting.expectOne(`api/nvmeof/subsystem?gw_group=${mockGroupName}`); - expect(req.request.method).toBe('GET'); - }); + describe('test subsystems APIs', () => { + it('should call listSubsystems', () => { + service.listSubsystems(mockGroupName).subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/subsystem?gw_group=${mockGroupName}`); + expect(req.request.method).toBe('GET'); + }); + + it('should call getSubsystem', () => { + service.getSubsystem(mockNQN, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('GET'); + }); + + it('should call createSubsystem', () => { + const request = { + nqn: mockNQN, + enable_ha: true, + initiators: '*', + gw_group: mockGroupName + }; + service.createSubsystem(request).subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/subsystem`); + expect(req.request.method).toBe('POST'); + }); - it('should call getSubsystem', () => { - service.getSubsystem(mockNQN, mockGroupName).subscribe(); - const req = httpTesting.expectOne(`api/nvmeof/subsystem/${mockNQN}?gw_group=${mockGroupName}`); - expect(req.request.method).toBe('GET'); + it('should call deleteSubsystem', () => { + service.deleteSubsystem(mockNQN, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('DELETE'); + }); + it('should call isSubsystemPresent', () => { + spyOn(service, 'getSubsystem').and.returnValue(throwError('test')); + service.isSubsystemPresent(mockNQN, mockGroupName).subscribe((res) => { + expect(res).toBe(false); + }); + }); }); - it('should call createSubsystem', () => { - const request = { - nqn: mockNQN, - enable_ha: true, - initiators: '*', - gw_group: mockGroupName - }; - service.createSubsystem(request).subscribe(); - const req = httpTesting.expectOne('api/nvmeof/subsystem'); - expect(req.request.method).toBe('POST'); + describe('test initiators APIs', () => { + let request = { host_nqn: '', gw_group: mockGroupName }; + it('should call getInitiators', () => { + service.getInitiators(mockNQN, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/host?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('GET'); + }); + it('should call addInitiators', () => { + service.addInitiators(mockNQN, request).subscribe(); + const req = httpTesting.expectOne(`${UI_API_PATH}/subsystem/${mockNQN}/host`); + expect(req.request.method).toBe('POST'); + }); + it('should call removeInitiators', () => { + service.removeInitiators(mockNQN, request).subscribe(); + const req = httpTesting.expectOne( + `${UI_API_PATH}/subsystem/${mockNQN}/host/${request.host_nqn}/${mockGroupName}` + ); + expect(req.request.method).toBe('DELETE'); + }); }); - it('should call deleteSubsystem', () => { - service.deleteSubsystem(mockNQN, mockGroupName).subscribe(); - const req = httpTesting.expectOne(`api/nvmeof/subsystem/${mockNQN}?gw_group=${mockGroupName}`); - expect(req.request.method).toBe('DELETE'); + describe('test listener APIs', () => { + it('it should listListeners', () => { + service.listListeners(mockNQN, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/listener?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('GET'); + }); + it('should call createListener', () => { + const request = { + gw_group: mockGroupName, + host_name: 'ceph-node-02', + traddr: '192.168.100.102', + trsvcid: 4421 + }; + service.createListener(mockNQN, request).subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/subsystem/${mockNQN}/listener`); + expect(req.request.method).toBe('POST'); + }); + it('should call deleteListener', () => { + const request = { host_name: 'ceph-node-02', traddr: '192.168.100.102', trsvcid: '4421' }; + service + .deleteListener(mockNQN, request.host_name, request.traddr, request.trsvcid) + .subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/listener/${request.host_name}/${request.traddr}?trsvcid=${request.trsvcid}` + ); + expect(req.request.method).toBe('DELETE'); + }); }); - // initiators - it('should call getInitiators', () => { - service.getInitiators(mockNQN, mockGroupName).subscribe(); - const req = httpTesting.expectOne( - `api/nvmeof/subsystem/${mockNQN}/host?gw_group=${mockGroupName}` - ); - expect(req.request.method).toBe('GET'); + describe('test namespace APIs', () => { + const mockNsid = '1'; + it('should call listNamespaces', () => { + service.listNamespaces(mockNQN, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/namespace?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('GET'); + }); + it('should call getNamespace', () => { + service.getNamespace(mockNQN, mockNsid, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/namespace/${mockNsid}?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('GET'); + }); + it('should call createNamespace', () => { + const mockNamespaceObj = { + rbd_image_name: 'nvme_ns_image:12345678', + rbd_pool: 'rbd', + size: 1024, + gw_group: mockGroupName + }; + service.createNamespace(mockNQN, mockNamespaceObj).subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/subsystem/${mockNQN}/namespace`); + expect(req.request.method).toBe('POST'); + }); + it('should call updateNamespace', () => { + const request = { rbd_image_size: 1024, gw_group: mockGroupName }; + service.updateNamespace(mockNQN, mockNsid, request).subscribe(); + const req = httpTesting.expectOne(`${API_PATH}/subsystem/${mockNQN}/namespace/${mockNsid}`); + expect(req.request.method).toBe('PATCH'); + }); + it('should call deleteNamespace', () => { + service.deleteNamespace(mockNQN, mockNsid, mockGroupName).subscribe(); + const req = httpTesting.expectOne( + `${API_PATH}/subsystem/${mockNQN}/namespace/${mockNsid}?gw_group=${mockGroupName}` + ); + expect(req.request.method).toBe('DELETE'); + }); }); }); |