]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.spec.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd-mirroring.service.spec.ts
CommitLineData
1911f103
TL
1import { HttpRequest } from '@angular/common/http';
2import {
3 HttpClientTestingModule,
4 HttpTestingController,
5 TestRequest
6} from '@angular/common/http/testing';
11fdf7f2
TL
7import { fakeAsync, TestBed, tick } from '@angular/core/testing';
8
f67539c2 9import { configureTestBed } from '~/testing/unit-test-helper';
11fdf7f2
TL
10import { RbdMirroringService } from './rbd-mirroring.service';
11
12describe('RbdMirroringService', () => {
13 let service: RbdMirroringService;
14 let httpTesting: HttpTestingController;
1911f103
TL
15 let getMirroringSummaryCalls: () => TestRequest[];
16 let flushCalls: (call: TestRequest) => void;
11fdf7f2 17
9f95a23c 18 const summary: Record<string, any> = {
11fdf7f2
TL
19 status: 0,
20 content_data: {
21 daemons: [],
22 pools: [],
23 image_error: [],
24 image_syncing: [],
25 image_ready: []
26 },
27 executing_tasks: [{}]
28 };
29
f6b5b4d7
TL
30 configureTestBed({
31 providers: [RbdMirroringService],
32 imports: [HttpClientTestingModule]
33 });
11fdf7f2
TL
34
35 beforeEach(() => {
f67539c2
TL
36 service = TestBed.inject(RbdMirroringService);
37 httpTesting = TestBed.inject(HttpTestingController);
1911f103
TL
38 getMirroringSummaryCalls = () => {
39 return httpTesting.match((request: HttpRequest<any>) => {
40 return request.url.match(/api\/block\/mirroring\/summary/) && request.method === 'GET';
41 });
42 };
43 flushCalls = (call: TestRequest) => {
44 if (!call.cancelled) {
45 call.flush(summary);
46 }
47 };
11fdf7f2
TL
48 });
49
50 afterEach(() => {
51 httpTesting.verify();
52 });
53
54 it('should be created', () => {
55 expect(service).toBeTruthy();
56 });
57
58 it('should periodically poll summary', fakeAsync(() => {
1911f103
TL
59 const subs = service.startPolling();
60 tick();
9f95a23c 61 const calledWith: any[] = [];
f6b5b4d7 62 service.subscribeSummary((data) => {
11fdf7f2
TL
63 calledWith.push(data);
64 });
1911f103
TL
65 tick(service.REFRESH_INTERVAL * 2);
66 const calls = getMirroringSummaryCalls();
11fdf7f2 67
1911f103
TL
68 expect(calls.length).toEqual(3);
69 calls.forEach((call: TestRequest) => flushCalls(call));
f6b5b4d7 70 expect(calledWith).toEqual([summary]);
11fdf7f2 71
1911f103 72 subs.unsubscribe();
11fdf7f2
TL
73 }));
74
11fdf7f2
TL
75 it('should get pool config', () => {
76 service.getPool('poolName').subscribe();
77
78 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName');
79 expect(req.request.method).toBe('GET');
80 });
81
82 it('should update pool config', () => {
83 const request = {
84 mirror_mode: 'pool'
85 };
86 service.updatePool('poolName', request).subscribe();
87
88 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName');
89 expect(req.request.method).toBe('PUT');
90 expect(req.request.body).toEqual(request);
91 });
92
9f95a23c
TL
93 it('should get site name', () => {
94 service.getSiteName().subscribe();
95
96 const req = httpTesting.expectOne('api/block/mirroring/site_name');
97 expect(req.request.method).toBe('GET');
98 });
99
100 it('should set site name', () => {
101 service.setSiteName('site-a').subscribe();
102
103 const req = httpTesting.expectOne('api/block/mirroring/site_name');
104 expect(req.request.method).toBe('PUT');
105 expect(req.request.body).toEqual({ site_name: 'site-a' });
106 });
107
108 it('should create bootstrap token', () => {
109 service.createBootstrapToken('poolName').subscribe();
110
111 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/bootstrap/token');
112 expect(req.request.method).toBe('POST');
113 });
114
115 it('should import bootstrap token', () => {
116 service.importBootstrapToken('poolName', 'rx', 'token-1234').subscribe();
117
118 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/bootstrap/peer');
119 expect(req.request.method).toBe('POST');
120 expect(req.request.body).toEqual({
121 direction: 'rx',
122 token: 'token-1234'
123 });
124 });
125
11fdf7f2
TL
126 it('should get peer config', () => {
127 service.getPeer('poolName', 'peerUUID').subscribe();
128
129 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/peer/peerUUID');
130 expect(req.request.method).toBe('GET');
131 });
132
133 it('should add peer config', () => {
134 const request = {
135 cluster_name: 'remote',
136 client_id: 'admin',
137 mon_host: 'localhost',
138 key: '1234'
139 };
140 service.addPeer('poolName', request).subscribe();
141
142 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/peer');
143 expect(req.request.method).toBe('POST');
144 expect(req.request.body).toEqual(request);
145 });
146
147 it('should update peer config', () => {
148 const request = {
149 cluster_name: 'remote'
150 };
151 service.updatePeer('poolName', 'peerUUID', request).subscribe();
152
153 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/peer/peerUUID');
154 expect(req.request.method).toBe('PUT');
155 expect(req.request.body).toEqual(request);
156 });
157
158 it('should delete peer config', () => {
159 service.deletePeer('poolName', 'peerUUID').subscribe();
160
161 const req = httpTesting.expectOne('api/block/mirroring/pool/poolName/peer/peerUUID');
162 expect(req.request.method).toBe('DELETE');
163 });
164});