]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.spec.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
3
4 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
5 import { configureTestBed } from '~/testing/unit-test-helper';
6 import { ImageSpec } from '../models/image-spec';
7 import { RbdConfigurationService } from '../services/rbd-configuration.service';
8 import { RbdService } from './rbd.service';
9
10 describe('RbdService', () => {
11 let service: RbdService;
12 let httpTesting: HttpTestingController;
13
14 configureTestBed({
15 providers: [RbdService, RbdConfigurationService],
16 imports: [HttpClientTestingModule]
17 });
18
19 beforeEach(() => {
20 service = TestBed.inject(RbdService);
21 httpTesting = TestBed.inject(HttpTestingController);
22 });
23
24 afterEach(() => {
25 httpTesting.verify();
26 });
27
28 it('should be created', () => {
29 expect(service).toBeTruthy();
30 });
31
32 it('should call create', () => {
33 service.create('foo').subscribe();
34 const req = httpTesting.expectOne('api/block/image');
35 expect(req.request.method).toBe('POST');
36 expect(req.request.body).toEqual('foo');
37 });
38
39 it('should call delete', () => {
40 service.delete(new ImageSpec('poolName', null, 'rbdName')).subscribe();
41 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
42 expect(req.request.method).toBe('DELETE');
43 });
44
45 it('should call update', () => {
46 service.update(new ImageSpec('poolName', null, 'rbdName'), 'foo').subscribe();
47 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
48 expect(req.request.body).toEqual('foo');
49 expect(req.request.method).toBe('PUT');
50 });
51
52 it('should call get', () => {
53 service.get(new ImageSpec('poolName', null, 'rbdName')).subscribe();
54 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
55 expect(req.request.method).toBe('GET');
56 });
57
58 it('should call list', () => {
59 /* tslint:disable:no-empty */
60 const context = new CdTableFetchDataContext(() => {});
61 service.list(context.toParams()).subscribe();
62 const req = httpTesting.expectOne((req) => {
63 return 'api/block/image?offset=0&limit=-1&search=&sort=+name' && req.method === 'GET';
64 });
65 expect(req.request.method).toBe('GET');
66 });
67
68 it('should call copy', () => {
69 service.copy(new ImageSpec('poolName', null, 'rbdName'), 'foo').subscribe();
70 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/copy');
71 expect(req.request.body).toEqual('foo');
72 expect(req.request.method).toBe('POST');
73 });
74
75 it('should call flatten', () => {
76 service.flatten(new ImageSpec('poolName', null, 'rbdName')).subscribe();
77 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/flatten');
78 expect(req.request.body).toEqual(null);
79 expect(req.request.method).toBe('POST');
80 });
81
82 it('should call defaultFeatures', () => {
83 service.defaultFeatures().subscribe();
84 const req = httpTesting.expectOne('api/block/image/default_features');
85 expect(req.request.method).toBe('GET');
86 });
87
88 it('should call cloneFormatVersion', () => {
89 service.cloneFormatVersion().subscribe();
90 const req = httpTesting.expectOne('api/block/image/clone_format_version');
91 expect(req.request.method).toBe('GET');
92 });
93
94 it('should call createSnapshot', () => {
95 service
96 .createSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', false)
97 .subscribe();
98 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap');
99 expect(req.request.body).toEqual({
100 snapshot_name: 'snapshotName',
101 mirrorImageSnapshot: false
102 });
103 expect(req.request.method).toBe('POST');
104 });
105
106 it('should call renameSnapshot', () => {
107 service
108 .renameSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', 'foo')
109 .subscribe();
110 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
111 expect(req.request.body).toEqual({
112 new_snap_name: 'foo'
113 });
114 expect(req.request.method).toBe('PUT');
115 });
116
117 it('should call protectSnapshot', () => {
118 service
119 .protectSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', true)
120 .subscribe();
121 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
122 expect(req.request.body).toEqual({
123 is_protected: true
124 });
125 expect(req.request.method).toBe('PUT');
126 });
127
128 it('should call rollbackSnapshot', () => {
129 service
130 .rollbackSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName')
131 .subscribe();
132 const req = httpTesting.expectOne(
133 'api/block/image/poolName%2FrbdName/snap/snapshotName/rollback'
134 );
135 expect(req.request.body).toEqual(null);
136 expect(req.request.method).toBe('POST');
137 });
138
139 it('should call cloneSnapshot', () => {
140 service
141 .cloneSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', null)
142 .subscribe();
143 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName/clone');
144 expect(req.request.body).toEqual(null);
145 expect(req.request.method).toBe('POST');
146 });
147
148 it('should call deleteSnapshot', () => {
149 service.deleteSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName').subscribe();
150 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
151 expect(req.request.method).toBe('DELETE');
152 });
153
154 it('should call moveTrash', () => {
155 service.moveTrash(new ImageSpec('poolName', null, 'rbdName'), 1).subscribe();
156 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/move_trash');
157 expect(req.request.method).toBe('POST');
158 expect(req.request.body).toEqual({ delay: 1 });
159 });
160
161 describe('should compose image spec', () => {
162 it('with namespace', () => {
163 expect(new ImageSpec('mypool', 'myns', 'myimage').toString()).toBe('mypool/myns/myimage');
164 });
165
166 it('without namespace', () => {
167 expect(new ImageSpec('mypool', null, 'myimage').toString()).toBe('mypool/myimage');
168 });
169 });
170
171 describe('should parse image spec', () => {
172 it('with namespace', () => {
173 const imageSpec = ImageSpec.fromString('mypool/myns/myimage');
174 expect(imageSpec.poolName).toBe('mypool');
175 expect(imageSpec.namespace).toBe('myns');
176 expect(imageSpec.imageName).toBe('myimage');
177 });
178
179 it('without namespace', () => {
180 const imageSpec = ImageSpec.fromString('mypool/myimage');
181 expect(imageSpec.poolName).toBe('mypool');
182 expect(imageSpec.namespace).toBeNull();
183 expect(imageSpec.imageName).toBe('myimage');
184 });
185 });
186 });