]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / pool.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
3
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { RbdConfigurationSourceField } from '../models/configuration';
6 import { RbdConfigurationService } from '../services/rbd-configuration.service';
7 import { PoolService } from './pool.service';
8
9 describe('PoolService', () => {
10 let service: PoolService;
11 let httpTesting: HttpTestingController;
12 const apiPath = 'api/pool';
13
14 configureTestBed({
15 providers: [PoolService, RbdConfigurationService],
16 imports: [HttpClientTestingModule]
17 });
18
19 beforeEach(() => {
20 service = TestBed.inject(PoolService);
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 getList', () => {
33 service.getList().subscribe();
34 const req = httpTesting.expectOne(`${apiPath}?stats=true`);
35 expect(req.request.method).toBe('GET');
36 });
37
38 it('should call getInfo', () => {
39 service.getInfo().subscribe();
40 const req = httpTesting.expectOne(`ui-${apiPath}/info`);
41 expect(req.request.method).toBe('GET');
42 });
43
44 it('should call create', () => {
45 const pool = { pool: 'somePool' };
46 service.create(pool).subscribe();
47 const req = httpTesting.expectOne(apiPath);
48 expect(req.request.method).toBe('POST');
49 expect(req.request.body).toEqual(pool);
50 });
51
52 it('should call update', () => {
53 service.update({ pool: 'somePool', application_metadata: [] }).subscribe();
54 const req = httpTesting.expectOne(`${apiPath}/somePool`);
55 expect(req.request.method).toBe('PUT');
56 expect(req.request.body).toEqual({ application_metadata: [] });
57 });
58
59 it('should call delete', () => {
60 service.delete('somePool').subscribe();
61 const req = httpTesting.expectOne(`${apiPath}/somePool`);
62 expect(req.request.method).toBe('DELETE');
63 });
64
65 it('should call list without parameter', fakeAsync(() => {
66 let result;
67 service.list().then((resp) => (result = resp));
68 const req = httpTesting.expectOne(`${apiPath}?attrs=`);
69 expect(req.request.method).toBe('GET');
70 req.flush(['foo', 'bar']);
71 tick();
72 expect(result).toEqual(['foo', 'bar']);
73 }));
74
75 it('should call list with a list', fakeAsync(() => {
76 let result;
77 service.list(['foo']).then((resp) => (result = resp));
78 const req = httpTesting.expectOne(`${apiPath}?attrs=foo`);
79 expect(req.request.method).toBe('GET');
80 req.flush(['foo', 'bar']);
81 tick();
82 expect(result).toEqual(['foo', 'bar']);
83 }));
84
85 it('should test injection of data from getConfiguration()', fakeAsync(() => {
86 const pool = 'foo';
87 let value;
88 service.getConfiguration(pool).subscribe((next) => (value = next));
89 const req = httpTesting.expectOne(`${apiPath}/${pool}/configuration`);
90 expect(req.request.method).toBe('GET');
91 req.flush([
92 {
93 name: 'rbd_qos_bps_limit',
94 value: '60',
95 source: RbdConfigurationSourceField.global
96 },
97 {
98 name: 'rbd_qos_iops_limit',
99 value: '0',
100 source: RbdConfigurationSourceField.global
101 }
102 ]);
103 tick();
104 expect(value).toEqual([
105 {
106 description: 'The desired limit of IO bytes per second.',
107 displayName: 'BPS Limit',
108 name: 'rbd_qos_bps_limit',
109 source: RbdConfigurationSourceField.global,
110 type: 0,
111 value: '60'
112 },
113 {
114 description: 'The desired limit of IO operations per second.',
115 displayName: 'IOPS Limit',
116 name: 'rbd_qos_iops_limit',
117 source: RbdConfigurationSourceField.global,
118 type: 1,
119 value: '0'
120 }
121 ]);
122 }));
123 });