@@ -2,13 +2,15 @@ import { TestBed } from '@angular/core/testing';
22import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
33import { configureTestBed } from '~/testing/unit-test-helper' ;
44import { NvmeofService } from '../../shared/api/nvmeof.service' ;
5+ import { throwError } from 'rxjs' ;
56
67describe ( 'NvmeofService' , ( ) => {
78 let service : NvmeofService ;
89 let httpTesting : HttpTestingController ;
910 const mockGroupName = 'default' ;
1011 const mockNQN = 'nqn.2001-07.com.ceph:1721041732363' ;
11-
12+ const UI_API_PATH = 'ui-api/nvmeof' ;
13+ const API_PATH = 'api/nvmeof' ;
1214 configureTestBed ( {
1315 providers : [ NvmeofService ] ,
1416 imports : [ HttpClientTestingModule ]
@@ -27,56 +29,155 @@ describe('NvmeofService', () => {
2729 expect ( service ) . toBeTruthy ( ) ;
2830 } ) ;
2931
30- // gateways
31- it ( 'should call listGatewayGroups' , ( ) => {
32- service . listGatewayGroups ( ) . subscribe ( ) ;
33- const req = httpTesting . expectOne ( 'api/nvmeof/ gateway/group' ) ;
34- expect ( req . request . method ) . toBe ( 'GET' ) ;
35- } ) ;
32+ describe ( 'test gateway APIs' , ( ) => {
33+ it ( 'should call listGatewayGroups' , ( ) => {
34+ service . listGatewayGroups ( ) . subscribe ( ) ;
35+ const req = httpTesting . expectOne ( ` ${ API_PATH } / gateway/group` ) ;
36+ expect ( req . request . method ) . toBe ( 'GET' ) ;
37+ } ) ;
3638
37- it ( 'should call listGateways' , ( ) => {
38- service . listGateways ( ) . subscribe ( ) ;
39- const req = httpTesting . expectOne ( 'api/nvmeof/gateway' ) ;
40- expect ( req . request . method ) . toBe ( 'GET' ) ;
39+ it ( 'should call listGateways' , ( ) => {
40+ service . listGateways ( ) . subscribe ( ) ;
41+ const req = httpTesting . expectOne ( `${ API_PATH } /gateway` ) ;
42+ expect ( req . request . method ) . toBe ( 'GET' ) ;
43+ } ) ;
4144 } ) ;
4245
43- // subsystems
44- it ( 'should call listSubsystems' , ( ) => {
45- service . listSubsystems ( mockGroupName ) . subscribe ( ) ;
46- const req = httpTesting . expectOne ( `api/nvmeof/subsystem?gw_group=${ mockGroupName } ` ) ;
47- expect ( req . request . method ) . toBe ( 'GET' ) ;
48- } ) ;
46+ describe ( 'test subsystems APIs' , ( ) => {
47+ it ( 'should call listSubsystems' , ( ) => {
48+ service . listSubsystems ( mockGroupName ) . subscribe ( ) ;
49+ const req = httpTesting . expectOne ( `${ API_PATH } /subsystem?gw_group=${ mockGroupName } ` ) ;
50+ expect ( req . request . method ) . toBe ( 'GET' ) ;
51+ } ) ;
52+
53+ it ( 'should call getSubsystem' , ( ) => {
54+ service . getSubsystem ( mockNQN , mockGroupName ) . subscribe ( ) ;
55+ const req = httpTesting . expectOne (
56+ `${ API_PATH } /subsystem/${ mockNQN } ?gw_group=${ mockGroupName } `
57+ ) ;
58+ expect ( req . request . method ) . toBe ( 'GET' ) ;
59+ } ) ;
60+
61+ it ( 'should call createSubsystem' , ( ) => {
62+ const request = {
63+ nqn : mockNQN ,
64+ enable_ha : true ,
65+ initiators : '*' ,
66+ gw_group : mockGroupName
67+ } ;
68+ service . createSubsystem ( request ) . subscribe ( ) ;
69+ const req = httpTesting . expectOne ( `${ API_PATH } /subsystem` ) ;
70+ expect ( req . request . method ) . toBe ( 'POST' ) ;
71+ } ) ;
4972
50- it ( 'should call getSubsystem' , ( ) => {
51- service . getSubsystem ( mockNQN , mockGroupName ) . subscribe ( ) ;
52- const req = httpTesting . expectOne ( `api/nvmeof/subsystem/${ mockNQN } ?gw_group=${ mockGroupName } ` ) ;
53- expect ( req . request . method ) . toBe ( 'GET' ) ;
73+ it ( 'should call deleteSubsystem' , ( ) => {
74+ service . deleteSubsystem ( mockNQN , mockGroupName ) . subscribe ( ) ;
75+ const req = httpTesting . expectOne (
76+ `${ API_PATH } /subsystem/${ mockNQN } ?gw_group=${ mockGroupName } `
77+ ) ;
78+ expect ( req . request . method ) . toBe ( 'DELETE' ) ;
79+ } ) ;
80+ it ( 'should call isSubsystemPresent' , ( ) => {
81+ spyOn ( service , 'getSubsystem' ) . and . returnValue ( throwError ( 'test' ) ) ;
82+ service . isSubsystemPresent ( mockNQN , mockGroupName ) . subscribe ( ( res ) => {
83+ expect ( res ) . toBe ( false ) ;
84+ } ) ;
85+ } ) ;
5486 } ) ;
5587
56- it ( 'should call createSubsystem' , ( ) => {
57- const request = {
58- nqn : mockNQN ,
59- enable_ha : true ,
60- initiators : '*' ,
61- gw_group : mockGroupName
62- } ;
63- service . createSubsystem ( request ) . subscribe ( ) ;
64- const req = httpTesting . expectOne ( 'api/nvmeof/subsystem' ) ;
65- expect ( req . request . method ) . toBe ( 'POST' ) ;
88+ describe ( 'test initiators APIs' , ( ) => {
89+ let request = { host_nqn : '' , gw_group : mockGroupName } ;
90+ it ( 'should call getInitiators' , ( ) => {
91+ service . getInitiators ( mockNQN , mockGroupName ) . subscribe ( ) ;
92+ const req = httpTesting . expectOne (
93+ `${ API_PATH } /subsystem/${ mockNQN } /host?gw_group=${ mockGroupName } `
94+ ) ;
95+ expect ( req . request . method ) . toBe ( 'GET' ) ;
96+ } ) ;
97+ it ( 'should call addInitiators' , ( ) => {
98+ service . addInitiators ( mockNQN , request ) . subscribe ( ) ;
99+ const req = httpTesting . expectOne ( `${ UI_API_PATH } /subsystem/${ mockNQN } /host` ) ;
100+ expect ( req . request . method ) . toBe ( 'POST' ) ;
101+ } ) ;
102+ it ( 'should call removeInitiators' , ( ) => {
103+ service . removeInitiators ( mockNQN , request ) . subscribe ( ) ;
104+ const req = httpTesting . expectOne (
105+ `${ UI_API_PATH } /subsystem/${ mockNQN } /host/${ request . host_nqn } /${ mockGroupName } `
106+ ) ;
107+ expect ( req . request . method ) . toBe ( 'DELETE' ) ;
108+ } ) ;
66109 } ) ;
67110
68- it ( 'should call deleteSubsystem' , ( ) => {
69- service . deleteSubsystem ( mockNQN , mockGroupName ) . subscribe ( ) ;
70- const req = httpTesting . expectOne ( `api/nvmeof/subsystem/${ mockNQN } ?gw_group=${ mockGroupName } ` ) ;
71- expect ( req . request . method ) . toBe ( 'DELETE' ) ;
111+ describe ( 'test listener APIs' , ( ) => {
112+ it ( 'it should listListeners' , ( ) => {
113+ service . listListeners ( mockNQN , mockGroupName ) . subscribe ( ) ;
114+ const req = httpTesting . expectOne (
115+ `${ API_PATH } /subsystem/${ mockNQN } /listener?gw_group=${ mockGroupName } `
116+ ) ;
117+ expect ( req . request . method ) . toBe ( 'GET' ) ;
118+ } ) ;
119+ it ( 'should call createListener' , ( ) => {
120+ const request = {
121+ gw_group : mockGroupName ,
122+ host_name : 'ceph-node-02' ,
123+ traddr : '192.168.100.102' ,
124+ trsvcid : 4421
125+ } ;
126+ service . createListener ( mockNQN , request ) . subscribe ( ) ;
127+ const req = httpTesting . expectOne ( `${ API_PATH } /subsystem/${ mockNQN } /listener` ) ;
128+ expect ( req . request . method ) . toBe ( 'POST' ) ;
129+ } ) ;
130+ it ( 'should call deleteListener' , ( ) => {
131+ const request = { host_name : 'ceph-node-02' , traddr : '192.168.100.102' , trsvcid : '4421' } ;
132+ service
133+ . deleteListener ( mockNQN , request . host_name , request . traddr , request . trsvcid )
134+ . subscribe ( ) ;
135+ const req = httpTesting . expectOne (
136+ `${ API_PATH } /subsystem/${ mockNQN } /listener/${ request . host_name } /${ request . traddr } ?trsvcid=${ request . trsvcid } `
137+ ) ;
138+ expect ( req . request . method ) . toBe ( 'DELETE' ) ;
139+ } ) ;
72140 } ) ;
73141
74- // initiators
75- it ( 'should call getInitiators' , ( ) => {
76- service . getInitiators ( mockNQN , mockGroupName ) . subscribe ( ) ;
77- const req = httpTesting . expectOne (
78- `api/nvmeof/subsystem/${ mockNQN } /host?gw_group=${ mockGroupName } `
79- ) ;
80- expect ( req . request . method ) . toBe ( 'GET' ) ;
142+ describe ( 'test namespace APIs' , ( ) => {
143+ const mockNsid = '1' ;
144+ it ( 'should call listNamespaces' , ( ) => {
145+ service . listNamespaces ( mockNQN , mockGroupName ) . subscribe ( ) ;
146+ const req = httpTesting . expectOne (
147+ `${ API_PATH } /subsystem/${ mockNQN } /namespace?gw_group=${ mockGroupName } `
148+ ) ;
149+ expect ( req . request . method ) . toBe ( 'GET' ) ;
150+ } ) ;
151+ it ( 'should call getNamespace' , ( ) => {
152+ service . getNamespace ( mockNQN , mockNsid , mockGroupName ) . subscribe ( ) ;
153+ const req = httpTesting . expectOne (
154+ `${ API_PATH } /subsystem/${ mockNQN } /namespace/${ mockNsid } ?gw_group=${ mockGroupName } `
155+ ) ;
156+ expect ( req . request . method ) . toBe ( 'GET' ) ;
157+ } ) ;
158+ it ( 'should call createNamespace' , ( ) => {
159+ const mockNamespaceObj = {
160+ rbd_image_name : 'nvme_ns_image:12345678' ,
161+ rbd_pool : 'rbd' ,
162+ size : 1024 ,
163+ gw_group : mockGroupName
164+ } ;
165+ service . createNamespace ( mockNQN , mockNamespaceObj ) . subscribe ( ) ;
166+ const req = httpTesting . expectOne ( `${ API_PATH } /subsystem/${ mockNQN } /namespace` ) ;
167+ expect ( req . request . method ) . toBe ( 'POST' ) ;
168+ } ) ;
169+ it ( 'should call updateNamespace' , ( ) => {
170+ const request = { rbd_image_size : 1024 , gw_group : mockGroupName } ;
171+ service . updateNamespace ( mockNQN , mockNsid , request ) . subscribe ( ) ;
172+ const req = httpTesting . expectOne ( `${ API_PATH } /subsystem/${ mockNQN } /namespace/${ mockNsid } ` ) ;
173+ expect ( req . request . method ) . toBe ( 'PATCH' ) ;
174+ } ) ;
175+ it ( 'should call deleteNamespace' , ( ) => {
176+ service . deleteNamespace ( mockNQN , mockNsid , mockGroupName ) . subscribe ( ) ;
177+ const req = httpTesting . expectOne (
178+ `${ API_PATH } /subsystem/${ mockNQN } /namespace/${ mockNsid } ?gw_group=${ mockGroupName } `
179+ ) ;
180+ expect ( req . request . method ) . toBe ( 'DELETE' ) ;
181+ } ) ;
81182 } ) ;
82183} ) ;
0 commit comments