]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.spec.ts
add stop-gap to fix compat with CPUs not supporting SSE 4.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('api/block/image?offset=0&limit=10&search=&sort=+name');
63 expect(req.request.method).toBe('GET');
64 });
65
66 it('should call copy', () => {
67 service.copy(new ImageSpec('poolName', null, 'rbdName'), 'foo').subscribe();
68 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/copy');
69 expect(req.request.body).toEqual('foo');
70 expect(req.request.method).toBe('POST');
71 });
72
73 it('should call flatten', () => {
74 service.flatten(new ImageSpec('poolName', null, 'rbdName')).subscribe();
75 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/flatten');
76 expect(req.request.body).toEqual(null);
77 expect(req.request.method).toBe('POST');
78 });
79
80 it('should call defaultFeatures', () => {
81 service.defaultFeatures().subscribe();
82 const req = httpTesting.expectOne('api/block/image/default_features');
83 expect(req.request.method).toBe('GET');
84 });
85
86 it('should call cloneFormatVersion', () => {
87 service.cloneFormatVersion().subscribe();
88 const req = httpTesting.expectOne('api/block/image/clone_format_version');
89 expect(req.request.method).toBe('GET');
90 });
91
92 it('should call createSnapshot', () => {
93 service
94 .createSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', false)
95 .subscribe();
96 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap');
97 expect(req.request.body).toEqual({
98 snapshot_name: 'snapshotName',
99 mirrorImageSnapshot: false
100 });
101 expect(req.request.method).toBe('POST');
102 });
103
104 it('should call renameSnapshot', () => {
105 service
106 .renameSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', 'foo')
107 .subscribe();
108 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
109 expect(req.request.body).toEqual({
110 new_snap_name: 'foo'
111 });
112 expect(req.request.method).toBe('PUT');
113 });
114
115 it('should call protectSnapshot', () => {
116 service
117 .protectSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', true)
118 .subscribe();
119 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
120 expect(req.request.body).toEqual({
121 is_protected: true
122 });
123 expect(req.request.method).toBe('PUT');
124 });
125
126 it('should call rollbackSnapshot', () => {
127 service
128 .rollbackSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName')
129 .subscribe();
130 const req = httpTesting.expectOne(
131 'api/block/image/poolName%2FrbdName/snap/snapshotName/rollback'
132 );
133 expect(req.request.body).toEqual(null);
134 expect(req.request.method).toBe('POST');
135 });
136
137 it('should call cloneSnapshot', () => {
138 service
139 .cloneSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', null)
140 .subscribe();
141 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName/clone');
142 expect(req.request.body).toEqual(null);
143 expect(req.request.method).toBe('POST');
144 });
145
146 it('should call deleteSnapshot', () => {
147 service.deleteSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName').subscribe();
148 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
149 expect(req.request.method).toBe('DELETE');
150 });
151
152 it('should call moveTrash', () => {
153 service.moveTrash(new ImageSpec('poolName', null, 'rbdName'), 1).subscribe();
154 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/move_trash');
155 expect(req.request.method).toBe('POST');
156 expect(req.request.body).toEqual({ delay: 1 });
157 });
158
159 describe('should compose image spec', () => {
160 it('with namespace', () => {
161 expect(new ImageSpec('mypool', 'myns', 'myimage').toString()).toBe('mypool/myns/myimage');
162 });
163
164 it('without namespace', () => {
165 expect(new ImageSpec('mypool', null, 'myimage').toString()).toBe('mypool/myimage');
166 });
167 });
168
169 describe('should parse image spec', () => {
170 it('with namespace', () => {
171 const imageSpec = ImageSpec.fromString('mypool/myns/myimage');
172 expect(imageSpec.poolName).toBe('mypool');
173 expect(imageSpec.namespace).toBe('myns');
174 expect(imageSpec.imageName).toBe('myimage');
175 });
176
177 it('without namespace', () => {
178 const imageSpec = ImageSpec.fromString('mypool/myimage');
179 expect(imageSpec.poolName).toBe('mypool');
180 expect(imageSpec.namespace).toBeNull();
181 expect(imageSpec.imageName).toBe('myimage');
182 });
183 });
184 });