1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
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';
9 describe('PoolService', () => {
10 let service: PoolService;
11 let httpTesting: HttpTestingController;
12 const apiPath = 'api/pool';
15 providers: [PoolService, RbdConfigurationService],
16 imports: [HttpClientTestingModule]
20 service = TestBed.inject(PoolService);
21 httpTesting = TestBed.inject(HttpTestingController);
28 it('should be created', () => {
29 expect(service).toBeTruthy();
32 it('should call getList', () => {
33 service.getList().subscribe();
34 const req = httpTesting.expectOne(`${apiPath}?stats=true`);
35 expect(req.request.method).toBe('GET');
38 it('should call getInfo', () => {
39 service.getInfo().subscribe();
40 const req = httpTesting.expectOne(`ui-${apiPath}/info`);
41 expect(req.request.method).toBe('GET');
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);
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: [] });
59 it('should call delete', () => {
60 service.delete('somePool').subscribe();
61 const req = httpTesting.expectOne(`${apiPath}/somePool`);
62 expect(req.request.method).toBe('DELETE');
65 it('should call list without parameter', fakeAsync(() => {
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']);
72 expect(result).toEqual(['foo', 'bar']);
75 it('should call list with a list', fakeAsync(() => {
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']);
82 expect(result).toEqual(['foo', 'bar']);
85 it('should test injection of data from getConfiguration()', fakeAsync(() => {
88 service.getConfiguration(pool).subscribe((next) => (value = next));
89 const req = httpTesting.expectOne(`${apiPath}/${pool}/configuration`);
90 expect(req.request.method).toBe('GET');
93 name: 'rbd_qos_bps_limit',
95 source: RbdConfigurationSourceField.global
98 name: 'rbd_qos_iops_limit',
100 source: RbdConfigurationSourceField.global
104 expect(value).toEqual([
106 description: 'The desired limit of IO bytes per second.',
107 displayName: 'BPS Limit',
108 name: 'rbd_qos_bps_limit',
109 source: RbdConfigurationSourceField.global,
114 description: 'The desired limit of IO operations per second.',
115 displayName: 'IOPS Limit',
116 name: 'rbd_qos_iops_limit',
117 source: RbdConfigurationSourceField.global,