]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/configuration.service.spec.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / configuration.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
3
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { ConfigFormCreateRequestModel } from '../../ceph/cluster/configuration/configuration-form/configuration-form-create-request.model';
6 import { ConfigurationService } from './configuration.service';
7
8 describe('ConfigurationService', () => {
9 let service: ConfigurationService;
10 let httpTesting: HttpTestingController;
11
12 configureTestBed({
13 providers: [ConfigurationService],
14 imports: [HttpClientTestingModule]
15 });
16
17 beforeEach(() => {
18 service = TestBed.get(ConfigurationService);
19 httpTesting = TestBed.get(HttpTestingController);
20 });
21
22 afterEach(() => {
23 httpTesting.verify();
24 });
25
26 it('should be created', () => {
27 expect(service).toBeTruthy();
28 });
29
30 it('should call getConfigData', () => {
31 service.getConfigData().subscribe();
32 const req = httpTesting.expectOne('api/cluster_conf/');
33 expect(req.request.method).toBe('GET');
34 });
35
36 it('should call get', () => {
37 service.get('configOption').subscribe();
38 const req = httpTesting.expectOne('api/cluster_conf/configOption');
39 expect(req.request.method).toBe('GET');
40 });
41
42 it('should call create', () => {
43 const configOption = new ConfigFormCreateRequestModel();
44 configOption.name = 'Test option';
45 configOption.value = [
46 { section: 'section1', value: 'value1' },
47 { section: 'section2', value: 'value2' }
48 ];
49 service.create(configOption).subscribe();
50 const req = httpTesting.expectOne('api/cluster_conf/');
51 expect(req.request.method).toBe('POST');
52 expect(req.request.body).toEqual(configOption);
53 });
54
55 it('should call bulkCreate', () => {
56 const configOptions = {
57 configOption1: { section: 'section', value: 'value' },
58 configOption2: { section: 'section', value: 'value' }
59 };
60 service.bulkCreate(configOptions).subscribe();
61 const req = httpTesting.expectOne('api/cluster_conf/');
62 expect(req.request.method).toBe('PUT');
63 expect(req.request.body).toEqual(configOptions);
64 });
65
66 it('should call filter', () => {
67 const configOptions = ['configOption1', 'configOption2', 'configOption3'];
68 service.filter(configOptions).subscribe();
69 const req = httpTesting.expectOne(
70 'api/cluster_conf/filter?names=configOption1,configOption2,configOption3'
71 );
72 expect(req.request.method).toBe('GET');
73 });
74
75 it('should call delete', () => {
76 service.delete('testOption', 'testSection').subscribe();
77 const reg = httpTesting.expectOne('api/cluster_conf/testOption?section=testSection');
78 expect(reg.request.method).toBe('DELETE');
79 });
80
81 it('should get value', () => {
82 const config = {
83 default: 'a',
84 value: [
85 { section: 'global', value: 'b' },
86 { section: 'mon', value: 'c' },
87 { section: 'mon.1', value: 'd' },
88 { section: 'mds', value: 'e' }
89 ]
90 };
91 expect(service.getValue(config, 'mon.1')).toBe('d');
92 expect(service.getValue(config, 'mon')).toBe('c');
93 expect(service.getValue(config, 'mds.1')).toBe('e');
94 expect(service.getValue(config, 'mds')).toBe('e');
95 expect(service.getValue(config, 'osd')).toBe('b');
96 config.value = [];
97 expect(service.getValue(config, 'osd')).toBe('a');
98 });
99 });