]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
import 15.2.9
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / service-form / service-form.component.spec.ts
CommitLineData
adb31ebb
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
4import { RouterTestingModule } from '@angular/router/testing';
5
6import * as _ from 'lodash';
7import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
8import { ToastrModule } from 'ngx-toastr';
9
10import {
11 configureTestBed,
12 FormHelper,
13 i18nProviders
14} from '../../../../../testing/unit-test-helper';
15import { CephServiceService } from '../../../../shared/api/ceph-service.service';
16import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
17import { SharedModule } from '../../../../shared/shared.module';
18import { ServiceFormComponent } from './service-form.component';
19
20describe('ServiceFormComponent', () => {
21 let component: ServiceFormComponent;
22 let fixture: ComponentFixture<ServiceFormComponent>;
23 let cephServiceService: CephServiceService;
24 let form: CdFormGroup;
25 let formHelper: FormHelper;
26
27 configureTestBed({
28 declarations: [ServiceFormComponent],
29 imports: [
30 HttpClientTestingModule,
31 TypeaheadModule,
32 ReactiveFormsModule,
33 RouterTestingModule,
34 SharedModule,
35 ToastrModule.forRoot()
36 ],
37 providers: [i18nProviders]
38 });
39
40 beforeEach(() => {
41 fixture = TestBed.createComponent(ServiceFormComponent);
42 component = fixture.componentInstance;
43 form = component.serviceForm;
44 formHelper = new FormHelper(form);
45 fixture.detectChanges();
46 });
47
48 it('should create', () => {
49 expect(component).toBeTruthy();
50 });
51
52 describe('should test form', () => {
53 beforeEach(() => {
54 cephServiceService = TestBed.get(CephServiceService);
55 spyOn(cephServiceService, 'create').and.stub();
56 });
57
58 it('should test placement (host)', () => {
59 formHelper.setValue('service_type', 'crash');
60 formHelper.setValue('placement', 'hosts');
61 formHelper.setValue('hosts', ['mgr0', 'mon0', 'osd0']);
62 formHelper.setValue('count', 2);
63 component.onSubmit();
64 expect(cephServiceService.create).toHaveBeenCalledWith({
65 service_type: 'crash',
66 placement: {
67 hosts: ['mgr0', 'mon0', 'osd0'],
68 count: 2
69 },
70 unmanaged: false
71 });
72 });
73
74 it('should test placement (label)', () => {
75 formHelper.setValue('service_type', 'mgr');
76 formHelper.setValue('placement', 'label');
77 formHelper.setValue('label', 'foo');
78 component.onSubmit();
79 expect(cephServiceService.create).toHaveBeenCalledWith({
80 service_type: 'mgr',
81 placement: {
82 label: 'foo'
83 },
84 unmanaged: false
85 });
86 });
87
88 it('should submit valid count', () => {
89 formHelper.setValue('count', 1);
90 component.onSubmit();
91 formHelper.expectValid('count');
92 });
93
94 it('should submit invalid count (1)', () => {
95 formHelper.setValue('count', 0);
96 component.onSubmit();
97 formHelper.expectError('count', 'min');
98 });
99
100 it('should submit invalid count (2)', () => {
101 formHelper.setValue('count', 'abc');
102 component.onSubmit();
103 formHelper.expectError('count', 'pattern');
104 });
105
106 it('should test unmanaged', () => {
107 formHelper.setValue('service_type', 'rgw');
108 formHelper.setValue('placement', 'label');
109 formHelper.setValue('label', 'bar');
110 formHelper.setValue('rgw_frontend_port', 4567);
111 formHelper.setValue('unmanaged', true);
112 component.onSubmit();
113 expect(cephServiceService.create).toHaveBeenCalledWith({
114 service_type: 'rgw',
115 placement: {},
116 unmanaged: true
117 });
118 });
119
120 it('should test various services', () => {
121 _.forEach(
122 [
123 'alertmanager',
124 'crash',
125 'grafana',
126 'mds',
127 'mgr',
128 'mon',
129 'node-exporter',
130 'prometheus',
131 'rbd-mirror'
132 ],
133 (serviceType) => {
134 formHelper.setValue('service_type', serviceType);
135 component.onSubmit();
136 expect(cephServiceService.create).toHaveBeenCalledWith({
137 service_type: serviceType,
138 placement: {},
139 unmanaged: false
140 });
141 }
142 );
143 });
144
145 describe('should test service nfs', () => {
146 beforeEach(() => {
147 formHelper.setValue('service_type', 'nfs');
148 formHelper.setValue('pool', 'foo');
149 });
150
151 it('should submit nfs with namespace', () => {
152 formHelper.setValue('namespace', 'bar');
153 component.onSubmit();
154 expect(cephServiceService.create).toHaveBeenCalledWith({
155 service_type: 'nfs',
156 placement: {},
157 unmanaged: false,
158 pool: 'foo',
159 namespace: 'bar'
160 });
161 });
162
163 it('should submit nfs w/o namespace', () => {
164 component.onSubmit();
165 expect(cephServiceService.create).toHaveBeenCalledWith({
166 service_type: 'nfs',
167 placement: {},
168 unmanaged: false,
169 pool: 'foo'
170 });
171 });
172 });
173
174 describe('should test service rgw', () => {
175 beforeEach(() => {
176 formHelper.setValue('service_type', 'rgw');
177 });
178
179 it('should test rgw valid service id', () => {
180 formHelper.setValue('service_id', 'foo.bar');
181 formHelper.expectValid('service_id');
182 formHelper.setValue('service_id', 'foo.bar.bas');
183 formHelper.expectValid('service_id');
184 });
185
186 it('should test rgw invalid service id', () => {
187 formHelper.setValue('service_id', 'foo');
188 formHelper.expectError('service_id', 'rgwPattern');
189 formHelper.setValue('service_id', 'foo.');
190 formHelper.expectError('service_id', 'rgwPattern');
191 formHelper.setValue('service_id', 'foo.bar.');
192 formHelper.expectError('service_id', 'rgwPattern');
193 formHelper.setValue('service_id', 'foo.bar.bas.');
194 formHelper.expectError('service_id', 'rgwPattern');
195 });
196
197 it('should submit rgw with port', () => {
198 formHelper.setValue('rgw_frontend_port', 1234);
199 formHelper.setValue('ssl', true);
200 component.onSubmit();
201 expect(cephServiceService.create).toHaveBeenCalledWith({
202 service_type: 'rgw',
203 placement: {},
204 unmanaged: false,
205 rgw_frontend_port: 1234,
206 rgw_frontend_ssl_certificate: '',
207 rgw_frontend_ssl_key: '',
208 ssl: true
209 });
210 });
211
212 it('should submit valid rgw port (1)', () => {
213 formHelper.setValue('rgw_frontend_port', 1);
214 component.onSubmit();
215 formHelper.expectValid('rgw_frontend_port');
216 });
217
218 it('should submit valid rgw port (2)', () => {
219 formHelper.setValue('rgw_frontend_port', 65535);
220 component.onSubmit();
221 formHelper.expectValid('rgw_frontend_port');
222 });
223
224 it('should submit invalid rgw port (1)', () => {
225 formHelper.setValue('rgw_frontend_port', 0);
226 component.onSubmit();
227 formHelper.expectError('rgw_frontend_port', 'min');
228 });
229
230 it('should submit invalid rgw port (2)', () => {
231 formHelper.setValue('rgw_frontend_port', 65536);
232 component.onSubmit();
233 formHelper.expectError('rgw_frontend_port', 'max');
234 });
235
236 it('should submit invalid rgw port (3)', () => {
237 formHelper.setValue('rgw_frontend_port', 'abc');
238 component.onSubmit();
239 formHelper.expectError('rgw_frontend_port', 'pattern');
240 });
241
242 it('should submit rgw w/o port', () => {
243 formHelper.setValue('ssl', false);
244 component.onSubmit();
245 expect(cephServiceService.create).toHaveBeenCalledWith({
246 service_type: 'rgw',
247 placement: {},
248 unmanaged: false,
249 ssl: false
250 });
251 });
252 });
253
254 describe('should test service iscsi', () => {
255 beforeEach(() => {
256 formHelper.setValue('service_type', 'iscsi');
257 formHelper.setValue('pool', 'xyz');
258 formHelper.setValue('api_user', 'user');
259 formHelper.setValue('api_password', 'password');
260 formHelper.setValue('ssl', false);
261 });
262
263 it('should submit iscsi', () => {
264 component.onSubmit();
265 expect(cephServiceService.create).toHaveBeenCalledWith({
266 service_type: 'iscsi',
267 placement: {},
268 unmanaged: false,
269 pool: 'xyz',
270 api_user: 'user',
271 api_password: 'password',
272 api_secure: false
273 });
274 });
275
276 it('should submit iscsi with trusted ips', () => {
277 formHelper.setValue('ssl', true);
278 formHelper.setValue('trusted_ip_list', ' 172.16.0.5, 192.1.1.10 ');
279 component.onSubmit();
280 expect(cephServiceService.create).toHaveBeenCalledWith({
281 service_type: 'iscsi',
282 placement: {},
283 unmanaged: false,
284 pool: 'xyz',
285 api_user: 'user',
286 api_password: 'password',
287 api_secure: true,
288 ssl_cert: '',
289 ssl_key: '',
290 trusted_ip_list: ['172.16.0.5', '192.1.1.10']
291 });
292 });
293
294 it('should submit iscsi with port', () => {
295 formHelper.setValue('api_port', 456);
296 component.onSubmit();
297 expect(cephServiceService.create).toHaveBeenCalledWith({
298 service_type: 'iscsi',
299 placement: {},
300 unmanaged: false,
301 pool: 'xyz',
302 api_user: 'user',
303 api_password: 'password',
304 api_secure: false,
305 api_port: 456
306 });
307 });
308
309 it('should submit valid iscsi port (1)', () => {
310 formHelper.setValue('api_port', 1);
311 component.onSubmit();
312 formHelper.expectValid('api_port');
313 });
314
315 it('should submit valid iscsi port (2)', () => {
316 formHelper.setValue('api_port', 65535);
317 component.onSubmit();
318 formHelper.expectValid('api_port');
319 });
320
321 it('should submit invalid iscsi port (1)', () => {
322 formHelper.setValue('api_port', 0);
323 component.onSubmit();
324 formHelper.expectError('api_port', 'min');
325 });
326
327 it('should submit invalid iscsi port (2)', () => {
328 formHelper.setValue('api_port', 65536);
329 component.onSubmit();
330 formHelper.expectError('api_port', 'max');
331 });
332
333 it('should submit invalid iscsi port (3)', () => {
334 formHelper.setValue('api_port', 'abc');
335 component.onSubmit();
336 formHelper.expectError('api_port', 'pattern');
337 });
338 });
339 });
340});