]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.spec.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd.service.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2import { TestBed } from '@angular/core/testing';
3
2a845540 4import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
f67539c2 5import { configureTestBed } from '~/testing/unit-test-helper';
9f95a23c 6import { ImageSpec } from '../models/image-spec';
11fdf7f2
TL
7import { RbdConfigurationService } from '../services/rbd-configuration.service';
8import { RbdService } from './rbd.service';
9
10describe('RbdService', () => {
11 let service: RbdService;
12 let httpTesting: HttpTestingController;
13
14 configureTestBed({
f67539c2 15 providers: [RbdService, RbdConfigurationService],
11fdf7f2
TL
16 imports: [HttpClientTestingModule]
17 });
18
19 beforeEach(() => {
f67539c2
TL
20 service = TestBed.inject(RbdService);
21 httpTesting = TestBed.inject(HttpTestingController);
11fdf7f2
TL
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', () => {
9f95a23c
TL
40 service.delete(new ImageSpec('poolName', null, 'rbdName')).subscribe();
41 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
11fdf7f2
TL
42 expect(req.request.method).toBe('DELETE');
43 });
44
45 it('should call update', () => {
9f95a23c
TL
46 service.update(new ImageSpec('poolName', null, 'rbdName'), 'foo').subscribe();
47 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
11fdf7f2
TL
48 expect(req.request.body).toEqual('foo');
49 expect(req.request.method).toBe('PUT');
50 });
51
52 it('should call get', () => {
9f95a23c
TL
53 service.get(new ImageSpec('poolName', null, 'rbdName')).subscribe();
54 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName');
11fdf7f2
TL
55 expect(req.request.method).toBe('GET');
56 });
57
58 it('should call list', () => {
2a845540
TL
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');
11fdf7f2
TL
63 expect(req.request.method).toBe('GET');
64 });
65
66 it('should call copy', () => {
9f95a23c
TL
67 service.copy(new ImageSpec('poolName', null, 'rbdName'), 'foo').subscribe();
68 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/copy');
11fdf7f2
TL
69 expect(req.request.body).toEqual('foo');
70 expect(req.request.method).toBe('POST');
71 });
72
73 it('should call flatten', () => {
9f95a23c
TL
74 service.flatten(new ImageSpec('poolName', null, 'rbdName')).subscribe();
75 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/flatten');
11fdf7f2
TL
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
f67539c2
TL
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
11fdf7f2 92 it('should call createSnapshot', () => {
9f95a23c
TL
93 service.createSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName').subscribe();
94 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap');
11fdf7f2
TL
95 expect(req.request.body).toEqual({
96 snapshot_name: 'snapshotName'
97 });
98 expect(req.request.method).toBe('POST');
99 });
100
101 it('should call renameSnapshot', () => {
9f95a23c
TL
102 service
103 .renameSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', 'foo')
104 .subscribe();
105 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
11fdf7f2
TL
106 expect(req.request.body).toEqual({
107 new_snap_name: 'foo'
108 });
109 expect(req.request.method).toBe('PUT');
110 });
111
112 it('should call protectSnapshot', () => {
9f95a23c
TL
113 service
114 .protectSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', true)
115 .subscribe();
116 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
11fdf7f2
TL
117 expect(req.request.body).toEqual({
118 is_protected: true
119 });
120 expect(req.request.method).toBe('PUT');
121 });
122
123 it('should call rollbackSnapshot', () => {
9f95a23c
TL
124 service
125 .rollbackSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName')
126 .subscribe();
11fdf7f2 127 const req = httpTesting.expectOne(
9f95a23c 128 'api/block/image/poolName%2FrbdName/snap/snapshotName/rollback'
11fdf7f2
TL
129 );
130 expect(req.request.body).toEqual(null);
131 expect(req.request.method).toBe('POST');
132 });
133
134 it('should call cloneSnapshot', () => {
9f95a23c
TL
135 service
136 .cloneSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName', null)
137 .subscribe();
138 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName/clone');
11fdf7f2
TL
139 expect(req.request.body).toEqual(null);
140 expect(req.request.method).toBe('POST');
141 });
142
143 it('should call deleteSnapshot', () => {
9f95a23c
TL
144 service.deleteSnapshot(new ImageSpec('poolName', null, 'rbdName'), 'snapshotName').subscribe();
145 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/snap/snapshotName');
11fdf7f2
TL
146 expect(req.request.method).toBe('DELETE');
147 });
148
149 it('should call moveTrash', () => {
9f95a23c
TL
150 service.moveTrash(new ImageSpec('poolName', null, 'rbdName'), 1).subscribe();
151 const req = httpTesting.expectOne('api/block/image/poolName%2FrbdName/move_trash');
11fdf7f2
TL
152 expect(req.request.method).toBe('POST');
153 expect(req.request.body).toEqual({ delay: 1 });
154 });
9f95a23c
TL
155
156 describe('should compose image spec', () => {
157 it('with namespace', () => {
158 expect(new ImageSpec('mypool', 'myns', 'myimage').toString()).toBe('mypool/myns/myimage');
159 });
160
161 it('without namespace', () => {
162 expect(new ImageSpec('mypool', null, 'myimage').toString()).toBe('mypool/myimage');
163 });
164 });
165
166 describe('should parse image spec', () => {
167 it('with namespace', () => {
168 const imageSpec = ImageSpec.fromString('mypool/myns/myimage');
169 expect(imageSpec.poolName).toBe('mypool');
170 expect(imageSpec.namespace).toBe('myns');
171 expect(imageSpec.imageName).toBe('myimage');
172 });
173
174 it('without namespace', () => {
175 const imageSpec = ImageSpec.fromString('mypool/myimage');
176 expect(imageSpec.poolName).toBe('mypool');
177 expect(imageSpec.namespace).toBeNull();
178 expect(imageSpec.imageName).toBe('myimage');
179 });
180 });
11fdf7f2 181});