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